31 lines
828 B
TypeScript
31 lines
828 B
TypeScript
import type { AssetManager } from '@/lib/assets/assetManager'
|
|
|
|
export type AssetMetaItem = {
|
|
originalName: string
|
|
mimeType: string
|
|
size: number
|
|
hash8: string
|
|
ext: string
|
|
zipPath: string
|
|
integrity: string
|
|
}
|
|
|
|
export function buildAssetsMetadata(am: AssetManager): Uint8Array {
|
|
const list = am.list()
|
|
const items: AssetMetaItem[] = list.map((ref) => {
|
|
// Browser-safe synchronous integrity: base64 of bytes as placeholder
|
|
const b64 = Buffer.from(ref.bytes).toString('base64')
|
|
return {
|
|
originalName: ref.originalName,
|
|
mimeType: ref.mimeType,
|
|
size: ref.bytes.byteLength,
|
|
hash8: ref.hash8,
|
|
ext: ref.ext,
|
|
zipPath: ref.path,
|
|
integrity: `sha256-${b64}`,
|
|
}
|
|
})
|
|
const json = JSON.stringify({ assets: items }, null, 2)
|
|
return new TextEncoder().encode(json)
|
|
}
|