chore(assets): assets.json에 group/referencedAt 추가 및 AssetManager 참조 추적
This commit is contained in:
@@ -38,6 +38,7 @@ export class AssetManager {
|
||||
private readonly allowed: Set<string>
|
||||
private byHash = new Map<string, AssetRef>()
|
||||
private byOriginal = new Map<string, string>() // originalName -> path
|
||||
private referenced = new Set<string>() // originalName referenced via rewrite
|
||||
|
||||
constructor(opts: AssetManagerOptions) {
|
||||
this.maxBytes = opts.maxBytes
|
||||
@@ -91,8 +92,13 @@ export class AssetManager {
|
||||
if (urlOrLocalRef.startsWith('local:')) {
|
||||
const key = urlOrLocalRef.slice('local:'.length)
|
||||
const p = this.byOriginal.get(key)
|
||||
if (p) this.referenced.add(key)
|
||||
return p ?? urlOrLocalRef
|
||||
}
|
||||
return urlOrLocalRef
|
||||
}
|
||||
|
||||
referencedList(): string[] {
|
||||
return Array.from(this.referenced)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,22 @@ export type AssetMetaItem = {
|
||||
ext: string
|
||||
zipPath: string
|
||||
integrity: string
|
||||
group: 'images' | 'fonts' | 'other'
|
||||
referencedAt: string[]
|
||||
}
|
||||
|
||||
export function buildAssetsMetadata(am: AssetManager): Uint8Array {
|
||||
const list = am.list()
|
||||
const referenced = new Set(am.referencedList())
|
||||
const items: AssetMetaItem[] = list.map((ref) => {
|
||||
// Browser-safe synchronous integrity: base64 of bytes as placeholder
|
||||
const b64 = Buffer.from(ref.bytes).toString('base64')
|
||||
const group: 'images' | 'fonts' | 'other' = ref.mimeType.startsWith('image/')
|
||||
? 'images'
|
||||
: ref.mimeType.startsWith('font/')
|
||||
? 'fonts'
|
||||
: 'other'
|
||||
const referencedAt = referenced.has(ref.originalName) ? [`local:${ref.originalName}`] : []
|
||||
return {
|
||||
originalName: ref.originalName,
|
||||
mimeType: ref.mimeType,
|
||||
@@ -23,6 +32,8 @@ export function buildAssetsMetadata(am: AssetManager): Uint8Array {
|
||||
ext: ref.ext,
|
||||
zipPath: ref.path,
|
||||
integrity: `sha256-${b64}`,
|
||||
group,
|
||||
referencedAt,
|
||||
}
|
||||
})
|
||||
const json = JSON.stringify({ assets: items }, null, 2)
|
||||
|
||||
Reference in New Issue
Block a user