From f3af0d18bcfe11ce89918fadd5fa1d3167199206 Mon Sep 17 00:00:00 2001 From: idranme <96647698+idranme@users.noreply.github.com> Date: Fri, 2 Aug 2024 12:00:13 +0000 Subject: [PATCH] refa: deps --- package.json | 23 ++++++++----------- scripts/test/test_db.ts | 4 ++-- src/common/utils/audio.ts | 4 ++-- src/common/utils/file.ts | 11 ++++----- src/main/main.ts | 10 ++++---- src/ntqqapi/hook.ts | 4 ++-- src/ntqqapi/ntcall.ts | 5 ++-- src/onebot11/action/go-cqhttp/DownloadFile.ts | 4 ++-- 8 files changed, 30 insertions(+), 35 deletions(-) diff --git a/package.json b/package.json index e25533a..7816c07 100644 --- a/package.json +++ b/package.json @@ -16,24 +16,21 @@ "author": "", "license": "MIT", "dependencies": { - "compressing": "^1.10.0", + "compressing": "^1.10.1", "cors": "^2.8.5", - "express": "^4.18.2", - "fast-xml-parser": "^4.3.6", - "file-type": "^19.0.0", - "fluent-ffmpeg": "^2.1.2", + "express": "^4.19.2", + "fast-xml-parser": "^4.4.1", + "file-type": "^19.3.0", + "fluent-ffmpeg": "^2.1.3", "level": "^8.0.1", - "silk-wasm": "^3.6.0", - "utf-8-validate": "^6.0.3", - "uuid": "^9.0.1", - "ws": "^8.16.0" + "silk-wasm": "^3.6.1", + "ws": "^8.18.0" }, "devDependencies": { - "@types/express": "^4.17.20", - "@types/fluent-ffmpeg": "^2.1.24", + "@types/express": "^4.17.21", + "@types/fluent-ffmpeg": "^2.1.25", "@types/node": "^20.11.24", - "@types/uuid": "^9.0.8", - "@types/ws": "^8.5.10", + "@types/ws": "^8.5.12", "@typescript-eslint/eslint-plugin": "^6.4.0", "electron": "^29.0.1", "electron-vite": "^2.0.0", diff --git a/scripts/test/test_db.ts b/scripts/test/test_db.ts index 66681fd..5b7444c 100644 --- a/scripts/test/test_db.ts +++ b/scripts/test/test_db.ts @@ -1,10 +1,10 @@ import { Level } from 'level' -const db = new Level(process.env['level_db_path'], { valueEncoding: 'json' }) +const db = new Level(process.env['level_db_path'] as string, { valueEncoding: 'json' }) async function getGroupNotify() { let keys = await db.keys().all() - let result = [] + let result: string[] = [] for (const key of keys) { // console.log(key) if (key.startsWith('group_notify_')) { diff --git a/src/common/utils/audio.ts b/src/common/utils/audio.ts index 78a7840..f5ca32e 100644 --- a/src/common/utils/audio.ts +++ b/src/common/utils/audio.ts @@ -4,9 +4,9 @@ import { decode, encode, getDuration, getWavFileInfo, isWav, isSilk } from 'silk import { log } from './log' import path from 'node:path' import { TEMP_DIR } from './index' -import { v4 as uuidv4 } from 'uuid' import { getConfigUtil } from '../config' import { spawn } from 'node:child_process' +import { randomUUID } from 'node:crypto' export async function encodeSilk(filePath: string) { function getFileHeader(filePath: string) { @@ -61,7 +61,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 2df5ec7..c400e80 100644 --- a/src/common/utils/file.ts +++ b/src/common/utils/file.ts @@ -1,13 +1,12 @@ import fs from 'fs' import fsPromise from 'fs/promises' -import crypto from 'crypto' import util from 'util' import path from 'node:path' -import { v4 as uuidv4 } from 'uuid' import { log, TEMP_DIR } from './index' import { dbUtil } from '../db' import * as fileType from 'file-type' import { net } from 'electron' +import { randomUUID, createHash } from 'node:crypto' export function isGIF(path: string) { const buffer = Buffer.alloc(4) @@ -66,7 +65,7 @@ export function calculateFileMD5(filePath: string): Promise { return new Promise((resolve, reject) => { // 创建一个流式读取器 const stream = fs.createReadStream(filePath) - const hash = crypto.createHash('md5') + const hash = createHash('md5') stream.on('data', (data: Buffer) => { // 当读取到数据时,更新哈希对象的状态 @@ -109,7 +108,7 @@ export async function httpDownload(options: string | HttpDownloadOptions): Promi } } } - const fetchRes = await net.fetch(url, {headers}) + const fetchRes = await net.fetch(url, { headers }) if (!fetchRes.ok) throw new Error(`下载文件失败: ${fetchRes.statusText}`) const blob = await fetchRes.blob() @@ -136,7 +135,7 @@ export async function uri2local(uri: string, fileName: string = null): Promise|]/g, '_') res.fileName = fileName - filePath = path.join(TEMP_DIR, uuidv4() + fileName) + filePath = path.join(TEMP_DIR, randomUUID() + fileName) fs.writeFileSync(filePath, buffer) } catch (e: any) { res.errMsg = `${url}下载失败,` + e.toString() diff --git a/src/main/main.ts b/src/main/main.ts index a1b1032..efcd61d 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -204,7 +204,7 @@ function onLoad() { async function startReceiveHook() { startHook().then() if (getConfigUtil().getConfig().enablePoke) { - if ( qqPkgInfo.buildVersion > '23873'){ + if (qqPkgInfo.buildVersion > '23873') { log(`当前版本${qqPkgInfo.buildVersion}不支持发送戳一戳模块`) } else { @@ -216,7 +216,7 @@ function onLoad() { pokeEvent = new OB11GroupPokeEvent(parseInt(id)) } else { - pokeEvent = new OB11FriendPokeEvent(parseInt(id)) + pokeEvent = new OB11FriendPokeEvent(parseInt(id), 0) } postOb11Event(pokeEvent) }) @@ -235,7 +235,7 @@ function onLoad() { registerReceiveHook<{ msgList: Array }>([ReceiveCmdS.UPDATE_MSG], async (payload) => { for (const message of payload.msgList) { const sentMessage = sentMessages[message.msgId] - if (sentMessage){ + if (sentMessage) { Object.assign(sentMessage, message) } log('message update', message.msgId, message) @@ -442,7 +442,7 @@ function onLoad() { async function start() { log('llonebot pid', process.pid) const config = getConfigUtil().getConfig() - if (!config.enableLLOB){ + if (!config.enableLLOB) { log('LLOneBot 开关设置为关闭,不启动LLOneBot') return } @@ -453,7 +453,7 @@ function onLoad() { uidMaps[value] = key } }) - try{ + try { log('start get groups') const _groups = await NTQQGroupApi.getGroups() log('_groups', _groups) diff --git a/src/ntqqapi/hook.ts b/src/ntqqapi/hook.ts index ca2708d..59f7ff0 100644 --- a/src/ntqqapi/hook.ts +++ b/src/ntqqapi/hook.ts @@ -13,7 +13,6 @@ import { uidMaps, } from '@/common/data' import { OB11GroupDecreaseEvent } from '../onebot11/event/notice/OB11GroupDecreaseEvent' -import { v4 as uuidv4 } from 'uuid' import { postOb11Event } from '../onebot11/server/post-ob11-event' import { getConfigUtil, HOOK_LOG } from '@/common/config' import fs from 'fs' @@ -23,6 +22,7 @@ import { log } from '@/common/utils' import { isNumeric, sleep } from '@/common/utils' import { OB11Constructor } from '../onebot11/constructor' import { OB11GroupCardEvent } from '../onebot11/event/notice/OB11GroupCardEvent' +import { randomUUID } from 'node:crypto' export let hookApiCallbacks: Record void> = {} @@ -203,7 +203,7 @@ export function registerReceiveHook( method: ReceiveCmd | ReceiveCmd[], hookFunc: (payload: PayloadType) => void, ): string { - const id = uuidv4() + const id = randomUUID() if (!Array.isArray(method)) { method = [method] } diff --git a/src/ntqqapi/ntcall.ts b/src/ntqqapi/ntcall.ts index c9370e4..12b8441 100644 --- a/src/ntqqapi/ntcall.ts +++ b/src/ntqqapi/ntcall.ts @@ -1,10 +1,9 @@ import { ipcMain } from 'electron' import { hookApiCallbacks, ReceiveCmd, ReceiveCmdS, registerReceiveHook, removeReceiveHook } from './hook' - -import { v4 as uuidv4 } from 'uuid' import { log } from '../common/utils/log' import { NTQQWindow, NTQQWindowApi, NTQQWindows } from './api/window' import { HOOK_LOG } from '../common/config' +import { randomUUID } from 'node:crypto' export enum NTQQApiClass { NT_API = 'ns-ntApi', @@ -130,7 +129,7 @@ export function callNTQQApi(params: NTQQApiParams) { args = args ?? [] timeout = timeout ?? 5 afterFirstCmd = afterFirstCmd ?? true - const uuid = uuidv4() + const uuid = randomUUID() HOOK_LOG && log('callNTQQApi', channel, className, methodName, args, uuid) return new Promise((resolve: (data: ReturnType) => void, reject) => { // log("callNTQQApiPromise", channel, className, methodName, args, uuid) diff --git a/src/onebot11/action/go-cqhttp/DownloadFile.ts b/src/onebot11/action/go-cqhttp/DownloadFile.ts index 5f7f758..fd43ef8 100644 --- a/src/onebot11/action/go-cqhttp/DownloadFile.ts +++ b/src/onebot11/action/go-cqhttp/DownloadFile.ts @@ -3,7 +3,7 @@ import { ActionName } from '../types' import fs from 'fs' import { join as joinPath } from 'node:path' import { calculateFileMD5, httpDownload, TEMP_DIR } from '../../../common/utils' -import { v4 as uuid4 } from 'uuid' +import { randomUUID } from 'node:crypto' interface Payload { thread_count?: number @@ -22,7 +22,7 @@ export default class GoCQHTTPDownloadFile extends BaseAction { const isRandomName = !payload.name - let name = payload.name || uuid4() + let name = payload.name || randomUUID() const filePath = joinPath(TEMP_DIR, name) if (payload.base64) {