fix(ci): 누락 파일 추가 및 AssetManager 경로 전략 변경사항 포함
This commit is contained in:
@@ -16,6 +16,7 @@ export type AssetRef = {
|
||||
export type AssetManagerOptions = {
|
||||
maxBytes: number
|
||||
allowedExts: string[] // e.g., ['png','jpg','jpeg','webp','svg']
|
||||
pathStrategy?: 'flat' | 'grouped'
|
||||
}
|
||||
|
||||
function extOf(name: string): string {
|
||||
@@ -36,6 +37,7 @@ function hash8(bytes: Uint8Array): string {
|
||||
export class AssetManager {
|
||||
private readonly maxBytes: number
|
||||
private readonly allowed: Set<string>
|
||||
private readonly pathStrategy: 'flat' | 'grouped'
|
||||
private byHash = new Map<string, AssetRef>()
|
||||
private byOriginal = new Map<string, string>() // originalName -> path
|
||||
private referenced = new Set<string>() // originalName referenced via rewrite
|
||||
@@ -43,6 +45,7 @@ export class AssetManager {
|
||||
constructor(opts: AssetManagerOptions) {
|
||||
this.maxBytes = opts.maxBytes
|
||||
this.allowed = new Set(opts.allowedExts.map((e) => e.toLowerCase()))
|
||||
this.pathStrategy = opts.pathStrategy ?? 'flat'
|
||||
}
|
||||
|
||||
async add(file: AssetInput): Promise<AssetRef> {
|
||||
@@ -61,7 +64,7 @@ export class AssetManager {
|
||||
return existing
|
||||
}
|
||||
|
||||
const path = `assets/${h}.${ext}`
|
||||
const path = this.makePath(h, ext, file.type)
|
||||
const ref: AssetRef = {
|
||||
originalName: file.name,
|
||||
mimeType: file.type,
|
||||
@@ -101,4 +104,14 @@ export class AssetManager {
|
||||
referencedList(): string[] {
|
||||
return Array.from(this.referenced)
|
||||
}
|
||||
|
||||
private makePath(hash8: string, ext: string, mime: string): string {
|
||||
if (this.pathStrategy === 'grouped') {
|
||||
let group = 'other'
|
||||
if (mime.startsWith('image/')) group = 'images'
|
||||
else if (mime.startsWith('font/')) group = 'fonts'
|
||||
return `assets/${group}/${hash8}.${ext}`
|
||||
}
|
||||
return `assets/${hash8}.${ext}`
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user