From eaa8d0eedbb143b195502b5bb93b4429bcb965a3 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 3 Oct 2023 00:53:09 +0200 Subject: [PATCH] fix: Use files etag for cache busting of preview images Signed-off-by: Ferdinand Thiessen --- lib/composables/preview.spec.ts | 12 ++++++++++++ lib/composables/preview.ts | 3 +++ 2 files changed, 15 insertions(+) diff --git a/lib/composables/preview.spec.ts b/lib/composables/preview.spec.ts index a8a110238..85ce96dfb 100644 --- a/lib/composables/preview.spec.ts +++ b/lib/composables/preview.spec.ts @@ -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'), diff --git a/lib/composables/preview.ts b/lib/composables/preview.ts index 90c69cb61..dba8d6202 100644 --- a/lib/composables/preview.ts +++ b/lib/composables/preview.ts @@ -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