mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
fix: try to fix '搜索名字模式' of GetFile
This commit is contained in:
@@ -17,7 +17,7 @@ import {
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import fsPromises from 'fs/promises';
|
import fsPromises from 'fs/promises';
|
||||||
import { InstanceContext, NapCatCore } from '@/core';
|
import { InstanceContext, NapCatCore, SearchResultItem } from '@/core';
|
||||||
import * as fileType from 'file-type';
|
import * as fileType from 'file-type';
|
||||||
import imageSize from 'image-size';
|
import imageSize from 'image-size';
|
||||||
import { ISizeCalculationResult } from 'image-size/dist/types/interface';
|
import { ISizeCalculationResult } from 'image-size/dist/types/interface';
|
||||||
@@ -438,17 +438,36 @@ export class NTQQFileApi {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchfile(keys: string[]) {
|
async searchForFile(keys: string[]): Promise<SearchResultItem | undefined> {
|
||||||
const Event = this.core.eventWrapper.createEventFunction('NodeIKernelSearchService/searchFileWithKeywords');
|
const [, searchResult] = await this.core.eventWrapper.callNormalEventV2(
|
||||||
const id = await Event!(keys, 12);
|
'NodeIKernelFileAssistantService/searchFile',
|
||||||
const Listener = this.core.eventWrapper.registerListen(
|
'NodeIKernelFileAssistantListener/onFileSearch',
|
||||||
'NodeIKernelSearchListener/onSearchFileKeywordsResult',
|
[
|
||||||
1,
|
keys,
|
||||||
20000,
|
{
|
||||||
(params) => id !== '' && params.searchId == id,
|
resultType: 2,
|
||||||
|
pageLimit: 1,
|
||||||
|
}
|
||||||
|
]
|
||||||
);
|
);
|
||||||
const [ret] = (await Listener);
|
return searchResult.resultItems[0];
|
||||||
return ret;
|
}
|
||||||
|
|
||||||
|
async downloadFileById(
|
||||||
|
fileId: string,
|
||||||
|
fileSize: number = 1024576,
|
||||||
|
estimatedTime: number = (fileSize * 1000 / 1024576) + 5000,
|
||||||
|
) {
|
||||||
|
const [, ret] = await this.core.eventWrapper.callNormalEventV2(
|
||||||
|
'NodeIKernelFileAssistantService/downloadFile',
|
||||||
|
'NodeIKernelFileAssistantListener/onFileStatusChanged',
|
||||||
|
[[fileId]],
|
||||||
|
ret => ret.result === 0,
|
||||||
|
status => status.fileStatus === 2 && status.fileProgress === '0',
|
||||||
|
1,
|
||||||
|
estimatedTime, // estimate 1MB/s
|
||||||
|
);
|
||||||
|
return ret.filePath!;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getImageUrl(element: PicElement) {
|
async getImageUrl(element: PicElement) {
|
||||||
|
@@ -1,5 +1,13 @@
|
|||||||
export class NodeIKernelFileAssistantListener {
|
export class NodeIKernelFileAssistantListener {
|
||||||
onFileStatusChanged(...args: unknown[]) {
|
onFileStatusChanged(fileStatus: {
|
||||||
|
id: string,
|
||||||
|
fileStatus: number,
|
||||||
|
fileProgress: `${number}`,
|
||||||
|
fileSize: `${number}`,
|
||||||
|
fileSpeed: number,
|
||||||
|
thumbPath: string | null,
|
||||||
|
filePath: string | null,
|
||||||
|
}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
onSessionListChanged(...args: unknown[]) {
|
onSessionListChanged(...args: unknown[]) {
|
||||||
@@ -11,6 +19,74 @@ export class NodeIKernelFileAssistantListener {
|
|||||||
onFileListChanged(...args: unknown[]) {
|
onFileListChanged(...args: unknown[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
onFileSearch(...args: unknown[]) {
|
onFileSearch(searchResult: {
|
||||||
|
searchId: number,
|
||||||
|
resultType: number,
|
||||||
|
hasMore: boolean,
|
||||||
|
resultItems: {
|
||||||
|
id: string,
|
||||||
|
fileName: string,
|
||||||
|
fileNameHits: string[],
|
||||||
|
fileStatus: number,
|
||||||
|
fileSize: string,
|
||||||
|
isSend: boolean,
|
||||||
|
source: number,
|
||||||
|
fileTime: string,
|
||||||
|
expTime: string,
|
||||||
|
session: {
|
||||||
|
context: null,
|
||||||
|
uid: string,
|
||||||
|
nick: string,
|
||||||
|
remark: string,
|
||||||
|
memberCard: string,
|
||||||
|
groupCode: string,
|
||||||
|
groupName: string,
|
||||||
|
groupRemark: string,
|
||||||
|
count: number,
|
||||||
|
},
|
||||||
|
thumbPath: string,
|
||||||
|
filePath: string,
|
||||||
|
msgId: string,
|
||||||
|
chatType: number,
|
||||||
|
peerUid: string,
|
||||||
|
fileType: number,
|
||||||
|
}[],
|
||||||
|
}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type SearchResultWrapper = {
|
||||||
|
searchId: number,
|
||||||
|
resultType: number,
|
||||||
|
hasMore: boolean,
|
||||||
|
resultItems: SearchResultItem[],
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SearchResultItem = {
|
||||||
|
id: string,
|
||||||
|
fileName: string,
|
||||||
|
fileNameHits: string[],
|
||||||
|
fileStatus: number,
|
||||||
|
fileSize: string,
|
||||||
|
isSend: boolean,
|
||||||
|
source: number,
|
||||||
|
fileTime: string,
|
||||||
|
expTime: string,
|
||||||
|
session: {
|
||||||
|
context: null,
|
||||||
|
uid: string,
|
||||||
|
nick: string,
|
||||||
|
remark: string,
|
||||||
|
memberCard: string,
|
||||||
|
groupCode: string,
|
||||||
|
groupName: string,
|
||||||
|
groupRemark: string,
|
||||||
|
count: number,
|
||||||
|
},
|
||||||
|
thumbPath: string,
|
||||||
|
filePath: string,
|
||||||
|
msgId: string,
|
||||||
|
chatType: number,
|
||||||
|
peerUid: string,
|
||||||
|
fileType: number,
|
||||||
|
};
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
|
import { NodeIKernelFileAssistantListener } from '@/core';
|
||||||
|
|
||||||
export interface NodeIKernelFileAssistantService {
|
export interface NodeIKernelFileAssistantService {
|
||||||
addKernelFileAssistantListener(arg1: unknown[]): unknown;
|
addKernelFileAssistantListener(listener: NodeIKernelFileAssistantListener): unknown;
|
||||||
|
|
||||||
removeKernelFileAssistantListener(arg1: unknown[]): unknown;
|
removeKernelFileAssistantListener(arg1: unknown[]): unknown;
|
||||||
|
|
||||||
@@ -9,7 +11,7 @@ export interface NodeIKernelFileAssistantService {
|
|||||||
|
|
||||||
getFileSessionList(): unknown;
|
getFileSessionList(): unknown;
|
||||||
|
|
||||||
searchFile(arg1: unknown, arg2: unknown, arg3: unknown): unknown;
|
searchFile(keywords: string[], params: { resultType: number, pageLimit: number }): unknown;
|
||||||
|
|
||||||
resetSearchFileSortType(arg1: unknown, arg2: unknown, arg3: unknown): unknown;
|
resetSearchFileSortType(arg1: unknown, arg2: unknown, arg3: unknown): unknown;
|
||||||
|
|
||||||
@@ -17,7 +19,7 @@ export interface NodeIKernelFileAssistantService {
|
|||||||
|
|
||||||
cancelSearchFile(arg1: unknown, arg2: unknown, arg3: unknown): unknown;
|
cancelSearchFile(arg1: unknown, arg2: unknown, arg3: unknown): unknown;
|
||||||
|
|
||||||
downloadFile(arg1: unknown[]): unknown;
|
downloadFile(fileIds: string[]): { result: number, errMsg: string };
|
||||||
|
|
||||||
forwardFile(arg1: unknown, arg2: unknown, arg3: unknown): unknown;
|
forwardFile(arg1: unknown, arg2: unknown, arg3: unknown): unknown;
|
||||||
|
|
||||||
|
@@ -84,29 +84,14 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//搜索名字模式
|
//搜索名字模式
|
||||||
const NTSearchNameResult = (await NTQQFileApi.searchfile([payload.file])).resultItems;
|
const searchResult = (await NTQQFileApi.searchForFile([payload.file]));
|
||||||
if (NTSearchNameResult.length !== 0) {
|
if (searchResult) {
|
||||||
const MsgId = NTSearchNameResult[0].msgId;
|
const downloadPath = await NTQQFileApi.downloadFileById(searchResult.id, parseInt(searchResult.fileSize));
|
||||||
let peer: Peer | undefined = undefined;
|
|
||||||
if (NTSearchNameResult[0].chatType == ChatType.KCHATTYPEGROUP) {
|
|
||||||
peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: NTSearchNameResult[0].groupChatInfo[0].groupCode };
|
|
||||||
}
|
|
||||||
if (!peer) throw new Error('chattype not support');
|
|
||||||
const msgList: RawMessage[] = (await NTQQMsgApi.getMsgsByMsgId(peer, [MsgId]))?.msgList;
|
|
||||||
if (!msgList || msgList.length == 0) {
|
|
||||||
throw new Error('msg not found');
|
|
||||||
}
|
|
||||||
const msg = msgList[0];
|
|
||||||
const file = msg.elements.filter(e => e.elementType == NTSearchNameResult[0].elemType);
|
|
||||||
if (file.length == 0) {
|
|
||||||
throw new Error('file not found');
|
|
||||||
}
|
|
||||||
const downloadPath = await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid, file[0].elementId, '', '');
|
|
||||||
const res: GetFileResponse = {
|
const res: GetFileResponse = {
|
||||||
file: downloadPath,
|
file: downloadPath,
|
||||||
url: downloadPath,
|
url: downloadPath,
|
||||||
file_size: NTSearchNameResult[0].fileSize.toString(),
|
file_size: searchResult.fileSize.toString(),
|
||||||
file_name: NTSearchNameResult[0].fileName,
|
file_name: searchResult.fileName,
|
||||||
};
|
};
|
||||||
if (this.obContext.configLoader.configData.enableLocalFile2Url && downloadPath) {
|
if (this.obContext.configLoader.configData.enableLocalFile2Url && downloadPath) {
|
||||||
try {
|
try {
|
||||||
|
Reference in New Issue
Block a user