diff --git a/app/__test__/media/mime-types.spec.ts b/app/__test__/media/mime-types.spec.ts index dd13f7c..d326aca 100644 --- a/app/__test__/media/mime-types.spec.ts +++ b/app/__test__/media/mime-types.spec.ts @@ -71,6 +71,7 @@ describe("media/mime-types", () => { ["application/zip", "zip"], ["text/tab-separated-values", "tsv"], ["application/zip", "zip"], + ["application/pdf", "pdf"], ] as const; for (const [mime, ext] of tests) { @@ -88,6 +89,7 @@ describe("media/mime-types", () => { ["image.jpeg", "jpeg"], ["-473Wx593H-466453554-black-MODEL.jpg", "jpg"], ["-473Wx593H-466453554-black-MODEL.avif", "avif"], + ["file.pdf", "pdf"], ] as const; for (const [filename, ext] of tests) { @@ -102,4 +104,28 @@ describe("media/mime-types", () => { const [, ext] = getRandomizedFilename(file).split("."); expect(ext).toBe("jpg"); }); + + test("getRandomizedFilename with body", async () => { + // should keep "pdf" + const [, ext] = getRandomizedFilename( + new File([""], "file.pdf", { type: "application/pdf" }), + ).split("."); + expect(ext).toBe("pdf"); + + { + // no ext, should use "pdf" only for known formats + const [, ext] = getRandomizedFilename( + new File([""], "file", { type: "application/pdf" }), + ).split("."); + expect(ext).toBe("pdf"); + } + + { + // wrong ext, should keep the wrong one + const [, ext] = getRandomizedFilename( + new File([""], "file.what", { type: "application/pdf" }), + ).split("."); + expect(ext).toBe("what"); + } + }); }); diff --git a/app/src/media/storage/mime-types-tiny.ts b/app/src/media/storage/mime-types-tiny.ts index e7c42bb..6a3e241 100644 --- a/app/src/media/storage/mime-types-tiny.ts +++ b/app/src/media/storage/mime-types-tiny.ts @@ -3,7 +3,7 @@ export const Q = { audio: ["ogg"], image: ["jpeg", "png", "gif", "webp", "bmp", "tiff", "avif", "heic", "heif"], text: ["html", "css", "mdx", "yaml", "vcard", "csv", "vtt"], - application: ["zip", "xml", "toml", "json", "json5"], + application: ["zip", "xml", "toml", "json", "json5", "pdf"], font: ["woff", "woff2", "ttf", "otf"], } as const; @@ -19,7 +19,7 @@ const c = { export const M = new Map([ ["7z", c.z], ["7zip", c.z], - ["ai", c.a("pdf")], + ["ai", c.a("postscript")], ["apk", c.a("vnd.android.package-archive")], ["doc", c.a("msword")], ["docx", `${c.vnd}.wordprocessingml.document`],