Skip to content

Commit

Permalink
Preview: PDF: dont count pages (#2276)
Browse files Browse the repository at this point in the history
  • Loading branch information
nl0 authored Jul 16, 2021
1 parent d5b37ba commit 4eb2c68
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
8 changes: 3 additions & 5 deletions catalog/app/components/Preview/loaders/Pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@ async function loadPdf({ endpoint, sign, handle }) {
input: 'pdf',
output: 'raw',
size: 'w1024h768',
countPages: true,
})
const r = await fetch(`${endpoint}/thumbnail${search}`)
if (r.status >= 400) {
const text = await r.text()
throw new HTTPError(r, text)
}
const { page_count: pages } = JSON.parse(r.headers.get('X-Quilt-Info') || '{}')
const firstPageBlob = await r.blob()
return PreviewData.Pdf({ handle, pages, firstPageBlob })
return PreviewData.Pdf({ handle, firstPageBlob })
} catch (e) {
if (e instanceof HTTPError && e.json && e.json.error === 'Forbidden') {
if (e.json.text && e.json.text.match(utils.GLACIER_ERROR_RE)) {
if (e instanceof HTTPError && e.json?.error === 'Forbidden') {
if (e.json.text?.match(utils.GLACIER_ERROR_RE)) {
throw PreviewError.Archived({ handle })
}
throw PreviewError.Forbidden({ handle })
Expand Down
19 changes: 5 additions & 14 deletions catalog/app/components/Preview/renderers/Pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const useStyles = M.makeStyles((t) => ({
},
}))

function Pdf({ handle, firstPageBlob, pages }, { className, ...props }) {
function Pdf({ handle, firstPageBlob }, { className, ...props }) {
const endpoint = Config.use().binaryApiGatewayEndpoint
const sign = AWS.Signer.useS3Signer()
const classes = useStyles()
Expand All @@ -130,10 +130,9 @@ function Pdf({ handle, firstPageBlob, pages }, { className, ...props }) {
const src = useBlob(blob)

const next = React.useCallback(() => {
if (page >= pages) return
setPage(page + 1)
setPageValue(page + 1)
}, [setPage, setPageValue, page, pages])
}, [setPage, setPageValue, page])

const prev = React.useCallback(() => {
if (page <= 1) return
Expand All @@ -153,15 +152,12 @@ function Pdf({ handle, firstPageBlob, pages }, { className, ...props }) {
const parsed = parseInt(val, 10)
if (Number.isNaN(parsed) || parsed < 1) {
setPageValue(page)
} else if (parsed > pages) {
setPage(pages)
setPageValue(pages)
} else {
setPage(parsed)
setPageValue(parsed)
}
},
[setPage, setPageValue, page, pages],
[setPage, setPageValue, page],
)

const handleBlur = React.useCallback(
Expand Down Expand Up @@ -217,14 +213,9 @@ function Pdf({ handle, firstPageBlob, pages }, { className, ...props }) {
onChange={handlePageChange}
onBlur={handleBlur}
onKeyDown={handleKey}
/>{' '}
/ {pages}
/>
</M.Typography>
<M.IconButton
onClick={next}
disabled={page >= pages}
className={cx(classes.btn, classes.next)}
>
<M.IconButton onClick={next} className={cx(classes.btn, classes.next)}>
<M.Icon fontSize="inherit">chevron_right</M.Icon>
</M.IconButton>
</div>
Expand Down
3 changes: 2 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
* [Changed] Scan more bytes (first 128 KiB) when trying to detect if a JSON file is a Vega visualization ([#2229](https://github.com/quiltdata/quilt/pull/2229))
* [Changed] Use GraphQL for fetching and editing buckets ([#2240](https://github.com/quiltdata/quilt/pull/2240))
* [Changed] Use registry for search requests ([#2242](https://github.com/quiltdata/quilt/pull/2242))
* [Changed] Enhance quilt_summarize.json format, support title, description and multi-column layout ([#2245](https://github.com/quiltdata/quilt/pull/2245))
* [Changed] Enhance `quilt_summarize.json` format, support title, description and multi-column layout ([#2245](https://github.com/quiltdata/quilt/pull/2245))
* [Changed] PDF preview: don't count pages ([#2276](https://github.com/quiltdata/quilt/pull/2276))
* [Fixed] `UnicodeDecodeError` in indexer and pkgselect lambdas ([#2123](https://github.com/quiltdata/quilt/pull/2123))
* [Fixed] Catch and display package-related errors properly ("no such package" and "bad revision") ([#2160](https://github.com/quiltdata/quilt/pull/2160))
* [Fixed] Crashing `pkgselect` lambda's folder view on an empty manifest ([#2147](https://github.com/quiltdata/quilt/pull/2147))
Expand Down

0 comments on commit 4eb2c68

Please sign in to comment.