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;