feat(web): connect quick share flow
Signed-off-by: JustMe <mr.toing@outlook.com>
This commit is contained in:
1 parent
53768a195d
commit
e02e024605
138 files changed
+10614
No files matched your search
@@ -0,0 +1,26 @@
|
||||
export interface ClipboardPayload {
|
||||
files: File[];
|
||||
text: string;
|
||||
}
|
||||
|
||||
/** 读取剪贴板(需要用户手势与权限)。失败或被拒绝返回 null */
|
||||
export async function readClipboard(): Promise<ClipboardPayload | null> {
|
||||
try {
|
||||
if (!navigator.clipboard.read) return { files: [], text: await navigator.clipboard.readText() };
|
||||
const files: File[] = [];
|
||||
let text = '';
|
||||
for (const entry of await navigator.clipboard.read()) {
|
||||
for (const type of entry.types) {
|
||||
const blob = await entry.getType(type);
|
||||
if (type.startsWith('image/')) {
|
||||
files.push(new File([blob], `粘贴-${Date.now()}.${type.split('/')[1] ?? 'png'}`, { type }));
|
||||
} else if (type === 'text/plain' && !text) {
|
||||
text = await blob.text();
|
||||
}
|
||||
}
|
||||
}
|
||||
return { files, text };
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user