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:
@@ -12,6 +12,22 @@ export function normalizeCid(
|
||||
return trimmed || undefined;
|
||||
}
|
||||
|
||||
// Collect the normalized Content-IDs referenced by `cid:` image sources in the
|
||||
// email body — exactly the set rewriteCidSrc would turn into inline <img> URLs.
|
||||
// Used at ingest to flag those attachments as inline (rendered in place, hidden
|
||||
// from the downloadable attachment lists).
|
||||
export function extractInlineCids(content: string): Set<string> {
|
||||
const cids = new Set<string>();
|
||||
if (!content || isPlainText(content)) return cids;
|
||||
const { document } = parseHTML(content);
|
||||
document.querySelectorAll("[src]").forEach((el: Element) => {
|
||||
const match = (el.getAttribute("src") ?? "").match(/^\s*cid:(.+)$/i);
|
||||
const cid = match ? normalizeCid(match[1]) : undefined;
|
||||
if (cid) cids.add(cid);
|
||||
});
|
||||
return cids;
|
||||
}
|
||||
|
||||
function cleanMsoStyles(style: string): string {
|
||||
return style
|
||||
.split(";")
|
||||
|
||||
Reference in New Issue
Block a user