feat(entries): list email attachments with download links

The email detail page loaded the full EmailData (including attachments)
but never rendered them, so attachments were invisible. Add a conditional
"Attachments" section linking each file to /files/:id/:filename with name
and human-readable size.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Julien Herr
2026-05-23 14:46:25 +02:00
parent d322bc1e92
commit 766f2717a7
2 changed files with 87 additions and 1 deletions
+38 -1
View File
@@ -13,7 +13,15 @@ function makeApp() {
return app;
}
async function seedFeed(env: ReturnType<typeof createMockEnv>) {
async function seedFeed(
env: ReturnType<typeof createMockEnv>,
attachments?: {
id: string;
filename: string;
contentType: string;
size: number;
}[],
) {
await env.EMAIL_STORAGE.put(
EMAIL_KEY,
JSON.stringify({
@@ -22,6 +30,7 @@ async function seedFeed(env: ReturnType<typeof createMockEnv>) {
content: "<p>Email body</p>",
receivedAt: RECEIVED_AT,
headers: {},
...(attachments ? { attachments } : {}),
}),
);
await env.EMAIL_STORAGE.put(
@@ -97,6 +106,34 @@ describe("GET /entries/:feedId/:entryId", () => {
expect(body).toContain("sender@example.com");
});
it("lists attachments with download links when present", async () => {
await seedFeed(env, [
{
id: "att-123",
filename: "report final.pdf",
contentType: "application/pdf",
size: 2048,
},
]);
const app = makeApp();
const res = await app.request(`/${FEED_ID}/${RECEIVED_AT}`, {}, env as any);
const body = await res.text();
expect(body).toContain("Attachments");
expect(body).toContain("report final.pdf");
expect(body).toContain(
`/files/att-123/${encodeURIComponent("report final.pdf")}`,
);
expect(body).toContain("2.0 KB");
});
it("does not render an attachments section when there are none", async () => {
await seedFeed(env);
const app = makeApp();
const res = await app.request(`/${FEED_ID}/${RECEIVED_AT}`, {}, env as any);
const body = await res.text();
expect(body).not.toContain("Attachments");
});
it("sets Content-Security-Policy header", async () => {
await seedFeed(env);
const app = makeApp();