Courriels - gabarit HTML brande (logo, couleur #b71c1c, bouton, mention ne pas repondre) dans backend/src/lib/mail-template.ts ; repli texte conserve - MailMessage gagne un champ html optionnel - MAIL_LOGO_URL (defaut PUBLIC_ORIGIN/logo.png) + logo.png servi par le front - notification au nouvel utilisateur a la creation du compte admin - forgot-password, email-change et reset-password passent par le gabarit Espace disque - diskUsage() (statfs) dans storage.ts (total/free/available) - upload et avatar refuses si le disque est plein (507 INSUFFICIENT_STORAGE) - quota d'emplacement borne par la capacite reelle du disque - statistiques disque exposees aux endpoints admin Exploitation - make purge-logs : vide le journal d'audit - make reset : cloud vierge en conservant les administrateurs - docker/reset-cloud.sql ; documentation deployment.md et api.md
133 lines
6.1 KiB
TypeScript
133 lines
6.1 KiB
TypeScript
import type { Config } from "./config.js";
|
|
|
|
/**
|
|
* Gabarit de courriel de marque, sans dependance ni feuille de style externe :
|
|
* les clients de messagerie n'interpretent qu'une partie du CSS, tout est donc
|
|
* ecrit en ligne et pose sur des tableaux, y compris pour Outlook.
|
|
*/
|
|
|
|
export interface Branding {
|
|
appName: string;
|
|
origin: string;
|
|
logoUrl: string;
|
|
color: string;
|
|
/** Adresse d'expedition, reprise en pied pour dire ou ne pas repondre. */
|
|
footer: string;
|
|
}
|
|
|
|
export const branding = (config: Config): Branding => ({
|
|
appName: "CoHaiSe Cloud",
|
|
origin: config.PUBLIC_ORIGIN,
|
|
logoUrl: config.MAIL_LOGO_URL ?? new URL("/logo.png", config.PUBLIC_ORIGIN).toString(),
|
|
color: "#b71c1c",
|
|
footer: config.SMTP_FROM,
|
|
});
|
|
|
|
export interface MailContent {
|
|
/** Aperçu affiche par le client, avant ouverture (texte brut). */
|
|
preview: string;
|
|
heading: string;
|
|
intro: string;
|
|
paragraphs?: string[];
|
|
/** Identifiants d'acces, presentes dans un encadre monospace. */
|
|
credentials?: { email: string; password: string };
|
|
cta?: { label: string; url: string };
|
|
note?: string;
|
|
}
|
|
|
|
export interface RenderedMail {
|
|
html: string;
|
|
text: string;
|
|
}
|
|
|
|
const escapeHtml = (value: string): string =>
|
|
value
|
|
.replace(/&/g, "&")
|
|
.replace(/</g, "<")
|
|
.replace(/>/g, ">")
|
|
.replace(/"/g, """)
|
|
.replace(/'/g, "'");
|
|
|
|
const FONT = "-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif";
|
|
|
|
export const renderMail = (brand: Branding, content: MailContent): RenderedMail => {
|
|
const paragraphs = (content.paragraphs ?? [])
|
|
.map(
|
|
(paragraph) =>
|
|
`<p style="margin:0 0 16px;font-size:15px;line-height:1.6;color:#3f3f46;">${escapeHtml(paragraph)}</p>`,
|
|
)
|
|
.join("");
|
|
|
|
const credentials = content.credentials
|
|
? `
|
|
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="margin:0 0 24px;background:#fafafa;border:1px solid #e4e4e7;border-radius:10px;">
|
|
<tr><td style="padding:16px 18px;font-family:${FONT};">
|
|
<p style="margin:0 0 10px;font:600 12px ${FONT};letter-spacing:.04em;text-transform:uppercase;color:#71717a;">Vos identifiants</p>
|
|
<p style="margin:0 0 6px;font:400 14px ${FONT};color:#3f3f46;">Adresse : <strong style="color:#18181b;">${escapeHtml(content.credentials.email)}</strong></p>
|
|
<p style="margin:0;font:400 14px ${FONT};color:#3f3f46;">Mot de passe temporaire :
|
|
<span style="font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:14px;background:#ffffff;border:1px solid #e4e4e7;border-radius:6px;padding:2px 8px;color:#18181b;">${escapeHtml(content.credentials.password)}</span>
|
|
</p>
|
|
</td></tr>
|
|
</table>`
|
|
: "";
|
|
|
|
const cta = content.cta
|
|
? `
|
|
<table role="presentation" cellpadding="0" cellspacing="0" style="margin:0 0 24px;">
|
|
<tr><td align="center" style="background:${brand.color};border-radius:10px;">
|
|
<a href="${escapeHtml(content.cta.url)}" style="display:inline-block;padding:13px 30px;font:600 15px ${FONT};color:#ffffff;text-decoration:none;">${escapeHtml(content.cta.label)}</a>
|
|
</td></tr>
|
|
</table>`
|
|
: "";
|
|
|
|
const note = content.note
|
|
? `
|
|
<p style="margin:0;font:400 13px ${FONT};line-height:1.6;color:#71717a;">${escapeHtml(content.note)}</p>`
|
|
: "";
|
|
|
|
const html = `<!doctype html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<meta name="color-scheme" content="light only">
|
|
<title>${escapeHtml(content.heading)}</title>
|
|
</head>
|
|
<body style="margin:0;padding:0;background:#f4f4f5;">
|
|
<div style="display:none;max-height:0;overflow:hidden;opacity:0;color:#f4f4f5;">${escapeHtml(content.preview)}</div>
|
|
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f4f4f5;padding:32px 12px;">
|
|
<tr><td align="center">
|
|
<table role="presentation" width="560" cellpadding="0" cellspacing="0" style="width:100%;max-width:560px;background:#ffffff;border:1px solid #e4e4e7;border-radius:14px;overflow:hidden;">
|
|
<tr><td style="background:${brand.color};padding:18px 28px;">
|
|
<a href="${escapeHtml(brand.origin)}" style="text-decoration:none;">
|
|
<img src="${escapeHtml(brand.logoUrl)}" width="34" height="34" alt="" style="vertical-align:middle;border:0;border-radius:9px;background:#ffffff;">
|
|
<span style="vertical-align:middle;margin-left:12px;font:600 17px ${FONT};color:#ffffff;">${escapeHtml(brand.appName)}</span>
|
|
</a>
|
|
</td></tr>
|
|
<tr><td style="padding:32px 28px 6px;font-family:${FONT};">
|
|
<h1 style="margin:0 0 16px;font:600 21px ${FONT};line-height:1.3;color:#18181b;">${escapeHtml(content.heading)}</h1>
|
|
<p style="margin:0 0 16px;font:400 15px ${FONT};line-height:1.6;color:#3f3f46;">${escapeHtml(content.intro)}</p>
|
|
${paragraphs}${credentials}${cta}${note}
|
|
</td></tr>
|
|
<tr><td style="padding:20px 28px 28px;font-family:${FONT};">
|
|
<hr style="border:0;border-top:1px solid #e4e4e7;margin:0 0 16px;">
|
|
<p style="margin:0 0 4px;font:400 12px ${FONT};line-height:1.6;color:#71717a;">Message automatique : merci de ne pas repondre a cet e-mail.</p>
|
|
<p style="margin:0;font:400 12px ${FONT};line-height:1.6;color:#a1a1aa;">${escapeHtml(brand.footer)}</p>
|
|
</td></tr>
|
|
</table>
|
|
<p style="margin:18px 0 0;font:400 12px ${FONT};color:#a1a1aa;">${escapeHtml(brand.appName)} — <a href="${escapeHtml(brand.origin)}" style="color:#a1a1aa;">${escapeHtml(brand.origin.replace(/^https?:\/\//, ""))}</a></p>
|
|
</td></tr>
|
|
</table>
|
|
</body>
|
|
</html>`;
|
|
|
|
const lines = [content.intro, ...(content.paragraphs ?? [])];
|
|
if (content.credentials) {
|
|
lines.push(`Adresse : ${content.credentials.email}`, `Mot de passe temporaire : ${content.credentials.password}`);
|
|
}
|
|
if (content.cta) lines.push(`${content.cta.label} : ${content.cta.url}`);
|
|
if (content.note) lines.push(content.note);
|
|
lines.push("", "Message automatique : merci de ne pas repondre a cet e-mail.", brand.footer);
|
|
|
|
return { html, text: lines.join("\n") };
|
|
}; |