Refactorizacion de PDFs y cambio de biblioteca backend 1.0.22-
-Funcional Usuarios, exportar Pdfs front v1.0.25
This commit is contained in:
@@ -1865,17 +1865,39 @@ function InspectionDetailModal({ inspection, user, onClose, onUpdate }) {
|
||||
const response = await fetch(`${API_URL}/api/inspections/${inspection.id}/pdf`, {
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
})
|
||||
|
||||
if (response.ok) {
|
||||
const blob = await response.blob()
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = `inspeccion_${inspection.id}_${inspection.vehicle_plate || 'sin-patente'}.pdf`
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
window.URL.revokeObjectURL(url)
|
||||
const contentType = response.headers.get('content-type')
|
||||
if (contentType && contentType.includes('application/pdf')) {
|
||||
const blob = await response.blob()
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = `inspeccion_${inspection.id}_${inspection.vehicle_plate || 'sin-patente'}.pdf`
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
window.URL.revokeObjectURL(url)
|
||||
} else {
|
||||
const data = await response.json()
|
||||
if (data.pdf_url) {
|
||||
const pdfRes = await fetch(data.pdf_url)
|
||||
if (pdfRes.ok) {
|
||||
const pdfBlob = await pdfRes.blob()
|
||||
const pdfUrl = window.URL.createObjectURL(pdfBlob)
|
||||
const a = document.createElement('a')
|
||||
a.href = pdfUrl
|
||||
a.download = `inspeccion_${inspection.id}_${inspection.vehicle_plate || 'sin-patente'}.pdf`
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
window.URL.revokeObjectURL(pdfUrl)
|
||||
} else {
|
||||
alert('No se pudo descargar el PDF desde MinIO')
|
||||
}
|
||||
} else {
|
||||
alert('No se encontró la URL del PDF')
|
||||
}
|
||||
}
|
||||
} else {
|
||||
alert('Error al generar PDF')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user