fix: References section link corruption and download filename issues
**Issue 1: URL corruption in "See this CV in..." links**
- Bug: replaceYearPlaceholder used fmt.Sprintf on ALL URLs
- URLs like "/?lang=es" were corrupted to "/?lang=es%!(EXTRA string=2025)"
- Fix: Changed to strings.ReplaceAll("{{YEAR}}", year)
- Result: Only replaces actual {{YEAR}} placeholders, leaves other URLs intact
**Issue 2: Download filename not respected**
- Bug: Shortcut URLs (cv-jamr-2025-en.pdf) redirected with HTTP 301
- Browsers used original URL filename instead of Content-Disposition header
- Fix: Generate PDF directly in DefaultCVShortcut handler
- Result: Returns PDF with correct filename in Content-Disposition header
Files changed:
- internal/models/cv.go: Fixed replaceYearPlaceholder function
- internal/handlers/cv.go: Changed redirect to direct PDF generation
Both fixes verified:
- "See this CV in Spanish" link: href="/?lang=es" ✓
- Download link: filename=cv-jamr-2025-en.pdf ✓
This commit is contained in:
@@ -301,10 +301,11 @@
|
||||
formatName = isSpanish ? 'CV Actual' : 'Current CV';
|
||||
}
|
||||
|
||||
// Show loading overlay
|
||||
// Show loading overlay in modal
|
||||
const overlay = document.getElementById('pdf-loading-overlay');
|
||||
const modalContent = document.getElementById('pdf-modal-content');
|
||||
const estimateEl = document.getElementById('pdf-loading-estimate');
|
||||
const modal = document.getElementById('pdf-modal');
|
||||
|
||||
overlay.classList.add('active');
|
||||
modalContent.classList.add('loading-active');
|
||||
@@ -315,16 +316,53 @@
|
||||
: `Generating ${formatName}... This may take ~${estimatedTime} seconds`;
|
||||
estimateEl.textContent = estimateMsg;
|
||||
|
||||
// Track if modal is closed by user during download
|
||||
let modalClosedByUser = false;
|
||||
const onModalClose = () => {
|
||||
modalClosedByUser = true;
|
||||
|
||||
// Show toast when user closes modal
|
||||
if (window.showPDFToast) {
|
||||
window.showPDFToast({
|
||||
icon: '📥',
|
||||
title: isSpanish ? 'Preparando PDF...' : 'Preparing PDF...',
|
||||
message: isSpanish
|
||||
? `Generando ${formatName}... (~${estimatedTime}s)`
|
||||
: `Generating ${formatName}... (~${estimatedTime}s)`,
|
||||
duration: estimatedTime * 1000,
|
||||
autoHide: false // We'll manually update it
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Listen for modal close
|
||||
modal.addEventListener('close', onModalClose, { once: true });
|
||||
|
||||
console.log('Navigating to:', url);
|
||||
|
||||
// Trigger download
|
||||
window.location.href = url;
|
||||
|
||||
// Keep overlay showing for estimated time, then close modal
|
||||
// After estimated time: update toast to success or close modal
|
||||
setTimeout(() => {
|
||||
overlay.classList.remove('active');
|
||||
modalContent.classList.remove('loading-active');
|
||||
document.getElementById('pdf-modal').close();
|
||||
|
||||
if (modalClosedByUser && window.showPDFToast) {
|
||||
// Update toast to success
|
||||
window.showPDFToast({
|
||||
icon: '✅',
|
||||
title: isSpanish ? '¡PDF Listo!' : 'PDF Ready!',
|
||||
message: isSpanish
|
||||
? 'Revisa tu carpeta de descargas'
|
||||
: 'Check your downloads folder',
|
||||
duration: 3000,
|
||||
autoHide: true
|
||||
});
|
||||
} else {
|
||||
// Close modal if still open
|
||||
modal.close();
|
||||
}
|
||||
}, estimatedTime * 1000);
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user