fix: #2100
This commit is contained in:
1 parent
450fb0429a
commit
89e8efc57e
7 files changed
+100
-10
No files matched your search
@@ -74,6 +74,7 @@ interface FileUUIDData {
|
|||||||
msgId?: string;
|
msgId?: string;
|
||||||
elementId?: string;
|
elementId?: string;
|
||||||
fileUUID?: string;
|
fileUUID?: string;
|
||||||
|
busId?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
class FileUUIDManager {
|
class FileUUIDManager {
|
||||||
@@ -105,6 +106,10 @@ export class FileNapCatOneBotUUIDWrap {
|
|||||||
return this.manager.encode({ peer, modelId, fileId, fileUUID }, endString, customUUID);
|
return this.manager.encode({ peer, modelId, fileId, fileUUID }, endString, customUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public encodeGroupFile (peer: Peer, file: { fileModelId: string; fileId: string; busId: number; }): string {
|
||||||
|
return this.manager.encode({ peer, modelId: file.fileModelId, fileId: file.fileId, fileUUID: file.fileId, busId: file.busId });
|
||||||
|
}
|
||||||
|
|
||||||
public decodeModelId (uuid: string): FileUUIDData | undefined {
|
public decodeModelId (uuid: string): FileUUIDData | undefined {
|
||||||
return this.manager.decode(uuid);
|
return this.manager.decode(uuid);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import {
|
|||||||
createGroupManagementRequests,
|
createGroupManagementRequests,
|
||||||
} from '../data';
|
} from '../data';
|
||||||
import { NTEventWrapper } from '../helper/event';
|
import { NTEventWrapper } from '../helper/event';
|
||||||
|
import { deleteGroupFiles } from '../helper/group-file';
|
||||||
|
|
||||||
export class NTQQGroupApi {
|
export class NTQQGroupApi {
|
||||||
context: InstanceContext;
|
context: InstanceContext;
|
||||||
@@ -384,8 +385,8 @@ export class NTQQGroupApi {
|
|||||||
return this.context.session.getRichMediaService().createGroupFolder(groupCode, folderName);
|
return this.context.session.getRichMediaService().createGroupFolder(groupCode, folderName);
|
||||||
}
|
}
|
||||||
|
|
||||||
async delGroupFile (groupCode: string, files: Array<string>) {
|
async delGroupFile (groupCode: string, files: Array<string>, busIds?: Array<number>) {
|
||||||
return this.context.session.getRichMediaService().deleteGroupFile(groupCode, [102], files);
|
return deleteGroupFiles(this.context.session.getRichMediaService(), groupCode, files, busIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
async delGroupFileFolder (groupCode: string, folderId: string) {
|
async delGroupFileFolder (groupCode: string, folderId: string) {
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import type { NodeIKernelRichMediaService } from '../services/NodeIKernelRichMediaService';
|
||||||
|
|
||||||
|
type GroupFileService = Pick<NodeIKernelRichMediaService, 'getGroupFileInfo' | 'deleteGroupFile'>;
|
||||||
|
|
||||||
|
function withTimeout<T> (promise: Promise<T>, operation: string): Promise<T> {
|
||||||
|
return new Promise<T>((resolve, reject) => {
|
||||||
|
const timer = setTimeout(() => reject(new Error(`${operation}超时,请重新查询群文件列表确认文件状态`)), 15000);
|
||||||
|
promise.then(resolve, reject).finally(() => clearTimeout(timer));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertBusId (busId: number): void {
|
||||||
|
if (!Number.isInteger(busId) || busId <= 0 || busId > 0xFFFFFFFF) {
|
||||||
|
throw new Error('Invalid bus_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteGroupFiles (service: GroupFileService, groupCode: string, files: string[], busIds?: number[]) {
|
||||||
|
if (!files.length || files.some(fileId => !fileId)) {
|
||||||
|
throw new Error('Invalid file_id');
|
||||||
|
}
|
||||||
|
if (busIds && busIds.length !== files.length) {
|
||||||
|
throw new Error('bus_id 数量必须与文件数量一致');
|
||||||
|
}
|
||||||
|
|
||||||
|
const resolvedBusIds: number[] = [];
|
||||||
|
for (const [index, fileId] of files.entries()) {
|
||||||
|
let busId = busIds?.[index];
|
||||||
|
if (busId === undefined) {
|
||||||
|
const info = await withTimeout(service.getGroupFileInfo(groupCode, fileId), '查询群文件信息');
|
||||||
|
if (info?.result !== 0) {
|
||||||
|
throw new Error(`查询群文件信息失败: ${info?.errMsg || info?.result}`);
|
||||||
|
}
|
||||||
|
const detail = info.groupFileInfoResult;
|
||||||
|
if (detail?.retCode !== 0 || detail.fileInfo?.fileId !== fileId) {
|
||||||
|
throw new Error(`查询群文件信息失败: ${detail?.clientWording || detail?.retMsg || '未返回目标文件信息'}`);
|
||||||
|
}
|
||||||
|
busId = detail.fileInfo.busId;
|
||||||
|
}
|
||||||
|
assertBusId(busId);
|
||||||
|
resolvedBusIds.push(busId);
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await withTimeout(service.deleteGroupFile(groupCode, resolvedBusIds, files), '删除群文件');
|
||||||
|
if (response?.result !== 0) {
|
||||||
|
throw new Error(`删除群文件失败: ${response?.errMsg || response?.result}`);
|
||||||
|
}
|
||||||
|
const detail = response.transGroupFileResult;
|
||||||
|
if (detail?.result?.retCode !== 0) {
|
||||||
|
throw new Error(`删除群文件失败: ${detail?.result?.clientWording || detail?.result?.retMsg || detail?.result?.retCode || '缺少删除结果'}`);
|
||||||
|
}
|
||||||
|
if (!Array.isArray(detail.successFileIdList) || !Array.isArray(detail.failFileIdList)) {
|
||||||
|
throw new Error('删除群文件失败: 缺少逐文件删除结果');
|
||||||
|
}
|
||||||
|
const missing = files.filter(fileId => !detail.successFileIdList.includes(fileId));
|
||||||
|
if (detail.failFileIdList.length || missing.length) {
|
||||||
|
const failed = [...new Set([...detail.failFileIdList, ...missing])];
|
||||||
|
throw new Error(`删除群文件失败: ${failed.join(', ')}`);
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { GetFileListParam, MessageElement, Peer } from '@/napcat-core/types';
|
import { GetFileListParam, MessageElement, Peer } from '@/napcat-core/types';
|
||||||
import { GeneralCallResult } from './common';
|
import { GeneralCallResult } from './common';
|
||||||
|
import type { GroupFileInfoUpdateItem } from '../listeners/NodeIKernelMsgListener';
|
||||||
|
|
||||||
export enum UrlFileDownloadType {
|
export enum UrlFileDownloadType {
|
||||||
KUNKNOWN,
|
KUNKNOWN,
|
||||||
@@ -192,7 +193,14 @@ export interface NodeIKernelRichMediaService {
|
|||||||
};
|
};
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
getGroupFileInfo (arg1: unknown, arg2: unknown): unknown;
|
getGroupFileInfo (groupCode: string, fileId: string): Promise<GeneralCallResult & {
|
||||||
|
groupFileInfoResult: {
|
||||||
|
retCode: number;
|
||||||
|
retMsg: string;
|
||||||
|
clientWording: string;
|
||||||
|
fileInfo: NonNullable<GroupFileInfoUpdateItem['fileInfo']>;
|
||||||
|
};
|
||||||
|
}>;
|
||||||
|
|
||||||
getGroupTransferList (arg1: string, arg2: unknown): unknown;
|
getGroupTransferList (arg1: string, arg2: unknown): unknown;
|
||||||
|
|
||||||
@@ -235,11 +243,16 @@ export interface NodeIKernelRichMediaService {
|
|||||||
|
|
||||||
searchGroupFileByWord (arg1: unknown[], arg2: unknown[], arg3: string, arg4: string, arg5: number): unknown;
|
searchGroupFileByWord (arg1: unknown[], arg2: unknown[], arg3: string, arg4: string, arg5: number): unknown;
|
||||||
|
|
||||||
deleteGroupFile (GroupCode: string, params: Array<number>, Files: Array<string>): Promise<GeneralCallResult & {
|
deleteGroupFile (groupCode: string, busIds: Array<number>, files: Array<string>): Promise<GeneralCallResult & {
|
||||||
|
// QQ's NodeIDeleteGroupFileCallback also uses this property name.
|
||||||
transGroupFileResult: {
|
transGroupFileResult: {
|
||||||
result: unknown;
|
result: {
|
||||||
successFileIdList: Array<unknown>;
|
retCode: number;
|
||||||
failFileIdList: Array<unknown>;
|
retMsg: string;
|
||||||
|
clientWording: string;
|
||||||
|
};
|
||||||
|
successFileIdList: Array<string>;
|
||||||
|
failFileIdList: Array<string>;
|
||||||
};
|
};
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export const GoCQHTTPActionsExamples = {
|
|||||||
response: { result: {}, groupItem: {} },
|
response: { result: {}, groupItem: {} },
|
||||||
},
|
},
|
||||||
DeleteGroupFile: {
|
DeleteGroupFile: {
|
||||||
payload: { group_id: '123456', file_id: 'file_uuid_123' },
|
payload: { group_id: '123456', file_id: 'file_uuid_123', bus_id: 104 },
|
||||||
response: {},
|
response: {},
|
||||||
},
|
},
|
||||||
DeleteGroupFileFolder: {
|
DeleteGroupFileFolder: {
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import { GoCQHTTPActionsExamples } from '../example/GoCQHTTPActionsExamples';
|
|||||||
const PayloadSchema = Type.Object({
|
const PayloadSchema = Type.Object({
|
||||||
group_id: Type.String({ description: '群号' }),
|
group_id: Type.String({ description: '群号' }),
|
||||||
file_id: Type.String({ description: '文件ID' }),
|
file_id: Type.String({ description: '文件ID' }),
|
||||||
|
bus_id: Type.Optional(Type.Number({ minimum: 1, maximum: 0xFFFFFFFF, multipleOf: 1, description: '文件业务ID,默认使用文件列表中的 busid' })),
|
||||||
|
busid: Type.Optional(Type.Number({ minimum: 1, maximum: 0xFFFFFFFF, multipleOf: 1, description: '文件业务ID,兼容 busid 字段' })),
|
||||||
});
|
});
|
||||||
|
|
||||||
type PayloadType = Static<typeof PayloadSchema>;
|
type PayloadType = Static<typeof PayloadSchema>;
|
||||||
@@ -28,6 +30,14 @@ export class DeleteGroupFile extends OneBotAction<PayloadType, ReturnType> {
|
|||||||
async _handle (payload: PayloadType) {
|
async _handle (payload: PayloadType) {
|
||||||
const data = FileNapCatOneBotUUID.decodeModelId(payload.file_id);
|
const data = FileNapCatOneBotUUID.decodeModelId(payload.file_id);
|
||||||
if (!data || !data.fileId) throw new Error('Invalid file_id');
|
if (!data || !data.fileId) throw new Error('Invalid file_id');
|
||||||
return await this.core.apis.GroupApi.delGroupFile(payload.group_id.toString(), [data.fileId]);
|
const groupCode = payload.group_id.toString();
|
||||||
|
if (data.peer.chatType !== 2 || data.peer.peerUid !== groupCode) {
|
||||||
|
throw new Error('file_id 不属于指定群');
|
||||||
|
}
|
||||||
|
if (payload.bus_id !== undefined && payload.busid !== undefined && payload.bus_id !== payload.busid) {
|
||||||
|
throw new Error('bus_id 与 busid 不一致');
|
||||||
|
}
|
||||||
|
const busId = payload.bus_id ?? payload.busid ?? data.busId;
|
||||||
|
return await this.core.apis.GroupApi.delGroupFile(groupCode, [data.fileId], busId === undefined ? undefined : [busId]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,7 +112,7 @@ export class OB11Construct {
|
|||||||
static file (peerId: string, file: Exclude<GroupFileInfoUpdateParamType['item'][0]['fileInfo'], undefined>): OB11GroupFile {
|
static file (peerId: string, file: Exclude<GroupFileInfoUpdateParamType['item'][0]['fileInfo'], undefined>): OB11GroupFile {
|
||||||
return {
|
return {
|
||||||
group_id: +peerId,
|
group_id: +peerId,
|
||||||
file_id: FileNapCatOneBotUUID.encodeModelId({ chatType: 2, peerUid: peerId }, file.fileModelId, file.fileId, file.fileId ?? ''),
|
file_id: FileNapCatOneBotUUID.encodeGroupFile({ chatType: 2, peerUid: peerId }, file),
|
||||||
file_name: file.fileName,
|
file_name: file.fileName,
|
||||||
busid: file.busId,
|
busid: file.busId,
|
||||||
size: +file.fileSize,
|
size: +file.fileSize,
|
||||||
|
|||||||
Reference in new issue
Block a user