diff --git a/packages/napcat-core/apis/file.ts b/packages/napcat-core/apis/file.ts index e45ebf70..a7acd3bc 100644 --- a/packages/napcat-core/apis/file.ts +++ b/packages/napcat-core/apis/file.ts @@ -33,7 +33,7 @@ export class NTQQFileApi { 'http://ss.xingzhige.com/music_card/rkey', 'https://secret-service.bietiaop.com/rkeys', ], - this.context.logger + this.context.logger ); } @@ -138,7 +138,7 @@ export class NTQQFileApi { })).urlResult.domainUrl; } - async uploadFile (filePath: string, elementType: ElementType = ElementType.PIC, elementSubType: number = 0) { + async uploadFile (filePath: string, elementType: ElementType = ElementType.PIC, elementSubType: number = 0, uploadGroupFile = true) { const fileMd5 = await calculateFileMD5(filePath); const extOrEmpty = await fileTypeFromFile(filePath).then(e => e?.ext ?? '').catch(() => ''); const ext = extOrEmpty ? `.${extOrEmpty}` : ''; @@ -146,24 +146,33 @@ export class NTQQFileApi { if (fileName.indexOf('.') === -1) { fileName += ext; } - - const mediaPath = this.context.session.getMsgService().getRichMediaFilePathForGuild({ - md5HexStr: fileMd5, - fileName, - elementType, - elementSubType, - thumbSize: 0, - needCreate: true, - downloadType: 1, - file_uuid: '', - }); - - await this.copyFile(filePath, mediaPath); const fileSize = await this.getFileSize(filePath); + if (uploadGroupFile) { + const mediaPath = this.context.session.getMsgService().getRichMediaFilePathForGuild({ + md5HexStr: fileMd5, + fileName, + elementType, + elementSubType, + thumbSize: 0, + needCreate: true, + downloadType: 1, + file_uuid: '', + }); + + await this.copyFile(filePath, mediaPath); + + return { + md5: fileMd5, + fileName, + path: mediaPath, + fileSize, + ext, + }; + } return { md5: fileMd5, fileName, - path: mediaPath, + path: filePath, fileSize, ext, }; diff --git a/packages/napcat-onebot/action/go-cqhttp/UploadGroupFile.ts b/packages/napcat-onebot/action/go-cqhttp/UploadGroupFile.ts index d9d09d5c..11bfe4b9 100644 --- a/packages/napcat-onebot/action/go-cqhttp/UploadGroupFile.ts +++ b/packages/napcat-onebot/action/go-cqhttp/UploadGroupFile.ts @@ -12,6 +12,7 @@ const SchemaData = Type.Object({ name: Type.String(), folder: Type.Optional(Type.String()), folder_id: Type.Optional(Type.String()), // 临时扩展 + upload_file: Type.Boolean({ default: true }), }); type Payload = Static; @@ -41,7 +42,7 @@ export default class GoCQHTTPUploadGroupFile extends OneBotAction; @@ -51,7 +52,7 @@ export default class GoCQHTTPUploadPrivateFile extends OneBotAction { + async createValidSendFileElement (context: SendMessageContext, filePath: string, fileName: string = '', folderId: string = '', uploadGroupFile: boolean = false): Promise { const { fileName: _fileName, path, fileSize, - } = await this.core.apis.FileApi.uploadFile(filePath, ElementType.FILE); + } = await this.core.apis.FileApi.uploadFile(filePath, ElementType.FILE, 0, uploadGroupFile); if (fileSize === 0) { throw new Error('文件异常,大小为0'); } - context.deleteAfterSentFiles.push(path); + if (uploadGroupFile) { + context.deleteAfterSentFiles.push(path); + } return { elementType: ElementType.FILE, elementId: '',