mirror of
https://github.com/mmahdium/portfolio.git
synced 2026-08-16 21:14:31 +03:30
feat(resume): add PDF download functionality with server endpoint
- Add useResumePdf composable for client-side PDF download handling - Implement /api/resume/pdf server endpoint for PDF generation - Add puppeteer and @sparticuz/chromium dependencies for PDF rendering - Add puppeteer-core for headless browser automation - Update Vercel configuration to support PDF generation - Include loading state management and error handling with toast notifications - Implement blob download with automatic filename generation - Add memory leak prevention through object URL revocation
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* PDF Download Composable
|
||||
* Handles PDF download logic with loading state and error handling
|
||||
*/
|
||||
|
||||
export function useResumePdf() {
|
||||
const isGenerating = ref(false)
|
||||
const toast = useToast()
|
||||
const { getPdfFilename } = useResumeData()
|
||||
|
||||
async function downloadPdf() {
|
||||
isGenerating.value = true
|
||||
|
||||
try {
|
||||
// Fetch PDF as blob (AC1)
|
||||
const response = await $fetch('/api/resume/pdf', {
|
||||
responseType: 'blob',
|
||||
})
|
||||
|
||||
// Create object URL from blob (AC2)
|
||||
const url = URL.createObjectURL(response as Blob)
|
||||
|
||||
// Create temporary anchor element and trigger download
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = getPdfFilename() // AC3: filename from composable
|
||||
a.click()
|
||||
|
||||
// Revoke object URL to prevent memory leaks (AC8)
|
||||
URL.revokeObjectURL(url)
|
||||
} catch (error) {
|
||||
// Error handling (AC6)
|
||||
console.error('PDF generation failed:', error)
|
||||
|
||||
toast.add({
|
||||
title: 'Error generating PDF',
|
||||
description: 'Please try again',
|
||||
color: 'error',
|
||||
})
|
||||
} finally {
|
||||
// Always reset loading state (AC7)
|
||||
isGenerating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// Return composable interface (AC4, AC5)
|
||||
return {
|
||||
isGenerating,
|
||||
downloadPdf,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user