Files
tsumugu/frontend/src/content-symbol.mjs
T
LarsandCursor e4380261fc
Deploy Development / deploy (push) Successful in 29s
Test Suite / pytest-backend (push) Successful in 1m24s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 9s
Verkuerze die Inhaltsliste und fuehre Unterkapitel ein, damit Richtung, Bezuge und Struktur ohne Zusatzzeilen bedienbar bleiben.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-17 21:13:21 +02:00

46 lines
2.7 KiB
JavaScript

/** Short content hashes so a replaced symbol is loaded without clearing the browser cache. */
const SYMBOL_REV = {
"light/note": "5A420BDCA465",
"dark/note": "A4CB08EFE0CE",
"light/communication-in": "E0EA4BDC8906",
"dark/communication-in": "96DD8CF1D6B0",
"light/communication-out": "700E710A12CB",
"dark/communication-out": "761536F9818E",
"light/communication-local": "6FD92AEECE11",
"dark/communication-local": "2E1EF315DFE5",
"light/communication-unspecified": "759AF850BB6C",
"dark/communication-unspecified": "541E3CFE050C",
};
export function symbolUrl(tone, name) {
const rev = SYMBOL_REV[`${tone}/${name}`] || "symbols-1-3";
return `/ui/content-symbols-v1/${tone}/${name}.svg?v=${rev}`;
}
/** UI classification only. The server's element kind and access rules are unchanged. */
export function contentSymbol(element = {}) {
if (element.kind === "note") return "note";
const detail = element.external?.detail || {};
const mime = String(element.file?.content_type || detail.content_type || detail.mime_type || "").split(";")[0].trim().toLowerCase();
const filename = String(element.file?.filename || detail.filename || "");
const ext = filename.toLowerCase().split(".").slice(1).pop() || "";
const media = element.preview?.media;
if (mime === "application/pdf" || media === "pdf" || ext === "pdf") return "pdf";
if (mime.startsWith("image/") || media === "image" || /^(png|jpe?g|webp|gif|heic|avif|svg|tiff?)$/.test(ext)) return "image";
if (mime.startsWith("audio/") || /^(mp3|wav|ogg|m4a|flac|aac)$/.test(ext)) return "audio";
if (mime.startsWith("video/") || /^(mp4|webm|mov|mkv|avi)$/.test(ext)) return "video";
if (mime === "message/rfc822" || mime === "application/vnd.ms-outlook" || /^(eml|msg)$/.test(ext)) return "email";
if (/spreadsheet|excel|csv|tab-separated/.test(mime) || /^(xlsx?|ods|csv|tsv)$/.test(ext)) return "spreadsheet";
if (/presentation|powerpoint/.test(mime) || /^(pptx?|odp)$/.test(ext)) return "presentation";
if (/zip|compressed|gzip|x-tar/.test(mime) || /^(zip|7z|rar|tar|gz|tgz)$/.test(ext)) return "archive";
if (/javascript|json|xml/.test(mime) || /^(js|jsx|ts|tsx|py|json|xml|html?|css|sql|ya?ml)$/.test(ext)) return "code";
if (mime.startsWith("text/") || /word|opendocument.text|rtf/.test(mime) || /^(docx?|odt|txt|rtf|md)$/.test(ext)) return "document";
// Paperless is an origin, not proof that a resource is a PDF. Do not infer format from a title.
if (element.kind === "external_ref") return element.external?.source === "paperless" ? "file" : "link";
return "file";
}
export function contentSourceSymbol(element = {}) {
return element.external?.source === "paperless" ? "source-archive" : null;
}