From cfae4f5acd8d277c7f9ae4fd4b9ea87b3cbace79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Wed, 7 May 2025 22:26:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=BC=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/apis/file.ts | 16 ++++++++++------ src/core/packet/transformer/proto/misc/fileid.ts | 6 ++++++ src/onebot/api/msg.ts | 4 ++-- 3 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 src/core/packet/transformer/proto/misc/fileid.ts diff --git a/src/core/apis/file.ts b/src/core/apis/file.ts index 026fe88d..800858fc 100644 --- a/src/core/apis/file.ts +++ b/src/core/apis/file.ts @@ -28,6 +28,8 @@ import { SendMessageContext } from '@/onebot/api'; import { getFileTypeForSendType } from '../helper/msg'; import { FFmpegService } from '@/common/ffmpeg'; import { rkeyDataType } from '../types/file'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { FileId } from '../packet/transformer/proto/misc/fileid'; export class NTQQFileApi { context: InstanceContext; @@ -78,10 +80,11 @@ export class NTQQFileApi { throw new Error('fileUUID or file10MMd5 is undefined'); } - async getPttUrl(chatType: ChatType, peer: string, fileUUID?: string) { - if (this.core.apis.PacketApi.available) { + async getPttUrl(peer: string, fileUUID?: string) { + if (this.core.apis.PacketApi.available && fileUUID) { + let appid = new NapProtoMsg(FileId).decode(Buffer.from(fileUUID.replaceAll('-', '+').replaceAll('_', '/'), 'base64')).appid; try { - if (chatType === ChatType.KCHATTYPEGROUP && fileUUID) { + if (appid && appid === 1403) { return this.core.apis.PacketApi.pkt.operation.GetGroupPttUrl(+peer, { fileUuid: fileUUID, storeId: 1, @@ -105,10 +108,11 @@ export class NTQQFileApi { throw new Error('packet cant get ptt url'); } - async getVideoUrlPacket(chatType: ChatType, peer: string, fileUUID?: string) { - if (this.core.apis.PacketApi.available) { + async getVideoUrlPacket(peer: string, fileUUID?: string) { + if (this.core.apis.PacketApi.available && fileUUID) { + let appid = new NapProtoMsg(FileId).decode(Buffer.from(fileUUID.replaceAll('-', '+').replaceAll('_', '/'), 'base64')).appid; try { - if (chatType === ChatType.KCHATTYPEGROUP && fileUUID) { + if (appid && appid === 1415) { return this.core.apis.PacketApi.pkt.operation.GetGroupVideoUrl(+peer, { fileUuid: fileUUID, storeId: 1, diff --git a/src/core/packet/transformer/proto/misc/fileid.ts b/src/core/packet/transformer/proto/misc/fileid.ts new file mode 100644 index 00000000..71426f3f --- /dev/null +++ b/src/core/packet/transformer/proto/misc/fileid.ts @@ -0,0 +1,6 @@ +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; + +export const FileId = { + appid: ProtoField(4, ScalarType.UINT32, true), + ttl: ProtoField(10, ScalarType.UINT32, true), +}; diff --git a/src/onebot/api/msg.ts b/src/onebot/api/msg.ts index 6191c57d..ffe55ceb 100644 --- a/src/onebot/api/msg.ts +++ b/src/onebot/api/msg.ts @@ -396,7 +396,7 @@ export class OneBotMsgApi { if (!videoDownUrl) { if (this.core.apis.PacketApi.available) { try { - videoDownUrl = await this.core.apis.FileApi.getVideoUrlPacket(msg.chatType, msg.peerUid, element.fileUuid); + videoDownUrl = await this.core.apis.FileApi.getVideoUrlPacket(msg.peerUid, element.fileUuid); } catch (e) { this.core.context.logger.logError('获取视频url失败', (e as Error).stack); videoDownUrl = element.filePath; @@ -427,7 +427,7 @@ export class OneBotMsgApi { let pttUrl = ''; if (this.core.apis.PacketApi.available) { try { - pttUrl = await this.core.apis.FileApi.getPttUrl(msg.chatType, msg.peerUid, element.fileUuid); + pttUrl = await this.core.apis.FileApi.getPttUrl(msg.peerUid, element.fileUuid); } catch (e) { this.core.context.logger.logError('获取语音url失败', (e as Error).stack); pttUrl = element.filePath;