From d3e3527c2bba8f1bcfaa8442b02ddaa72f292603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=B6=E7=91=BE?= <74231782+sj817@users.noreply.github.com> Date: Tue, 21 Oct 2025 22:49:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20go-cqhttp=20=E4=B8=8A=E4=BC=A0=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=BF=94=E5=9B=9E=20file=5Fid=20(UploadGroupFile,=20U?= =?UTF-8?q?ploadPrivateFile)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/onebot/action/go-cqhttp/UploadGroupFile.ts | 18 +++++++++++++----- .../action/go-cqhttp/UploadPrivateFile.ts | 18 +++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/onebot/action/go-cqhttp/UploadGroupFile.ts b/src/onebot/action/go-cqhttp/UploadGroupFile.ts index 5c636e16..072251a7 100644 --- a/src/onebot/action/go-cqhttp/UploadGroupFile.ts +++ b/src/onebot/action/go-cqhttp/UploadGroupFile.ts @@ -1,6 +1,6 @@ import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; -import { ChatType, Peer } from '@/core/types'; +import { ChatType, Peer, ElementType } from '@/core/types'; import fs from 'fs'; import { uriToLocalFile } from '@/common/file'; import { SendMessageContext } from '@/onebot/api'; @@ -16,11 +16,15 @@ const SchemaData = Type.Object({ type Payload = Static; -export default class GoCQHTTPUploadGroupFile extends OneBotAction { +interface UploadGroupFileResponse { + file_id: string | null; +} + +export default class GoCQHTTPUploadGroupFile extends OneBotAction { override actionName = ActionName.GoCQHTTP_UploadGroupFile; override payloadSchema = SchemaData; - async _handle(payload: Payload): Promise { + async _handle(payload: Payload): Promise { let file = payload.file; if (fs.existsSync(file)) { file = `file://${file}`; @@ -39,7 +43,11 @@ export default class GoCQHTTPUploadGroupFile extends OneBotAction }; const sendFileEle = await this.core.apis.FileApi.createValidSendFileElement(msgContext, downloadResult.path, payload.name, payload.folder ?? payload.folder_id); msgContext.deleteAfterSentFiles.push(downloadResult.path); - await this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(peer, [sendFileEle], msgContext.deleteAfterSentFiles); - return null; + const returnMsg = await this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(peer, [sendFileEle], msgContext.deleteAfterSentFiles); + + const fileElement = returnMsg.elements.find(ele => ele.elementType === ElementType.FILE); + return { + file_id: fileElement?.fileElement?.fileUuid || null + }; } } diff --git a/src/onebot/action/go-cqhttp/UploadPrivateFile.ts b/src/onebot/action/go-cqhttp/UploadPrivateFile.ts index 1a37a21f..b88cab49 100644 --- a/src/onebot/action/go-cqhttp/UploadPrivateFile.ts +++ b/src/onebot/action/go-cqhttp/UploadPrivateFile.ts @@ -1,6 +1,6 @@ import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; -import { ChatType, Peer, SendFileElement } from '@/core/types'; +import { ChatType, Peer, SendFileElement, ElementType } from '@/core/types'; import fs from 'fs'; import { uriToLocalFile } from '@/common/file'; import { SendMessageContext } from '@/onebot/api'; @@ -15,7 +15,11 @@ const SchemaData = Type.Object({ type Payload = Static; -export default class GoCQHTTPUploadPrivateFile extends OneBotAction { +interface UploadPrivateFileResponse { + file_id: string | null; +} + +export default class GoCQHTTPUploadPrivateFile extends OneBotAction { override actionName = ActionName.GOCQHTTP_UploadPrivateFile; override payloadSchema = SchemaData; @@ -31,7 +35,7 @@ export default class GoCQHTTPUploadPrivateFile extends OneBotAction { + async _handle(payload: Payload): Promise { let file = payload.file; if (fs.existsSync(file)) { file = `file://${file}`; @@ -49,7 +53,11 @@ export default class GoCQHTTPUploadPrivateFile extends OneBotAction ele.elementType === ElementType.FILE); + return { + file_id: fileElement?.fileElement?.fileUuid || null + }; } }