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',