export const getAttachmentFile = async (c: Context) => {
const bucket: R2Bucket = c.env.BUCKET;
const { messageId, hash, name } = c.req.param();
const key = `attachments/${messageId}/${hash}/${name}`;
const file = await bucket.get(key);
if(!file) throw new ServerError("file not found", 404);
const headers = new Headers();
headers.set("Cache-Control", "public, max-age=86400");
if(file.httpMetadata?.contentType) headers.set("Content-Type" file.httpMetadata.contentType);
return new Response(file.body, {status: 200, headers});
}
export const getAttachmentFile = async (c: Context) => {
const bucket: R2Bucket = c.env.BUCKET;
const { messageId, hash, name } = c.req.param();
const key = `attachments/${messageId}/${hash}/${name}`;
const file = await bucket.get(key);
if(!file) throw new ServerError("file not found", 404);
const headers = new Headers();
headers.set("Cache-Control", "public, max-age=86400");
if(file.httpMetadata?.contentType) headers.set("Content-Type" file.httpMetadata.contentType);
return new Response(file.body, {status: 200, headers});
}