From f62febad1ec34718134fe686017a4d6f18b97d36 Mon Sep 17 00:00:00 2001 From: Il Harper Date: Sat, 7 Sep 2024 14:16:22 +0800 Subject: [PATCH] refactor(api): use shell provided mime --- packages/engine-chronocat-api/package.json | 1 - packages/engine-chronocat-api/src/common/file.ts | 5 ++--- yarn.lock | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/engine-chronocat-api/package.json b/packages/engine-chronocat-api/package.json index 226fc29..a3b3b6c 100644 --- a/packages/engine-chronocat-api/package.json +++ b/packages/engine-chronocat-api/package.json @@ -25,7 +25,6 @@ "concurrently": "^8.2.1", "esbuild-register": "^3.5.0", "ipcman": "^0.1.3", - "mime": "^4.0.4", "node-fetch": "^3.3.2", "ts-toolbelt": "^9.6.0", "typescript": "~5.1.0" diff --git a/packages/engine-chronocat-api/src/common/file.ts b/packages/engine-chronocat-api/src/common/file.ts index 073abca..78bb3ce 100644 --- a/packages/engine-chronocat-api/src/common/file.ts +++ b/packages/engine-chronocat-api/src/common/file.ts @@ -1,5 +1,4 @@ import type { ChronocatContext } from '@chronocat/shell' -import mime from 'mime/lite' import fetch from 'node-fetch' import { createReadStream, createWriteStream } from 'node:fs' import { copyFile, mkdir, unlink, writeFile } from 'node:fs/promises' @@ -66,7 +65,7 @@ export const commonFile = async ( // 从 Content-Type 获得 MIME fileMime ||= response.headers.get('Content-Type') || undefined if (fileMime && !fileName.includes('.')) { - const ext = mime.getExtension(fileMime) + const ext = ctx.chronocat.mime.getExtension(fileMime) fileName += ext ? '.' + ext : '' } @@ -85,7 +84,7 @@ export const commonFile = async ( if (capture) { fileMime ||= capture[1]! const base64 = capture[2]! - const ext = mime.getExtension(fileMime) + const ext = ctx.chronocat.mime.getExtension(fileMime) fileName ||= generateToken16() + (ext ? '.' + ext : '') filePath = await saveBuffer( ctx, diff --git a/yarn.lock b/yarn.lock index c1132ee..cc8320e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1783,7 +1783,6 @@ __metadata: concurrently: "npm:^8.2.1" esbuild-register: "npm:^3.5.0" ipcman: "npm:^0.1.3" - mime: "npm:^4.0.4" node-fetch: "npm:^3.3.2" ts-toolbelt: "npm:^9.6.0" typescript: "npm:~5.1.0" @@ -1868,6 +1867,7 @@ __metadata: esbuild-register: "npm:^3.5.0" js-yaml: "npm:^4.1.0" logiri: "npm:^0.1.2" + mime: "npm:^4.0.4" node-fetch: "npm:^3.3.2" protobufjs: "npm:^7.2.5" ts-toolbelt: "npm:^9.6.0"