refactor: consolidate shared application helpers
This commit is contained in:
@@ -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",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user