feat(assets): ZIP에 assets.json 포함 및 메타데이터(integrity 포함) 생성
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user