remove uploads from repo but keep empty folder
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
import puppeteer from 'puppeteer';
|
||||
|
||||
/**
|
||||
* Konvertiert HTML zu PDF mit Puppeteer
|
||||
*/
|
||||
export async function htmlToPdf(html: string): Promise<Buffer> {
|
||||
const browser = await puppeteer.launch({
|
||||
headless: true,
|
||||
args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
||||
});
|
||||
|
||||
try {
|
||||
const page = await browser.newPage();
|
||||
await page.setContent(html, { waitUntil: 'networkidle0' });
|
||||
|
||||
const pdfBuffer = await page.pdf({
|
||||
format: 'A4',
|
||||
margin: {
|
||||
top: '20mm',
|
||||
right: '15mm',
|
||||
bottom: '20mm',
|
||||
left: '15mm',
|
||||
},
|
||||
printBackground: true,
|
||||
});
|
||||
|
||||
return Buffer.from(pdfBuffer);
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Baut ein HTML-Dokument für eine E-Mail mit Header
|
||||
*/
|
||||
export function buildEmailHtml(email: {
|
||||
subject?: string | null;
|
||||
fromAddress: string;
|
||||
fromName?: string | null;
|
||||
toAddresses: string;
|
||||
receivedAt: Date;
|
||||
htmlBody?: string | null;
|
||||
textBody?: string | null;
|
||||
}): string {
|
||||
const formatDate = (date: Date) => {
|
||||
return new Date(date).toLocaleString('de-DE', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
});
|
||||
};
|
||||
|
||||
// To-Adressen parsen (JSON Array)
|
||||
let toList: string[] = [];
|
||||
try {
|
||||
toList = JSON.parse(email.toAddresses);
|
||||
} catch {
|
||||
toList = [email.toAddresses];
|
||||
}
|
||||
|
||||
const fromDisplay = email.fromName
|
||||
? `${email.fromName} <${email.fromAddress}>`
|
||||
: email.fromAddress;
|
||||
|
||||
const body = email.htmlBody || `<pre style="white-space: pre-wrap; font-family: inherit;">${email.textBody || ''}</pre>`;
|
||||
|
||||
return `
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<style>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
font-size: 12pt;
|
||||
line-height: 1.5;
|
||||
color: #333;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.email-header {
|
||||
background: #f5f5f5;
|
||||
border-bottom: 2px solid #ddd;
|
||||
padding: 15px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.email-header h1 {
|
||||
margin: 0 0 15px 0;
|
||||
font-size: 16pt;
|
||||
color: #222;
|
||||
}
|
||||
.email-header table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
.email-header th {
|
||||
text-align: left;
|
||||
width: 60px;
|
||||
padding: 3px 10px 3px 0;
|
||||
color: #666;
|
||||
font-weight: normal;
|
||||
vertical-align: top;
|
||||
}
|
||||
.email-header td {
|
||||
padding: 3px 0;
|
||||
}
|
||||
.email-body {
|
||||
padding: 0 5px;
|
||||
}
|
||||
.email-body img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="email-header">
|
||||
<h1>${escapeHtml(email.subject || '(Kein Betreff)')}</h1>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Von:</th>
|
||||
<td>${escapeHtml(fromDisplay)}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>An:</th>
|
||||
<td>${escapeHtml(toList.join(', '))}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Datum:</th>
|
||||
<td>${formatDate(email.receivedAt)}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="email-body">
|
||||
${body}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`.trim();
|
||||
}
|
||||
|
||||
function escapeHtml(str: string): string {
|
||||
return str
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"');
|
||||
}
|
||||
Reference in New Issue
Block a user