refa: deps

This commit is contained in:
idranme 2024-08-02 12:00:13 +00:00
parent d0967785de
commit f3af0d18bc
8 changed files with 30 additions and 35 deletions

View File

@ -16,24 +16,21 @@
"author": "", "author": "",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"compressing": "^1.10.0", "compressing": "^1.10.1",
"cors": "^2.8.5", "cors": "^2.8.5",
"express": "^4.18.2", "express": "^4.19.2",
"fast-xml-parser": "^4.3.6", "fast-xml-parser": "^4.4.1",
"file-type": "^19.0.0", "file-type": "^19.3.0",
"fluent-ffmpeg": "^2.1.2", "fluent-ffmpeg": "^2.1.3",
"level": "^8.0.1", "level": "^8.0.1",
"silk-wasm": "^3.6.0", "silk-wasm": "^3.6.1",
"utf-8-validate": "^6.0.3", "ws": "^8.18.0"
"uuid": "^9.0.1",
"ws": "^8.16.0"
}, },
"devDependencies": { "devDependencies": {
"@types/express": "^4.17.20", "@types/express": "^4.17.21",
"@types/fluent-ffmpeg": "^2.1.24", "@types/fluent-ffmpeg": "^2.1.25",
"@types/node": "^20.11.24", "@types/node": "^20.11.24",
"@types/uuid": "^9.0.8", "@types/ws": "^8.5.12",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "^6.4.0", "@typescript-eslint/eslint-plugin": "^6.4.0",
"electron": "^29.0.1", "electron": "^29.0.1",
"electron-vite": "^2.0.0", "electron-vite": "^2.0.0",

View File

@ -1,10 +1,10 @@
import { Level } from 'level' 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() { async function getGroupNotify() {
let keys = await db.keys().all() let keys = await db.keys().all()
let result = [] let result: string[] = []
for (const key of keys) { for (const key of keys) {
// console.log(key) // console.log(key)
if (key.startsWith('group_notify_')) { if (key.startsWith('group_notify_')) {

View File

@ -4,9 +4,9 @@ import { decode, encode, getDuration, getWavFileInfo, isWav, isSilk } from 'silk
import { log } from './log' import { log } from './log'
import path from 'node:path' import path from 'node:path'
import { TEMP_DIR } from './index' import { TEMP_DIR } from './index'
import { v4 as uuidv4 } from 'uuid'
import { getConfigUtil } from '../config' import { getConfigUtil } from '../config'
import { spawn } from 'node:child_process' import { spawn } from 'node:child_process'
import { randomUUID } from 'node:crypto'
export async function encodeSilk(filePath: string) { export async function encodeSilk(filePath: string) {
function getFileHeader(filePath: string) { function getFileHeader(filePath: string) {
@ -61,7 +61,7 @@ export async function encodeSilk(filePath: string) {
try { try {
const file = await fsPromise.readFile(filePath) const file = await fsPromise.readFile(filePath)
const pttPath = path.join(TEMP_DIR, uuidv4()) const pttPath = path.join(TEMP_DIR, randomUUID())
if (!isSilk(file)) { if (!isSilk(file)) {
log(`语音文件${filePath}需要转换成silk`) log(`语音文件${filePath}需要转换成silk`)
const _isWav = isWav(file) const _isWav = isWav(file)

View File

@ -1,13 +1,12 @@
import fs from 'fs' import fs from 'fs'
import fsPromise from 'fs/promises' import fsPromise from 'fs/promises'
import crypto from 'crypto'
import util from 'util' import util from 'util'
import path from 'node:path' import path from 'node:path'
import { v4 as uuidv4 } from 'uuid'
import { log, TEMP_DIR } from './index' import { log, TEMP_DIR } from './index'
import { dbUtil } from '../db' import { dbUtil } from '../db'
import * as fileType from 'file-type' import * as fileType from 'file-type'
import { net } from 'electron' import { net } from 'electron'
import { randomUUID, createHash } from 'node:crypto'
export function isGIF(path: string) { export function isGIF(path: string) {
const buffer = Buffer.alloc(4) const buffer = Buffer.alloc(4)
@ -66,7 +65,7 @@ export function calculateFileMD5(filePath: string): Promise<string> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// 创建一个流式读取器 // 创建一个流式读取器
const stream = fs.createReadStream(filePath) const stream = fs.createReadStream(filePath)
const hash = crypto.createHash('md5') const hash = createHash('md5')
stream.on('data', (data: Buffer) => { stream.on('data', (data: Buffer) => {
// 当读取到数据时,更新哈希对象的状态 // 当读取到数据时,更新哈希对象的状态
@ -136,7 +135,7 @@ export async function uri2local(uri: string, fileName: string = null): Promise<U
isLocal: false, isLocal: false,
} }
if (!fileName) { if (!fileName) {
fileName = uuidv4() fileName = randomUUID()
} }
let filePath = path.join(TEMP_DIR, fileName) let filePath = path.join(TEMP_DIR, fileName)
let url = null let url = null
@ -178,7 +177,7 @@ export async function uri2local(uri: string, fileName: string = null): Promise<U
} }
fileName = fileName.replace(/[/\\:*?"<>|]/g, '_') fileName = fileName.replace(/[/\\:*?"<>|]/g, '_')
res.fileName = fileName res.fileName = fileName
filePath = path.join(TEMP_DIR, uuidv4() + fileName) filePath = path.join(TEMP_DIR, randomUUID() + fileName)
fs.writeFileSync(filePath, buffer) fs.writeFileSync(filePath, buffer)
} catch (e: any) { } catch (e: any) {
res.errMsg = `${url}下载失败,` + e.toString() res.errMsg = `${url}下载失败,` + e.toString()

View File

@ -216,7 +216,7 @@ function onLoad() {
pokeEvent = new OB11GroupPokeEvent(parseInt(id)) pokeEvent = new OB11GroupPokeEvent(parseInt(id))
} }
else { else {
pokeEvent = new OB11FriendPokeEvent(parseInt(id)) pokeEvent = new OB11FriendPokeEvent(parseInt(id), 0)
} }
postOb11Event(pokeEvent) postOb11Event(pokeEvent)
}) })

View File

@ -13,7 +13,6 @@ import {
uidMaps, uidMaps,
} from '@/common/data' } from '@/common/data'
import { OB11GroupDecreaseEvent } from '../onebot11/event/notice/OB11GroupDecreaseEvent' import { OB11GroupDecreaseEvent } from '../onebot11/event/notice/OB11GroupDecreaseEvent'
import { v4 as uuidv4 } from 'uuid'
import { postOb11Event } from '../onebot11/server/post-ob11-event' import { postOb11Event } from '../onebot11/server/post-ob11-event'
import { getConfigUtil, HOOK_LOG } from '@/common/config' import { getConfigUtil, HOOK_LOG } from '@/common/config'
import fs from 'fs' import fs from 'fs'
@ -23,6 +22,7 @@ import { log } from '@/common/utils'
import { isNumeric, sleep } from '@/common/utils' import { isNumeric, sleep } from '@/common/utils'
import { OB11Constructor } from '../onebot11/constructor' import { OB11Constructor } from '../onebot11/constructor'
import { OB11GroupCardEvent } from '../onebot11/event/notice/OB11GroupCardEvent' import { OB11GroupCardEvent } from '../onebot11/event/notice/OB11GroupCardEvent'
import { randomUUID } from 'node:crypto'
export let hookApiCallbacks: Record<string, (apiReturn: any) => void> = {} export let hookApiCallbacks: Record<string, (apiReturn: any) => void> = {}
@ -203,7 +203,7 @@ export function registerReceiveHook<PayloadType>(
method: ReceiveCmd | ReceiveCmd[], method: ReceiveCmd | ReceiveCmd[],
hookFunc: (payload: PayloadType) => void, hookFunc: (payload: PayloadType) => void,
): string { ): string {
const id = uuidv4() const id = randomUUID()
if (!Array.isArray(method)) { if (!Array.isArray(method)) {
method = [method] method = [method]
} }

View File

@ -1,10 +1,9 @@
import { ipcMain } from 'electron' import { ipcMain } from 'electron'
import { hookApiCallbacks, ReceiveCmd, ReceiveCmdS, registerReceiveHook, removeReceiveHook } from './hook' import { hookApiCallbacks, ReceiveCmd, ReceiveCmdS, registerReceiveHook, removeReceiveHook } from './hook'
import { v4 as uuidv4 } from 'uuid'
import { log } from '../common/utils/log' import { log } from '../common/utils/log'
import { NTQQWindow, NTQQWindowApi, NTQQWindows } from './api/window' import { NTQQWindow, NTQQWindowApi, NTQQWindows } from './api/window'
import { HOOK_LOG } from '../common/config' import { HOOK_LOG } from '../common/config'
import { randomUUID } from 'node:crypto'
export enum NTQQApiClass { export enum NTQQApiClass {
NT_API = 'ns-ntApi', NT_API = 'ns-ntApi',
@ -130,7 +129,7 @@ export function callNTQQApi<ReturnType>(params: NTQQApiParams) {
args = args ?? [] args = args ?? []
timeout = timeout ?? 5 timeout = timeout ?? 5
afterFirstCmd = afterFirstCmd ?? true afterFirstCmd = afterFirstCmd ?? true
const uuid = uuidv4() const uuid = randomUUID()
HOOK_LOG && log('callNTQQApi', channel, className, methodName, args, uuid) HOOK_LOG && log('callNTQQApi', channel, className, methodName, args, uuid)
return new Promise((resolve: (data: ReturnType) => void, reject) => { return new Promise((resolve: (data: ReturnType) => void, reject) => {
// log("callNTQQApiPromise", channel, className, methodName, args, uuid) // log("callNTQQApiPromise", channel, className, methodName, args, uuid)

View File

@ -3,7 +3,7 @@ import { ActionName } from '../types'
import fs from 'fs' import fs from 'fs'
import { join as joinPath } from 'node:path' import { join as joinPath } from 'node:path'
import { calculateFileMD5, httpDownload, TEMP_DIR } from '../../../common/utils' import { calculateFileMD5, httpDownload, TEMP_DIR } from '../../../common/utils'
import { v4 as uuid4 } from 'uuid' import { randomUUID } from 'node:crypto'
interface Payload { interface Payload {
thread_count?: number thread_count?: number
@ -22,7 +22,7 @@ export default class GoCQHTTPDownloadFile extends BaseAction<Payload, FileRespon
protected async _handle(payload: Payload): Promise<FileResponse> { protected async _handle(payload: Payload): Promise<FileResponse> {
const isRandomName = !payload.name const isRandomName = !payload.name
let name = payload.name || uuid4() let name = payload.name || randomUUID()
const filePath = joinPath(TEMP_DIR, name) const filePath = joinPath(TEMP_DIR, name)
if (payload.base64) { if (payload.base64) {