diff --git a/package.json b/package.json index 80000a4..052910c 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,6 @@ "esbuild": "^0.24.0", "fs-extra": "^11.2.0", "hookable": "^5.5.3", - "mime": "^4.0.4", "octokit": "^4.0.2", "std-env": "^3.8.0", "tiny-update-notifier": "^2.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 14cde88..1977729 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -44,9 +44,6 @@ importers: hookable: specifier: ^5.5.3 version: 5.5.3 - mime: - specifier: ^4.0.4 - version: 4.0.4 octokit: specifier: ^4.0.2 version: 4.0.2 @@ -2749,11 +2746,6 @@ packages: resolution: {integrity: sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==} engines: {node: '>=8.6'} - mime@4.0.4: - resolution: {integrity: sha512-v8yqInVjhXyqP6+Kw4fV3ZzeMRqEW6FotRsKXjRS5VMTNIuXsdRoAvklpoRgSqXm6o9VNH4/C0mgedko9DdLsQ==} - engines: {node: '>=16'} - hasBin: true - mimic-fn@4.0.0: resolution: {integrity: sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==} engines: {node: '>=12'} @@ -6553,8 +6545,6 @@ snapshots: braces: 3.0.3 picomatch: 2.3.1 - mime@4.0.4: {} - mimic-fn@4.0.0: {} min-indent@1.0.1: {} diff --git a/src/core/releaser/github.ts b/src/core/releaser/github.ts index c65c3a3..955932e 100644 --- a/src/core/releaser/github.ts +++ b/src/core/releaser/github.ts @@ -2,9 +2,9 @@ import type { Context } from "../../types/index.js"; import { readFile, stat } from "node:fs/promises"; import { basename, join } from "node:path"; import process from "node:process"; -import mime from "mime"; import { Octokit } from "octokit"; import { glob } from "tinyglobby"; +import { getMimeTypeByFileName } from "../../utils/mime.js"; import { ReleaseBase } from "./base.js"; export default class GitHub extends ReleaseBase { @@ -94,7 +94,7 @@ export default class GitHub extends ReleaseBase { release_id: releaseID, data: await readFile(asset) as unknown as string, headers: { - "content-type": mime.getType(asset) || "application/octet-stream", + "content-type": getMimeTypeByFileName(asset) || "application/octet-stream", "content-length": (await stat(asset)).size, }, name: basename(asset), diff --git a/src/utils/mime.ts b/src/utils/mime.ts new file mode 100644 index 0000000..396bb00 --- /dev/null +++ b/src/utils/mime.ts @@ -0,0 +1,17 @@ +import { extname } from "node:path"; + +const mimeTypes: { [key: string]: string[] } = { + "application/json": ["json"], + "application/x-xpinstall": ["xpi"], +}; + +export function getMimeTypeByFileName(filename: string) { + const ext = extname(filename); + + for (const type in mimeTypes) { + if (mimeTypes[type].includes(ext)) + return type; + } + + return undefined; +}