chore: 项目基线(基于 WeKnora 定制版,整理文件忽略规则)
This commit is contained in:
commit
9097ee699d
5769 files changed
+1446466
No files matched your search
@@ -0,0 +1,30 @@
|
||||
export interface LoadedProtectedFile {
|
||||
blob: Blob;
|
||||
blobURL: string;
|
||||
fileName: string;
|
||||
}
|
||||
|
||||
export const RESOURCE_PREVIEW_EVENT = 'weknora:resource-preview';
|
||||
|
||||
export function responseFileName(disposition: string | null, source: string): string {
|
||||
const encoded = disposition?.match(/(?:^|;)\s*filename\*\s*=\s*UTF-8'[^']*'([^;]+)/i)?.[1]?.trim();
|
||||
let name = disposition?.match(/filename="([^"]+)"|filename=([^;]+)/i)?.slice(1).find(Boolean);
|
||||
if (encoded) {
|
||||
try { name = decodeURIComponent(encoded); } catch { /* use plain filename */ }
|
||||
}
|
||||
return (name || source.split('/').pop() || 'download').split(/[\\/]/).pop()!
|
||||
.replace(/[\x00-\x1f\x7f]/g, '').trim() || 'download';
|
||||
}
|
||||
|
||||
// The browser cannot render an Office document as an <img>. Keep a real
|
||||
// download link as fallback; the app's preview host intercepts normal clicks.
|
||||
export function applyProtectedFile(img: HTMLImageElement, file: LoadedProtectedFile, source: string): void {
|
||||
const link = img.ownerDocument.createElement('a');
|
||||
link.href = file.blobURL;
|
||||
link.download = file.fileName;
|
||||
link.className = 'protected-resource-card';
|
||||
link.textContent = img.alt || file.fileName;
|
||||
link.title = file.fileName;
|
||||
link.dataset.protectedResource = source;
|
||||
img.replaceWith(link);
|
||||
}
|
||||
Reference in new issue
Block a user