import { ART_FILES } from './art-assets.ts'
export type ArtFileName = keyof typeof ART_FILES
const ART_PATHS = new Set(Object.keys(ART_FILES))
export function artFileName(pathname: string): ArtFileName | null {
const name = pathname.replace(/^\//, '')
return ART_PATHS.has(name) ? (name as ArtFileName) : null
}
export function decodeArtBase64(base64: string): Uint8Array {
const binary = atob(base64)
const bytes = new Uint8Array(binary.length)
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i)
return bytes
}
export function artResponse(pathname: string): Response | null {
const name = artFileName(pathname)
if (!name) return null
const file = ART_FILES[name]
return new Response(decodeArtBase64(file.base64), {
headers: {
'Content-Type': file.type,
'Cache-Control': 'public, max-age=604800',
},
})
}