diff --git a/src/components/extension-fallback.js b/src/components/extension-fallback.js index 5023fee..e4c3409 100644 --- a/src/components/extension-fallback.js +++ b/src/components/extension-fallback.js @@ -66,6 +66,7 @@ export default function ExtensionFallback() { Loading PDF}> Loading PDF} /> @@ -80,6 +81,7 @@ export default function ExtensionFallback() { Loading PDF}> Loading PDF} /> diff --git a/src/components/pdf-viewer.js b/src/components/pdf-viewer.js index 77b3ac4..37d1a5a 100644 --- a/src/components/pdf-viewer.js +++ b/src/components/pdf-viewer.js @@ -11,7 +11,7 @@ const CSS_MAX_WIDTH = 900; // keep in sync with CSS * This implement an infinite scroll mechanism so that we never load more than a * few pages at the time */ -export default function PdfViewer({ docId, loading }) { +export default function PdfViewer({ docId, pdfUrl, loading }) { const containerEl = useRef(null); const getWidth = () => { const el = containerEl.current; @@ -79,7 +79,7 @@ export default function PdfViewer({ docId, loading }) { { let dims = []; diff --git a/src/routes/api-routes.js b/src/routes/api-routes.js index f308e76..ed0a772 100644 --- a/src/routes/api-routes.js +++ b/src/routes/api-routes.js @@ -375,16 +375,21 @@ router.get( * due to cross origin restriction we need to proxy the PDF */ router.get('/pdf', async (req, res, next) => { - let pdfUrl; - const preprintId = req.query.preprintId; - try { - const body = await req.db.get(`preprint:${preprintId}`); - pdfUrl = getPdfUrl(body); - if (!pdfUrl) { - return next(createError(500, `Could not determine PDF from prereview: ${JSON.stringify(body)}`)); + let { preprintId, pdfUrl } = req.query; + + // If we already have the pdfUrl, there's no need to look in the database. + // The pdfUrl is present in the case where the preprint is not in the database yet, + // but we were able to resolve it. + if (!pdfUrl) { + try { + const body = await req.db.get(`preprint:${preprintId}`); + pdfUrl = getPdfUrl(body); + if (!pdfUrl) { + return next(createError(500, `Could not determine PDF from prereview: ${JSON.stringify(body)}`)); + } + } catch (err) { + return next(createError(500, `Prereview query failed: ${preprintId} ${JSON.stringify(err)}`)); } - } catch (err) { - return next(createError(500, `Prereview query failed: ${preprintId} ${JSON.stringify(err)}`)); } if (!pdfUrl) {