mirror of
https://github.com/juherr/kill-the-news.git
synced 2026-06-21 06:13:48 +00:00
feat(attachments): render inline cid images in place, not as attachments
Inline images (referenced by src="cid:…") are now classified at ingest and kept out of the downloadable attachment lists, RSS/Atom enclosures, and the API — while still stored in R2 and cleaned up with the email. Fixes the admin email preview, which injected raw HTML into the data: iframe so cid refs never resolved; it now rewrites them to absolute /files URLs. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -20,14 +20,17 @@ async function seedFeed(
|
||||
filename: string;
|
||||
contentType: string;
|
||||
size: number;
|
||||
contentId?: string;
|
||||
inline?: boolean;
|
||||
}[],
|
||||
content = "<p>Email body</p>",
|
||||
) {
|
||||
await env.EMAIL_STORAGE.put(
|
||||
EMAIL_KEY,
|
||||
JSON.stringify({
|
||||
subject: "Test Subject",
|
||||
from: "sender@example.com",
|
||||
content: "<p>Email body</p>",
|
||||
content,
|
||||
receivedAt: RECEIVED_AT,
|
||||
headers: {},
|
||||
...(attachments ? { attachments } : {}),
|
||||
@@ -126,6 +129,31 @@ describe("GET /entries/:feedId/:entryId", () => {
|
||||
expect(body).toContain("2.0 KB");
|
||||
});
|
||||
|
||||
it("renders inline images in place and omits them from the attachments list", async () => {
|
||||
await seedFeed(
|
||||
env,
|
||||
[
|
||||
{
|
||||
id: "img-1",
|
||||
filename: "logo.png",
|
||||
contentType: "image/png",
|
||||
size: 512,
|
||||
contentId: "logo123",
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
'<p>Body</p><img src="cid:logo123"/>',
|
||||
);
|
||||
const app = makeApp();
|
||||
const res = await app.request(`/${FEED_ID}/${RECEIVED_AT}`, {}, env as any);
|
||||
const body = await res.text();
|
||||
// The cid: ref is rewritten to the stored file URL (rendered in place)…
|
||||
expect(body).toContain('src="/files/img-1/logo.png"');
|
||||
expect(body).not.toContain("cid:logo123");
|
||||
// …and the image is not listed as a downloadable attachment.
|
||||
expect(body).not.toContain("Attachments");
|
||||
});
|
||||
|
||||
it("does not render an attachments section when there are none", async () => {
|
||||
await seedFeed(env);
|
||||
const app = makeApp();
|
||||
|
||||
Reference in New Issue
Block a user