refactor: 初步fileApi就绪

This commit is contained in:
手瓜一十雪
2024-08-09 17:12:57 +08:00
parent dfb31b78d9
commit b016268fdb
9 changed files with 84 additions and 80 deletions

View File

@@ -75,69 +75,71 @@ export class NTQQFileApi {
async downloadMediaByUuid() {
//napCatCore.session.getRichMediaService().downloadFileForFileUuid();
}
// async downloadMedia(msgId: string, chatType: ChatType, peerUid: string, elementId: string, thumbPath: string, sourcePath: string, timeout = 1000 * 60 * 2, force: boolean = false) {
// //logDebug('receive downloadMedia task', msgId, chatType, peerUid, elementId, thumbPath, sourcePath, timeout, force);
// // 用于下载收到的消息中的图片等
// if (sourcePath && fs.existsSync(sourcePath)) {
// if (force) {
// try {
// await fsPromises.unlink(sourcePath);
// } catch (e) {
// //
// }
// } else {
// return sourcePath;
// }
// }
// const data = await this.core.eventWrapper.CallNormalEvent<
// (
// params: {
// fileModelId: string,
// downloadSourceType: number,
// triggerType: number,
// msgId: string,
// chatType: ChatType,
// peerUid: string,
// elementId: string,
// thumbSize: number,
// downloadType: number,
// filePath: string
// }) => Promise<unknown>,
// (fileTransNotifyInfo: OnRichMediaDownloadCompleteParams) => void
// >(
// 'NodeIKernelMsgService/downloadRichMedia',
// 'NodeIKernelMsgListener/onRichMediaDownloadComplete',
// 1,
// timeout,
// (arg: OnRichMediaDownloadCompleteParams) => {
// if (arg.msgId === msgId) {
// return true;
// }
// return false;
// },
// {
// fileModelId: '0',
// downloadSourceType: 0,
// triggerType: 1,
// msgId: msgId,
// chatType: chatType,
// peerUid: peerUid,
// elementId: elementId,
// thumbSize: 0,
// downloadType: 1,
// filePath: thumbPath
// }
// );
// let filePath = data[1].filePath;
// if (filePath.startsWith('\\')) {
// // log('filePath start with \\');
// const downloadPath = sessionConfig.defaultFileDownloadPath;
// //logDebug('downloadPath', downloadPath);
// filePath = path.join(downloadPath, filePath);
// // 下载路径是下载文件夹的相对路径
// }
// return filePath;
// }
async downloadMedia(msgId: string, chatType: ChatType, peerUid: string, elementId: string, thumbPath: string, sourcePath: string, timeout = 1000 * 60 * 2, force: boolean = false) {
//logDebug('receive downloadMedia task', msgId, chatType, peerUid, elementId, thumbPath, sourcePath, timeout, force);
// 用于下载收到的消息中的图片等
if (sourcePath && fs.existsSync(sourcePath)) {
if (force) {
try {
await fsPromises.unlink(sourcePath);
} catch (e) {
//
}
} else {
return sourcePath;
}
}
const data = await this.core.eventWrapper.CallNormalEvent<
(
params: {
fileModelId: string,
downloadSourceType: number,
triggerType: number,
msgId: string,
chatType: ChatType,
peerUid: string,
elementId: string,
thumbSize: number,
downloadType: number,
filePath: string
}) => Promise<unknown>,
(fileTransNotifyInfo: OnRichMediaDownloadCompleteParams) => void
>(
'NodeIKernelMsgService/downloadRichMedia',
'NodeIKernelMsgListener/onRichMediaDownloadComplete',
1,
timeout,
(arg: OnRichMediaDownloadCompleteParams) => {
if (arg.msgId === msgId) {
return true;
}
return false;
},
{
fileModelId: '0',
downloadSourceType: 0,
triggerType: 1,
msgId: msgId,
chatType: chatType,
peerUid: peerUid,
elementId: elementId,
thumbSize: 0,
downloadType: 1,
filePath: thumbPath
}
);
let filePath = data[1].filePath;
if (filePath.startsWith('\\')) {
// log('filePath start with \\');
// Mlikiowa V2.0.0 Refactor Todo
//const downloadPath = sessionConfig.defaultFileDownloadPath;
//logDebug('downloadPath', downloadPath);
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
filePath = path.join("", filePath);
// 下载路径是下载文件夹的相对路径
}
return filePath;
}
async getImageSize(filePath: string): Promise<ISizeCalculationResult | undefined> {
return new Promise((resolve, reject) => {

View File

@@ -8,7 +8,7 @@ import { MsgListener, ProfileListener } from "./listeners";
import { sleep } from "@/common/utils/helper";
import { SelfInfo, LineDevice, SelfStatusInfo } from "./entities";
import { LegacyNTEventWrapper } from "@/common/framework/event-legacy";
import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, NTQQSystemApi, NTQQUserApi, NTQQWebApi } from "./apis";
import { NTQQFileApi, NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, NTQQSystemApi, NTQQUserApi, NTQQWebApi } from "./apis";
import os from "node:os";
import { NTQQCollectionApi } from "./apis/collection";
export enum NapCatCoreWorkingEnv {
@@ -43,8 +43,9 @@ export class NapCatCore {
this.eventWrapper = new LegacyNTEventWrapper(context.wrapper, context.session);
this.initNapCatCoreListeners().then().catch(console.error);
this.ApiContext = {
SystemApi:new NTQQSystemApi(this.context, this),
CollectionApi:new NTQQCollectionApi(this.context, this),
FileApi: new NTQQFileApi(this.context, this),
SystemApi: new NTQQSystemApi(this.context, this),
CollectionApi: new NTQQCollectionApi(this.context, this),
WebApi: new NTQQWebApi(this.context, this),
FriendApi: new NTQQFriendApi(this.context, this),
MsgApi: new NTQQMsgApi(this.context, this),

View File

@@ -4,7 +4,7 @@ import { NapCatCoreWorkingEnv } from "@/core";
import { SelfInfo } from "../entities";
import { NodeIKernelLoginService } from "../services";
import { WrapperNodeApi, NodeIQQNTWrapperSession } from "@/core";
import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, NTQQSystemApi, NTQQUserApi, NTQQWebApi } from "../apis";
import { NTQQFileApi, NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, NTQQSystemApi, NTQQUserApi, NTQQWebApi } from "../apis";
import { NTQQCollectionApi } from "../apis/collection";
export interface InstanceContext {
@@ -16,6 +16,7 @@ export interface InstanceContext {
readonly basicInfoWrapper: QQBasicInfoWrapper;
}
export interface NTApiContext {
FileApi: NTQQFileApi,
SystemApi: NTQQSystemApi,
CollectionApi: NTQQCollectionApi,
WebApi: NTQQWebApi,