ultisuite-client/lib/api/map-message-attachments.ts
R3D347HR4Y f44dadc453
Some checks failed
E2E / Playwright e2e (push) Has been cancelled
feat(admin): add VirusTotal scan settings and mail UI
File policies API key field, conditional scan badge, safe policy merge.
2026-06-07 22:05:28 +02:00

40 lines
1.1 KiB
TypeScript

import type { EmailAttachment } from "@/lib/email-data"
import { resolveAttachmentKind } from "@/lib/attachment-display"
export interface ApiMessageAttachment {
id: string
filename: string
content_type: string
size: number
is_inline?: boolean
content_id?: string
drive_path?: string
virus_scan_status?: "clean" | "skipped" | "malicious"
}
export function mapApiAttachmentsToEmail(
list: ApiMessageAttachment[] | undefined
): EmailAttachment[] {
if (!list?.length) return []
return list
.filter((a) => !a.is_inline)
.map((a) => ({
id: a.id,
name: a.filename || "Pièce jointe",
kind: resolveAttachmentKind(a.filename, kindFromContentType(a.content_type)),
contentType: a.content_type || undefined,
drivePath: a.drive_path || undefined,
sizeBytes: a.size > 0 ? a.size : undefined,
virusScanStatus: a.virus_scan_status,
}))
}
function kindFromContentType(
contentType: string
): EmailAttachment["kind"] | undefined {
const ct = contentType.toLowerCase()
if (ct.includes("pdf")) return "pdf"
if (ct.startsWith("image/")) return "image"
return undefined
}