Skip to content

Commit

Permalink
fix: mime type error
Browse files Browse the repository at this point in the history
  • Loading branch information
northword committed Feb 3, 2025
1 parent 88ad87f commit 50a2d35
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/scaffold/src/utils/mime.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { extname } from "node:path";

const mimeTypes: { [key: string]: string[] } = {
"application/json": ["json"],
"application/x-xpinstall": ["xpi"],
const mimeTypes: { [key: string]: string } = {
json: "application/json",
xpi: "application/x-xpinstall",
};

export function getMimeTypeByFileName(filename: string) {
const ext = extname(filename);

for (const type in mimeTypes) {
if (mimeTypes[type].includes(ext))
return type;
if (ext === `.${type}`)
return mimeTypes[type];
}

return undefined;
Expand Down
18 changes: 18 additions & 0 deletions packages/scaffold/test/unit/mime.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { describe, expect, it } from "vitest";
import { getMimeTypeByFileName } from "../../src/utils/mime.js";

describe("mime", () => {
describe("getMimeTypeByFileName", () => {
it("should return application/json for json files", () => {
expect(getMimeTypeByFileName("test.json")).toEqual("application/json");
});

it("should return application/x-xpinstall for xpi files", () => {
expect(getMimeTypeByFileName("test.xpi")).toEqual("application/x-xpinstall");
});

it("should return undefined for unknown file types", () => {
expect(getMimeTypeByFileName("test.unknown")).toBeUndefined();
});
});
});

0 comments on commit 50a2d35

Please sign in to comment.