From e776e9e6c1d8a28c1088476d108d24174b1492fd Mon Sep 17 00:00:00 2001 From: skjnldsv Date: Sun, 20 Sep 2026 23:41:41 +0200 Subject: [PATCH] feat(images): open JPEG 2000 where the server renders it Picks up nextcloud/viewer#2587 by mexthecat, which was right and had nothing to stand on: the list it adds to is filtered against the server's enabled preview providers, and none of them claimed image/jp2, so the entry was dropped again on every server. nextcloud/server#64603 adds the provider, so the entry now means something wherever an admin enables it, which is how tiff beside it has always worked. Co-authored-by: mexthecat Assisted-by: ClaudeCode:claude-opus-5 Signed-off-by: skjnldsv --- __tests__/previewProviders.spec.ts | 16 ++++++++++++++++ lib/models/images.ts | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/__tests__/previewProviders.spec.ts b/__tests__/previewProviders.spec.ts index 05520b7..d79990d 100644 --- a/__tests__/previewProviders.spec.ts +++ b/__tests__/previewProviders.spec.ts @@ -39,6 +39,22 @@ describe('preview providers', () => { expect(handler.enabled([makeFile({ mime: 'image/heic' })])).toBe(false) }) + it('opens a JPEG 2000 where the server renders one', async () => { + // Nothing decodes this in the browser, so the server having a + // provider for it is the whole of the support + const handler = await registerWithProviders(['/image\\/jp2/']) + + expect(handler.enabled([makeFile({ mime: 'image/jp2' })])).toBe(true) + }) + + it('leaves a JPEG 2000 alone on a server that cannot render one', async () => { + // Which is every server until an admin enables the provider, so + // offering it would open a file that can only come up empty + const handler = await registerWithProviders(['/image\\/jpeg/']) + + expect(handler.enabled([makeFile({ mime: 'image/jp2' })])).toBe(false) + }) + it('falls back to the browser mimes when the capability is missing', async () => { const handler = await registerWithProviders(undefined) diff --git a/lib/models/images.ts b/lib/models/images.ts index 1009f0e..716dcae 100644 --- a/lib/models/images.ts +++ b/lib/models/images.ts @@ -27,6 +27,10 @@ const enabledPreviewProviders = (getCapabilities() as PreviewCapabilities).core? const previewSupportedMimes = [ 'image/heic', 'image/heif', + // No browser decodes JPEG 2000, and libgd cannot either, so this one + // depends entirely on the server rendering it. Filtered out below + // wherever no provider is enabled for it, as tiff already is. + 'image/jp2', 'image/tiff', 'image/x-xbitmap', 'image/emf',