diff --git a/package.json b/package.json index 9ce418af..4c27d511 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "@types/jest": "^29.5.12", "@types/node": "^20.11.30", "@types/qrcode-terminal": "^0.12.2", - "@types/uuid": "^10.0.0", "@types/ws": "^8.5.10", "@typescript-eslint/eslint-plugin": "^7.4.0", "@typescript-eslint/parser": "^7.4.0", @@ -66,7 +65,6 @@ "log4js": "^6.9.1", "qrcode-terminal": "^0.12.0", "silk-wasm": "^3.6.1", - "uuid": "^10.0.0", "ws": "^8.16.0" } } diff --git a/src/common/utils/audio.ts b/src/common/utils/audio.ts index e9a33c91..2ac39700 100644 --- a/src/common/utils/audio.ts +++ b/src/common/utils/audio.ts @@ -3,7 +3,7 @@ import { encode, getDuration, getWavFileInfo, isWav, isSilk } from 'silk-wasm'; import fsPromise from 'fs/promises'; import { log, logError } from './log'; import path from 'node:path'; -import { v4 as uuidv4 } from 'uuid'; +import { randomUUID } from 'crypto'; import { spawn } from 'node:child_process'; import { getTempDir } from '@/common/utils/file'; @@ -64,7 +64,7 @@ export async function encodeSilk(filePath: string) { try { const file = await fsPromise.readFile(filePath); - const pttPath = path.join(TEMP_DIR, uuidv4()); + const pttPath = path.join(TEMP_DIR, randomUUID()); if (!isSilk(file)) { log(`语音文件${filePath}需要转换成silk`); const _isWav = isWav(file); diff --git a/src/common/utils/file.ts b/src/common/utils/file.ts index b84e6b50..aa847e07 100644 --- a/src/common/utils/file.ts +++ b/src/common/utils/file.ts @@ -5,7 +5,7 @@ import util from 'util'; import path from 'node:path'; import { log, logError } from './log'; import * as fileType from 'file-type'; -import { v4 as uuidv4 } from 'uuid'; +import { randomUUID } from 'crypto'; import { napCatCore } from '@/core'; export const getNapCatDir = () => { @@ -191,7 +191,7 @@ export async function uri2local(uri: string, fileName: string | null = null): Pr isLocal: false }; if (!fileName) { - fileName = uuidv4(); + fileName = randomUUID(); } let filePath = path.join(getTempDir(), fileName); let url = null; @@ -234,7 +234,7 @@ export async function uri2local(uri: string, fileName: string | null = null): Pr } fileName = fileName.replace(/[/\\:*?"<>|]/g, '_'); res.fileName = fileName; - filePath = path.join(getTempDir(), uuidv4() + fileName); + filePath = path.join(getTempDir(), randomUUID() + fileName); fs.writeFileSync(filePath, buffer); } catch (e: any) { res.errMsg = `${url}下载失败,` + e.toString(); diff --git a/src/common/utils/system.ts b/src/common/utils/system.ts index 1e75a95e..18b476c8 100644 --- a/src/common/utils/system.ts +++ b/src/common/utils/system.ts @@ -1,7 +1,7 @@ import os from 'node:os'; import path from 'node:path'; import { networkInterfaces } from 'os'; -import { v4 as uuidv4 } from 'uuid'; +import { randomUUID } from 'crypto'; // 缓解Win7设备兼容性问题 let osName: string; @@ -30,7 +30,7 @@ export async function getMachineId(): Promise { if (!machineId) { machineId = (async () => { const id = await getMacMachineId(); - return id || uuidv4(); // fallback, generate a UUID + return id || randomUUID(); // fallback, generate a UUID })(); } diff --git a/vite.config.ts b/vite.config.ts index 6d3ef9c8..ed071173 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -10,7 +10,7 @@ import fs from 'node:fs'; import babel from 'vite-plugin-babel'; import { version } from 'os'; // "@rollup/plugin-babel": "^6.0.4", -const external = ['silk-wasm', 'ws', 'express', 'uuid', 'fluent-ffmpeg', 'log4js', 'qrcode-terminal']; +const external = ['silk-wasm', 'ws', 'express', 'fluent-ffmpeg', 'log4js', 'qrcode-terminal']; const nodeModules = [...builtinModules, builtinModules.map(m => `node:${m}`)].flat(); // let nodeModules = ["fs", "path", "events", "buffer", "url", "crypto", "fs/promise", "fsPromise", "os", "http", "net"]