refactor: replace chromedp with browser native print for PDF export

Remove chromedp dependency, use window.print() instead. Docker image no longer needs Chromium (~200MB smaller).

- Delete services/pdf.go and templates/reports/review.html

- Remove PDF API route POST /api/repos/:id/review/pdf

- Add @media print CSS to review page

- Remove chromium from Dockerfile
This commit is contained in:
2026-06-20 22:26:46 +08:00
parent 37aa9c0a33
commit 6c60b767df
10 changed files with 88 additions and 510 deletions
+4 -44
View File
@@ -149,55 +149,15 @@ const NoteEditor = {
},
/**
* Trigger PDF export and download.
* Trigger PDF export via browser's native print dialog.
* Users can select "Save as PDF" in the print dialog.
*/
async exportPDF() {
exportPDF() {
if (!this.analysisId) {
showToast('请先完成审查再导出 PDF', 'warning');
return;
}
const btn = document.getElementById('btn-export-pdf');
if (btn) {
btn.disabled = true;
btn.textContent = '⏳ 生成中...';
}
try {
const resp = await fetch(`/api/repos/${this.repoId}/review/pdf`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'same-origin',
body: JSON.stringify({
analysis_id: this.analysisId,
base: document.getElementById('base-ref')?.value || '',
head: document.getElementById('head-ref')?.value || '',
}),
});
if (!resp.ok) {
const err = await resp.json();
throw new Error(err.error || 'PDF generation failed');
}
// Download the PDF
const blob = await resp.blob();
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `pr-helper-review-${new Date().toISOString().slice(0, 10)}.pdf`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
} catch (err) {
showToast('PDF 导出失败: ' + err.message, 'error');
} finally {
if (btn) {
btn.disabled = false;
btn.textContent = '📄 导出 PDF 报告';
}
}
window.print();
},
// ── Internal helpers ──────────────────────────────────────────