diff --git a/src/core/apis/file.ts b/src/core/apis/file.ts index 4564d4da..6a742354 100644 --- a/src/core/apis/file.ts +++ b/src/core/apis/file.ts @@ -3,12 +3,11 @@ import { CacheFileType, ChatCacheListItemBasic, ChatType, - ElementType, IMAGE_HTTP_HOST, IMAGE_HTTP_HOST_NT, Peer, PicElement, RawMessage + ElementType, IMAGE_HTTP_HOST, IMAGE_HTTP_HOST_NT, Peer, PicElement } from '@/core/entities'; import path from 'path'; import fs from 'fs'; import fsPromises from 'fs/promises'; -import { log, logDebug, logError } from '@/common/utils/log'; import { GeneralCallResult, napCatCore, OnRichMediaDownloadCompleteParams } from '@/core'; import { calculateFileMD5 } from '@/common/utils/file'; import * as fileType from 'file-type'; @@ -18,26 +17,25 @@ import { sessionConfig } from '@/core/sessionConfig'; import { rkeyManager } from '../utils/rkey'; import { NTEventDispatch } from '@/common/utils/EventTask'; import { NodeIKernelSearchService } from '../services/NodeIKernelSearchService'; -import { selfInfo } from '../data'; export class NTQQFileApi { - static async getFileType(filePath: string) { + async getFileType(filePath: string) { return fileType.fileTypeFromFile(filePath); } - static async copyFile(filePath: string, destPath: string) { + async copyFile(filePath: string, destPath: string) { await napCatCore.util.copyFile(filePath, destPath); } - static async getFileSize(filePath: string): Promise { + async getFileSize(filePath: string): Promise { return await napCatCore.util.getFileSize(filePath); } - static async getVideoUrl(peer: Peer, msgId: string, elementId: string) { + async getVideoUrl(peer: Peer, msgId: string, elementId: string) { return (await napCatCore.session.getRichMediaService().getVideoPlayUrlV2(peer, msgId, elementId, 0, { downSourceType: 1, triggerType: 1 })).urlResult.domainUrl; } // 上传文件到QQ的文件夹 - static async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC, elementSubType: number = 0) { + async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC, elementSubType: number = 0) { // napCatCore.wrapper.util. const fileMd5 = await calculateFileMD5(filePath); let ext: string = (await NTQQFileApi.getFileType(filePath))?.ext as string || ''; @@ -68,10 +66,10 @@ export class NTQQFileApi { ext }; } - static async downloadMediaByUuid() { + async downloadMediaByUuid() { //napCatCore.session.getRichMediaService().downloadFileForFileUuid(); } - static async downloadMedia(msgId: string, chatType: ChatType, peerUid: string, elementId: string, thumbPath: string, sourcePath: string, timeout = 1000 * 60 * 2, force: boolean = false) { + 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)) { @@ -135,7 +133,7 @@ export class NTQQFileApi { return filePath; } - static async getImageSize(filePath: string): Promise { + async getImageSize(filePath: string): Promise { return new Promise((resolve, reject) => { imageSize(filePath, (err, dimensions) => { if (err) { @@ -146,7 +144,7 @@ export class NTQQFileApi { }); }); } - static async addFileCache(peer: Peer, msgId: string, msgSeq: string, senderUid: string, elemId: string, elemType: string, fileSize: string, fileName: string) { + async addFileCache(peer: Peer, msgId: string, msgSeq: string, senderUid: string, elemId: string, elemType: string, fileSize: string, fileName: string) { let GroupData; let BuddyData; if (peer.chatType === ChatType.group) { @@ -204,7 +202,7 @@ export class NTQQFileApi { ] }); } - static async searchfile(keys: string[]) { + async searchfile(keys: string[]) { type EventType = NodeIKernelSearchService['searchFileWithKeywords']; interface OnListener { searchId: string, @@ -256,7 +254,7 @@ export class NTQQFileApi { let [ret] = (await Listener); return ret; } - static async getImageUrl(element: PicElement) { + async getImageUrl(element: PicElement) { if (!element) { return ''; } @@ -291,51 +289,51 @@ export class NTQQFileApi { } export class NTQQFileCacheApi { - static async setCacheSilentScan(isSilent: boolean = true) { + async setCacheSilentScan(isSilent: boolean = true) { return ''; } - static getCacheSessionPathList() { + getCacheSessionPathList() { return ''; } - static clearCache(cacheKeys: Array = ['tmp', 'hotUpdate']) { + clearCache(cacheKeys: Array = ['tmp', 'hotUpdate']) { // 参数未验证 return napCatCore.session.getStorageCleanService().clearCacheDataByKeys(cacheKeys); } - static addCacheScannedPaths(pathMap: object = {}) { + addCacheScannedPaths(pathMap: object = {}) { return napCatCore.session.getStorageCleanService().addCacheScanedPaths(pathMap); } - static scanCache(): Promise { // 需要注册Listener onFinishScan return napCatCore.session.getStorageCleanService().scanCache(); } - static getHotUpdateCachePath() { + getHotUpdateCachePath() { // 未实现 return ''; } - static getDesktopTmpPath() { + getDesktopTmpPath() { // 未实现 return ''; } - static getChatCacheList(type: ChatType, pageSize: number = 1000, pageIndex: number = 0) { + getChatCacheList(type: ChatType, pageSize: number = 1000, pageIndex: number = 0) { return napCatCore.session.getStorageCleanService().getChatCacheInfo(type, pageSize, 1, pageIndex); } - static getFileCacheInfo(fileType: CacheFileType, pageSize: number = 1000, lastRecord?: CacheFileListItem) { + getFileCacheInfo(fileType: CacheFileType, pageSize: number = 1000, lastRecord?: CacheFileListItem) { const _lastRecord = lastRecord ? lastRecord : { fileType: fileType }; //需要五个参数 //return napCatCore.session.getStorageCleanService().getFileCacheInfo(); } - static async clearChatCache(chats: ChatCacheListItemBasic[] = [], fileKeys: string[] = []) { + async clearChatCache(chats: ChatCacheListItemBasic[] = [], fileKeys: string[] = []) { return napCatCore.session.getStorageCleanService().clearChatCacheInfo(chats, fileKeys); } } diff --git a/src/core/apis/user.ts b/src/core/apis/user.ts index dea9937f..b269874e 100644 --- a/src/core/apis/user.ts +++ b/src/core/apis/user.ts @@ -1,13 +1,7 @@ -import { ModifyProfileParams, SelfInfo, User, UserDetailInfoByUin, UserDetailInfoByUinV2 } from '@/core/entities'; -import { friends, groupMembers, selfInfo } from '@/core/data'; -import { CacheClassFuncAsync, CacheClassFuncAsyncExtend } from '@/common/utils/helper'; -import { napCatCore, NTQQFriendApi } from '@/core'; +import type { ModifyProfileParams, SelfInfo, User, UserDetailInfoByUin, UserDetailInfoByUinV2 } from '@/core/entities'; import { NodeIKernelProfileListener, ProfileListener } from '@/core/listeners'; import { RequestUtil } from '@/common/utils/request'; -import { logWarn } from '@/common/utils/log'; -import { NTEventDispatch } from '@/common/utils/EventTask'; import { NodeIKernelProfileService, ProfileBizType, UserDetailSource } from '@/core/services'; -import { requireMinNTQQBuild } from '@/common/utils/QQBasicInfo'; export class NTQQUserApi { async getProfileLike(uid: string) { @@ -156,14 +150,12 @@ export class NTQQUserApi { return napCatCore.session.getProfileService().modifyDesktopMiniProfile(param); } //需要异常处理 - @CacheClassFuncAsync(1800 * 1000) async getCookies(domain: string) { const ClientKeyData = await NTQQUserApi.forceFetchClientKey(); const requestUrl = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + selfInfo.uin + '&clientkey=' + ClientKeyData.clientKey + '&u1=https%3A%2F%2F' + domain + '%2F' + selfInfo.uin + '%2Finfocenter&keyindex=19%27' let cookies: { [key: string]: string; } = await RequestUtil.HttpsGetCookies(requestUrl); return cookies; } - @CacheClassFuncAsync(1800 * 1000) async getPSkey(domainList: string[]) { return await napCatCore.session.getTipOffService().getPskey(domainList, true); } @@ -178,7 +170,7 @@ export class NTQQUserApi { return robotUinRanges?.response?.robotUinRanges; } //需要异常处理 - @CacheClassFuncAsync(1800 * 1000) + async getQzoneCookies() { const ClientKeyData = await NTQQUserApi.forceFetchClientKey(); const requestUrl = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + selfInfo.uin + '&clientkey=' + ClientKeyData.clientKey + '&u1=https%3A%2F%2Fuser.qzone.qq.com%2F' + selfInfo.uin + '%2Finfocenter&keyindex=19%27' @@ -186,7 +178,7 @@ export class NTQQUserApi { return cookies; } //需要异常处理 - @CacheClassFuncAsync(1800 * 1000) + async getSkey(): Promise { const ClientKeyData = await NTQQUserApi.forceFetchClientKey(); if (ClientKeyData.result !== 0) { diff --git a/src/core/apis/webapi.ts b/src/core/apis/webapi.ts index d1dbe4c5..e233ed6f 100644 --- a/src/core/apis/webapi.ts +++ b/src/core/apis/webapi.ts @@ -1,8 +1,4 @@ -import { selfInfo } from '@/core/data'; -import { log, logDebug } from '@/common/utils/log'; -import { NTQQUserApi } from './user'; import { RequestUtil } from '@/common/utils/request'; -import { CacheClassFuncAsync } from '@/common/utils/helper'; export enum WebHonorType { ALL = 'all', TALKACTIVE = 'talkative', @@ -117,7 +113,7 @@ export class WebApi { async shareDigest(groupCode: string, msgSeq: string, msgRandom: string, targetGroupCode: string) { const CookiesObject = await NTQQUserApi.getCookies('qun.qq.com'); const CookieValue = Object.entries(CookiesObject).map(([key, value]) => `${key}=${value}`).join('; '); - const Bkn = WebApi.genBkn(CookiesObject.skey); + const Bkn = this.genBkn(CookiesObject.skey); let ret: any = undefined; const data = 'group_code=' + groupCode + '&msg_seq=' + msgSeq + '&msg_random=' + msgRandom + '&target_group_code=' + targetGroupCode; const url = 'https://qun.qq.com/cgi-bin/group_digest/share_digest?bkn=' + Bkn + "&" + data; @@ -134,7 +130,7 @@ export class WebApi { async getGroupEssenceMsg(GroupCode: string, page_start: string) { const CookiesObject = await NTQQUserApi.getCookies('qun.qq.com'); const CookieValue = Object.entries(CookiesObject).map(([key, value]) => `${key}=${value}`).join('; '); - const Bkn = WebApi.genBkn(CookiesObject.skey); + const Bkn = this.genBkn(CookiesObject.skey); const url = 'https://qun.qq.com/cgi-bin/group_digest/digest_list?bkn=' + Bkn + '&group_code=' + GroupCode + '&page_start=' + page_start + '&page_limit=20'; let ret; try { @@ -155,7 +151,7 @@ export class WebApi { try { const CookiesObject = await NTQQUserApi.getCookies('qun.qq.com'); const CookieValue = Object.entries(CookiesObject).map(([key, value]) => `${key}=${value}`).join('; '); - const Bkn = WebApi.genBkn(CookiesObject.skey); + const Bkn = this.genBkn(CookiesObject.skey); const retList: Promise[] = []; const fastRet = await RequestUtil.HttpGetJson('https://qun.qq.com/cgi-bin/qun_mgr/search_group_members?st=0&end=40&sort=1&gc=' + GroupCode + '&bkn=' + Bkn, 'POST', '', { 'Cookie': CookieValue }); if (!fastRet?.count || fastRet?.errcode !== 0 || !fastRet?.mems) { @@ -204,7 +200,7 @@ export class WebApi { const CookiesObject = await NTQQUserApi.getCookies('qun.qq.com'); const CookieValue = Object.entries(CookiesObject).map(([key, value]) => `${key}=${value}`).join('; '); - const Bkn = WebApi.genBkn(CookiesObject.skey); + const Bkn = this.genBkn(CookiesObject.skey); let ret: any = undefined; const data = 'qid=' + GroupCode + '&bkn=' + Bkn + '&text=' + Content + '&pinned=0&type=1&settings={"is_show_edit_card":1,"tip_window_type":1,"confirm_required":1}'; const url = 'https://web.qun.qq.com/cgi-bin/announce/add_qun_notice?bkn=' + Bkn; @@ -219,7 +215,7 @@ export class WebApi { async getGrouptNotice(GroupCode: string): Promise { const CookiesObject = await NTQQUserApi.getCookies('qun.qq.com'); const CookieValue = Object.entries(CookiesObject).map(([key, value]) => `${key}=${value}`).join('; '); - const Bkn = WebApi.genBkn(CookiesObject.skey); + const Bkn = this.genBkn(CookiesObject.skey); let ret: WebApiGroupNoticeRet | undefined = undefined; //console.log(CookieValue); const url = 'https://web.qun.qq.com/cgi-bin/announce/get_t_list?bkn=' + Bkn + '&qid=' + GroupCode + '&ft=23&ni=1&n=1&i=1&log_read=1&platform=1&s=-1&n=20';