fix(pdf-download): use pdfFile.build instead of regex-transforming pdfDownloadUrl
Build and Deploy Verso / deploy (push) Failing after 3h10m18s
Build and Deploy Verso / deploy (push) Failing after 3h10m18s
When a compile result is served from cache (fromCache: true), pdfDownloadUrl is set to the cached format `/download/.../build/editorId-buildId/output/cached/output.pdf`, which doesn't match the /compressed route. pdfFile.build always contains the raw buildId regardless of cache state, so use that to construct the URL directly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
080de97632
commit
e123c06c81
+12
-7
@@ -31,7 +31,7 @@ function filenameFromDisposition(disposition: string | null, ext: string) {
|
||||
}
|
||||
|
||||
function PdfHybridDownloadButton() {
|
||||
const { pdfDownloadUrl, pdfFile, showLogs } = useCompileContext()
|
||||
const { pdfDownloadUrl, pdfFile, showLogs, clsiServerId } = useCompileContext()
|
||||
const { sendEvent } = useEditorAnalytics()
|
||||
const { projectId } = useProjectContext()
|
||||
const { t } = useTranslation()
|
||||
@@ -67,11 +67,16 @@ function PdfHybridDownloadButton() {
|
||||
setDownloading(true)
|
||||
setDownloadError(null)
|
||||
try {
|
||||
// Derive the compressed URL from the existing pdfDownloadUrl by appending /compressed
|
||||
const compressedUrl = pdfDownloadUrl.replace(
|
||||
/\/output\.pdf(\?|$)/,
|
||||
`/output.pdf/compressed$1`
|
||||
) + (pdfDownloadUrl.includes('?') ? '&' : '?') + `quality=${downloadQuality}`
|
||||
// Use pdfFile.build (always the raw buildId, even for cached compiles) so
|
||||
// the URL matches our /compressed route regardless of fromCache state.
|
||||
const buildId = pdfFile?.build
|
||||
if (!buildId) {
|
||||
setDownloadError(t('pdf_download_compression_failed'))
|
||||
return
|
||||
}
|
||||
const params = new URLSearchParams({ quality: downloadQuality })
|
||||
if (clsiServerId) params.set('clsiserverid', clsiServerId)
|
||||
const compressedUrl = `/download/project/${projectId}/build/${buildId}/output/output.pdf/compressed?${params}`
|
||||
const response = await fetch(compressedUrl, { credentials: 'same-origin' })
|
||||
if (!response.ok) {
|
||||
setDownloadError(t('pdf_download_compression_failed'))
|
||||
@@ -95,7 +100,7 @@ function PdfHybridDownloadButton() {
|
||||
} finally {
|
||||
setDownloading(false)
|
||||
}
|
||||
}, [pdfDownloadUrl, downloadQuality, t])
|
||||
}, [pdfDownloadUrl, pdfFile, clsiServerId, projectId, downloadQuality, t])
|
||||
|
||||
const dismiss = useCallback(() => {
|
||||
requestIdRef.current += 1
|
||||
|
||||
Reference in New Issue
Block a user