mirror of
https://github.com/juherr/kill-the-news.git
synced 2026-06-20 22:03:48 +00:00
feat: store email attachments in R2 and expose as RSS enclosures
Attachments from incoming emails are uploaded to an optional Cloudflare R2
bucket and exposed as <enclosure> elements in RSS and <link rel="enclosure">
in Atom feeds, served at /files/{id}/{filename} with immutable caching.
R2 is opt-in: if ATTACHMENT_BUCKET is not bound the feature is a no-op.
Attachments are cleaned up from R2 on email/feed deletion and during
size-based feed trimming. Adds MockR2 to the test setup.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import PostalMime from "postal-mime";
|
||||
import { Env } from "../types";
|
||||
import { processEmail } from "./email-processor";
|
||||
import { processEmail, RawAttachment } from "./email-processor";
|
||||
|
||||
export async function handleCloudflareEmail(
|
||||
message: ForwardableEmailMessage,
|
||||
@@ -21,6 +21,14 @@ export async function handleCloudflareEmail(
|
||||
headers[h.key] = h.value;
|
||||
}
|
||||
|
||||
const rawAttachments: RawAttachment[] = (email.attachments ?? [])
|
||||
.filter((a) => a.content instanceof ArrayBuffer)
|
||||
.map((a) => ({
|
||||
filename: a.filename || "attachment",
|
||||
contentType: a.mimeType || "application/octet-stream",
|
||||
content: a.content as ArrayBuffer,
|
||||
}));
|
||||
|
||||
await processEmail(
|
||||
{
|
||||
toAddress: message.to,
|
||||
@@ -30,6 +38,7 @@ export async function handleCloudflareEmail(
|
||||
content: email.html ?? email.text ?? "",
|
||||
receivedAt: email.date ? new Date(email.date).getTime() : Date.now(),
|
||||
headers,
|
||||
attachments: rawAttachments,
|
||||
},
|
||||
env,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user