refactor: consolidate shared application helpers

This commit is contained in:
2026-07-29 12:28:51 +07:00 Unverified
parent 1fb154b465
commit 6b0440602b
14 changed files with 45 additions and 45 deletions
+17
View File
@@ -27,3 +27,20 @@ export function validateImageUploadFile(file: Pick<File, "name" | "type" | "size
export function cdnUrl(id: string | null | undefined) {
return id ? `/cdn/${id}` : "";
}
export type CdnResponseRecord = {
data: Buffer;
type: string;
size: number;
};
export function cdnImageResponse(record: CdnResponseRecord) {
return new Response(new Uint8Array(record.data), {
headers: {
"Content-Type": record.type,
"Content-Length": String(record.size),
"Cache-Control": "public, max-age=31536000, immutable",
"X-Content-Type-Options": "nosniff",
},
});
}