Skip to content

Commit ca7e3aa

Browse files
committed
detect more image types
Sync of <vercel/next.js#82118>
1 parent d00b3a1 commit ca7e3aa

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

.changeset/lucky-cups-live.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
detect more image types
6+
7+
Sync of <https://github.com/vercel/next.js/pull/82118>

packages/cloudflare/src/cli/templates/images.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,16 @@ const AVIF = "image/avif";
167167
const WEBP = "image/webp";
168168
const PNG = "image/png";
169169
const JPEG = "image/jpeg";
170+
const JXL = "image/jxl";
171+
const JP2 = "image/jp2";
172+
const HEIC = "image/heic";
170173
const GIF = "image/gif";
171174
const SVG = "image/svg+xml";
172175
const ICO = "image/x-icon";
173176
const ICNS = "image/x-icns";
174177
const TIFF = "image/tiff";
175178
const BMP = "image/bmp";
179+
const PDF = "application/pdf";
176180

177181
/**
178182
* Detects the content type by looking at the first few bytes of a file
@@ -216,6 +220,25 @@ export function detectContentType(buffer: Uint8Array) {
216220
if ([0x42, 0x4d].every((b, i) => buffer[i] === b)) {
217221
return BMP;
218222
}
223+
if ([0xff, 0x0a].every((b, i) => buffer[i] === b)) {
224+
return JXL;
225+
}
226+
if (
227+
[0x00, 0x00, 0x00, 0x0c, 0x4a, 0x58, 0x4c, 0x20, 0x0d, 0x0a, 0x87, 0x0a].every((b, i) => buffer[i] === b)
228+
) {
229+
return JXL;
230+
}
231+
if ([0, 0, 0, 0, 0x66, 0x74, 0x79, 0x70, 0x68, 0x65, 0x69, 0x63].every((b, i) => !b || buffer[i] === b)) {
232+
return HEIC;
233+
}
234+
if ([0x25, 0x50, 0x44, 0x46, 0x2d].every((b, i) => buffer[i] === b)) {
235+
return PDF;
236+
}
237+
if (
238+
[0x00, 0x00, 0x00, 0x0c, 0x6a, 0x50, 0x20, 0x20, 0x0d, 0x0a, 0x87, 0x0a].every((b, i) => buffer[i] === b)
239+
) {
240+
return JP2;
241+
}
219242
}
220243

221244
declare global {

0 commit comments

Comments
 (0)