From a1298b1c9366124120a813cb54f161c87a1e743d Mon Sep 17 00:00:00 2001 From: idranme Date: Sun, 8 Sep 2024 21:09:03 +0800 Subject: [PATCH] optimize --- src/ntqqapi/entities.ts | 2 +- src/onebot11/action/go-cqhttp/UploadFile.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ntqqapi/entities.ts b/src/ntqqapi/entities.ts index 2dd2d2a..aec9761 100644 --- a/src/ntqqapi/entities.ts +++ b/src/ntqqapi/entities.ts @@ -99,7 +99,7 @@ export namespace SendElementEntities { } } - export async function file(ctx: Context, filePath: string, fileName = '', folderId = ''): Promise { + export async function file(ctx: Context, filePath: string, fileName: string, folderId = ''): Promise { const fileSize = (await stat(filePath)).size.toString() if (fileSize === '0') { ctx.logger.warn(`文件${fileName}异常,大小为 0`) diff --git a/src/onebot11/action/go-cqhttp/UploadFile.ts b/src/onebot11/action/go-cqhttp/UploadFile.ts index e10d598..e64c1ed 100644 --- a/src/onebot11/action/go-cqhttp/UploadFile.ts +++ b/src/onebot11/action/go-cqhttp/UploadFile.ts @@ -16,11 +16,11 @@ export class UploadGroupFile extends BaseAction { actionName = ActionName.GoCQHTTP_UploadGroupFile protected async _handle(payload: UploadGroupFilePayload): Promise { - const { success, errMsg, path } = await uri2local(payload.file) + const { success, errMsg, path, fileName } = await uri2local(payload.file) if (!success) { throw new Error(errMsg) } - const sendFileEle = await SendElementEntities.file(this.ctx, path, payload.name, payload.folder_id) + const sendFileEle = await SendElementEntities.file(this.ctx, path, payload.name || fileName, payload.folder_id) const peer = await createPeer(this.ctx, payload, CreatePeerMode.Group) await sendMsg(this.ctx, peer, [sendFileEle], []) return null @@ -37,11 +37,11 @@ export class UploadPrivateFile extends BaseAction { - const { success, errMsg, path } = await uri2local(payload.file) + const { success, errMsg, path, fileName } = await uri2local(payload.file) if (!success) { throw new Error(errMsg) } - const sendFileEle = await SendElementEntities.file(this.ctx, path, payload.name) + const sendFileEle = await SendElementEntities.file(this.ctx, path, payload.name || fileName) const peer = await createPeer(this.ctx, payload, CreatePeerMode.Private) await sendMsg(this.ctx, peer, [sendFileEle], []) return null