refactor(api): use shell provided mime

This commit is contained in:
Il Harper 2024-09-07 14:16:22 +08:00
parent a91e4bde19
commit f62febad1e
No known key found for this signature in database
GPG Key ID: 4B71FCA698E7E8EC
3 changed files with 3 additions and 5 deletions

View File

@ -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"

View File

@ -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,

View File

@ -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"