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:
@@ -309,85 +309,3 @@ func (h *ReviewHandler) GetReview(c *gin.Context) {
|
||||
"result": reviewResult,
|
||||
})
|
||||
}
|
||||
|
||||
// GeneratePDF handles POST /api/repos/:id/review/pdf — generate and download a PDF report.
|
||||
func (h *ReviewHandler) GeneratePDF(c *gin.Context) {
|
||||
user := GetCurrentUser(c)
|
||||
if user == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthenticated"})
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Param("id")
|
||||
|
||||
// Get repo info (scoped to user)
|
||||
var repoURL string
|
||||
err := h.db.QueryRow(`SELECT url FROM repositories WHERE id = ? AND user_id = ?`, id, user.ID).Scan(&repoURL)
|
||||
if err == sql.ErrNoRows {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "repository not found"})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
// Parse request
|
||||
var req struct {
|
||||
AnalysisID int64 `json:"analysis_id" binding:"required"`
|
||||
Base string `json:"base"`
|
||||
Head string `json:"head"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "analysis_id is required"})
|
||||
return
|
||||
}
|
||||
|
||||
// Verify analysis belongs to user
|
||||
var analysisResult, baseRef, headRef string
|
||||
var createdAt string
|
||||
err = h.db.QueryRow(`SELECT result, base_ref, head_ref, created_at FROM analyses WHERE id = ? AND user_id = ?`, req.AnalysisID, user.ID).Scan(&analysisResult, &baseRef, &headRef, &createdAt)
|
||||
if err == sql.ErrNoRows {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "analysis not found"})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
// Load all notes for this analysis
|
||||
notes, err := services.GetNotes(h.db, req.AnalysisID, "")
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
// Build report data
|
||||
reportData := services.ReportData{
|
||||
RepoURL: repoURL,
|
||||
BaseRef: baseRef,
|
||||
HeadRef: headRef,
|
||||
ReviewedAt: createdAt,
|
||||
AnalysisID: req.AnalysisID,
|
||||
Result: analysisResult,
|
||||
Notes: notes,
|
||||
}
|
||||
|
||||
// Generate PDF
|
||||
pdfBytes, err := services.GeneratePDFReport(reportData)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "PDF generation failed: " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
// Return PDF as download
|
||||
dateStr := createdAt
|
||||
if len(dateStr) > 10 {
|
||||
dateStr = dateStr[:10]
|
||||
}
|
||||
filename := fmt.Sprintf("pr-helper-review-%s.pdf", dateStr)
|
||||
c.Header("Content-Type", "application/pdf")
|
||||
c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s", filename))
|
||||
c.Data(http.StatusOK, "application/pdf", pdfBytes)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user