Skip to content

Commit

Permalink
fix: Use files etag for cache busting of preview images
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Oct 3, 2023
1 parent ff3b9fa commit 4114aad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/composables/preview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ describe('preview composable', () => {
expect(wrapper.text()).toMatch('/core/preview?fileId=2')
})

it('uses etag for cache busting', () => {
const previewNode = new File({
...createData('tst.txt', 'text/plain'),
attributes: {
etag: 'the-etag',
},
})

const { previewURL } = usePreviewURL(previewNode)
expect(previewURL.value?.searchParams.get('c')).toBe('the-etag')
})

it('uses Nodes previewUrl if available', () => {
const previewNode = new File({
...createData('text.txt', 'text/plain'),
Expand Down
3 changes: 3 additions & 0 deletions lib/composables/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export function getPreviewURL(node: Node, options: PreviewOptions = {}) {

// Handle cropping
url.searchParams.set('a', options.cropPreview === true ? '0' : '1')

// cache busting
url.searchParams.set('c', `${node.attributes.etag}`)
return url
} catch (e) {
return null
Expand Down

0 comments on commit 4114aad

Please sign in to comment.