chore: 项目基线(基于 WeKnora 定制版,整理文件忽略规则)

This commit is contained in:
runny committed 2026-11-13 17:54:56 +08:00
commit 9097ee699d
5769 files changed
+1446466

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
/** Byte identity: never infer an embedded image's position from its filename or OCR. */
export async function sourceImageDigest(bytes: ArrayBuffer): Promise<string> {
const hash = await crypto.subtle.digest('SHA-256', bytes)
return [...new Uint8Array(hash)].map(b => b.toString(16).padStart(2, '0')).join('')
}
export async function indexEmbeddedSourceImages(root: Element): Promise<void> {
await Promise.all([...root.querySelectorAll<HTMLImageElement>('img')].map(async image => {
// Only bytes embedded by docx-preview; never fetch remote document links.
const match = /^data:(?:image\/[^;,]+|application\/octet-stream);base64,([A-Za-z0-9+/=\s]+)$/.exec(image.src)
if (!match) return
try {
const bytes = Uint8Array.from(atob(match[1]!), c => c.charCodeAt(0))
image.dataset.sourceImageDigest = await sourceImageDigest(bytes.buffer)
} catch { /* An unsupported image cannot establish identity. */ }
}))
}