Skip to content

Commit 50a2d35

Browse files
committed
fix: mime type error
1 parent 88ad87f commit 50a2d35

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

packages/scaffold/src/utils/mime.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { extname } from "node:path";
22

3-
const mimeTypes: { [key: string]: string[] } = {
4-
"application/json": ["json"],
5-
"application/x-xpinstall": ["xpi"],
3+
const mimeTypes: { [key: string]: string } = {
4+
json: "application/json",
5+
xpi: "application/x-xpinstall",
66
};
77

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

1111
for (const type in mimeTypes) {
12-
if (mimeTypes[type].includes(ext))
13-
return type;
12+
if (ext === `.${type}`)
13+
return mimeTypes[type];
1414
}
1515

1616
return undefined;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { describe, expect, it } from "vitest";
2+
import { getMimeTypeByFileName } from "../../src/utils/mime.js";
3+
4+
describe("mime", () => {
5+
describe("getMimeTypeByFileName", () => {
6+
it("should return application/json for json files", () => {
7+
expect(getMimeTypeByFileName("test.json")).toEqual("application/json");
8+
});
9+
10+
it("should return application/x-xpinstall for xpi files", () => {
11+
expect(getMimeTypeByFileName("test.xpi")).toEqual("application/x-xpinstall");
12+
});
13+
14+
it("should return undefined for unknown file types", () => {
15+
expect(getMimeTypeByFileName("test.unknown")).toBeUndefined();
16+
});
17+
});
18+
});

0 commit comments

Comments
 (0)