Parte de la actualización de obtención de documentos a partir del documentos_id
Ahora se usa documentos_id para obtener los documentos de referencia de minio, por lo que se cambiaron los nombres de las variables utilizadas
This commit is contained in:
@@ -7,7 +7,7 @@ import * as Icons from "lucide-react"
|
|||||||
import type { RefRow } from "@/types/RefRow"
|
import type { RefRow } from "@/types/RefRow"
|
||||||
|
|
||||||
// POST -> recibe blob PDF y (opcional) Content-Disposition
|
// POST -> recibe blob PDF y (opcional) Content-Disposition
|
||||||
async function fetchPdfBlob(url: string, body: { s3_file_path: string }) {
|
async function fetchPdfBlob(url: string, body: { documentos_id: string }) {
|
||||||
const res = await fetch(url, {
|
const res = await fetch(url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
@@ -35,6 +35,7 @@ export function DetailDialog({
|
|||||||
onClose: () => void
|
onClose: () => void
|
||||||
pdfUrl?: string
|
pdfUrl?: string
|
||||||
}) {
|
}) {
|
||||||
|
console.log("DetailDialog render", { row })
|
||||||
const [viewerUrl, setViewerUrl] = useState<string | null>(null)
|
const [viewerUrl, setViewerUrl] = useState<string | null>(null)
|
||||||
const [currentBlob, setCurrentBlob] = useState<Blob | null>(null)
|
const [currentBlob, setCurrentBlob] = useState<Blob | null>(null)
|
||||||
const [filename, setFilename] = useState<string>("archivo.pdf")
|
const [filename, setFilename] = useState<string>("archivo.pdf")
|
||||||
@@ -48,13 +49,15 @@ export function DetailDialog({
|
|||||||
const ctrl = new AbortController()
|
const ctrl = new AbortController()
|
||||||
|
|
||||||
async function load() {
|
async function load() {
|
||||||
if (!row?.s3_file_path) {
|
console.log(row)
|
||||||
|
if (!row?.documentos_id) {
|
||||||
setViewerUrl(null)
|
setViewerUrl(null)
|
||||||
setCurrentBlob(null)
|
setCurrentBlob(null)
|
||||||
|
console.warn("No hay documentos_id en el row")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const { blob, disposition } = await fetchPdfBlob(`${import.meta.env.VITE_BACK_ORIGIN}/api/get/documento`, { s3_file_path: row.s3_file_path })
|
const { blob, disposition } = await fetchPdfBlob(`${import.meta.env.VITE_BACK_ORIGIN}/api/get/documento`, { documentos_id: row.documentos_id })
|
||||||
if (ctrl.signal.aborted) return
|
if (ctrl.signal.aborted) return
|
||||||
const name = row.titulo_archivo ? `${row.titulo_archivo}.pdf` : filenameFromDisposition(disposition)
|
const name = row.titulo_archivo ? `${row.titulo_archivo}.pdf` : filenameFromDisposition(disposition)
|
||||||
setFilename(name)
|
setFilename(name)
|
||||||
@@ -94,8 +97,8 @@ export function DetailDialog({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Si no, vuelve a pedirlo (p. ej., si el user abre y descarga sin render previo)
|
// Si no, vuelve a pedirlo (p. ej., si el user abre y descarga sin render previo)
|
||||||
if (!row?.s3_file_path) throw new Error("No hay contenido para descargar.")
|
if (!row?.documentos_id) throw new Error("No hay contenido para descargar.")
|
||||||
const { blob, disposition } = await fetchPdfBlob(`${import.meta.env.VITE_BACK_ORIGIN}/api/get/documento`, { s3_file_path: row.s3_file_path })
|
const { blob, disposition } = await fetchPdfBlob(`${import.meta.env.VITE_BACK_ORIGIN}/api/get/documento`, { documentos_id: row.documentos_id })
|
||||||
const name = row.titulo_archivo ? `${row.titulo_archivo}.pdf` : filenameFromDisposition(disposition)
|
const name = row.titulo_archivo ? `${row.titulo_archivo}.pdf` : filenameFromDisposition(disposition)
|
||||||
const link = document.createElement("a")
|
const link = document.createElement("a")
|
||||||
const href = URL.createObjectURL(blob)
|
const href = URL.createObjectURL(blob)
|
||||||
|
|||||||
Reference in New Issue
Block a user