mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
refactor: getUserInfo
This commit is contained in:
parent
c367728c43
commit
37bd51e138
@ -15,7 +15,6 @@ 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';
|
||||||
import { sessionConfig } from '@/core/sessionConfig';
|
import { sessionConfig } from '@/core/sessionConfig';
|
||||||
import { randomUUID } from 'crypto';
|
|
||||||
import { rkeyManager } from '../utils/rkey';
|
import { rkeyManager } from '../utils/rkey';
|
||||||
import { NTEventDispatch } from '@/common/utils/EventTask';
|
import { NTEventDispatch } from '@/common/utils/EventTask';
|
||||||
|
|
||||||
|
@ -1,52 +1,26 @@
|
|||||||
import { ModifyProfileParams, SelfInfo, User, UserDetailInfoByUin } from '@/core/entities';
|
import { ModifyProfileParams, SelfInfo, User, UserDetailInfoByUin } from '@/core/entities';
|
||||||
import { friends, selfInfo } from '@/core/data';
|
import { friends, selfInfo } from '@/core/data';
|
||||||
import { CacheClassFuncAsync, CacheClassFuncAsyncExtend } from '@/common/utils/helper';
|
import { CacheClassFuncAsync, CacheClassFuncAsyncExtend } from '@/common/utils/helper';
|
||||||
import { GeneralCallResult, napCatCore, NTQQFriendApi } from '@/core';
|
import { napCatCore } from '@/core';
|
||||||
import { ProfileListener } from '@/core/listeners';
|
import { NodeIKernelProfileListener, ProfileListener } from '@/core/listeners';
|
||||||
import { rejects } from 'assert';
|
|
||||||
import { randomUUID } from 'crypto';
|
|
||||||
import { RequestUtil } from '@/common/utils/request';
|
import { RequestUtil } from '@/common/utils/request';
|
||||||
import { log, logDebug, logError, logWarn } from '@/common/utils/log';
|
import { logWarn } from '@/common/utils/log';
|
||||||
import { NTEventDispatch } from '@/common/utils/EventTask';
|
import { NTEventDispatch } from '@/common/utils/EventTask';
|
||||||
const userInfoCache: Record<string, User> = {}; // uid: User
|
import { NodeIKernelProfileService } from '@/core/services';
|
||||||
|
|
||||||
const profileListener = new ProfileListener();
|
|
||||||
|
|
||||||
const userDetailHandlers: Map<string, ((profile: User) => void)> = new Map();
|
|
||||||
profileListener.onProfileDetailInfoChanged = (profile) => {
|
|
||||||
userInfoCache[profile.uid] = profile;
|
|
||||||
userDetailHandlers.forEach(handler => handler(profile));
|
|
||||||
};
|
|
||||||
setTimeout(() => {
|
|
||||||
napCatCore.onLoginSuccess(() => {
|
|
||||||
napCatCore.addListener(profileListener);
|
|
||||||
});
|
|
||||||
}, 100);
|
|
||||||
// 老版本逻辑现已移除
|
|
||||||
// console.log('onProfileDetailInfoChanged', profile);
|
|
||||||
// recevCount++;
|
|
||||||
// firstProfile = profile;
|
|
||||||
// if (recevCount === 2) {
|
|
||||||
// profileService.removeKernelProfileListener(listenerId);
|
|
||||||
// // if (!completed) {
|
|
||||||
// completed = true;
|
|
||||||
// resolve(profile);
|
|
||||||
// // }
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
export class NTQQUserApi {
|
export class NTQQUserApi {
|
||||||
static async getProfileLike(uid: string) {
|
static async getProfileLike(uid: string) {
|
||||||
return napCatCore.session.getProfileLikeService().getBuddyProfileLike({
|
return napCatCore.session.getProfileLikeService().getBuddyProfileLike({
|
||||||
"friendUids": [
|
friendUids: [
|
||||||
uid
|
uid
|
||||||
],
|
],
|
||||||
"basic": 1,
|
basic: 1,
|
||||||
"vote": 1,
|
vote: 1,
|
||||||
"favorite": 0,
|
favorite: 0,
|
||||||
"userProfile": 1,
|
userProfile: 1,
|
||||||
"type": 2,
|
type: 2,
|
||||||
"start": 0,
|
start: 0,
|
||||||
"limit": 20
|
limit: 20
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
static async setLongNick(longNick: string) {
|
static async setLongNick(longNick: string) {
|
||||||
@ -87,45 +61,26 @@ export class NTQQUserApi {
|
|||||||
// KQZONE,
|
// KQZONE,
|
||||||
// KOTHER
|
// KOTHER
|
||||||
// }
|
// }
|
||||||
static async getUserDetailInfo(uid: string): Promise<User> {
|
static async getUserDetailInfo(uid: string) {
|
||||||
// const existUser = userInfoCache[uid];
|
type EventService = NodeIKernelProfileService['getUserDetailInfoWithBizInfo'];
|
||||||
// if (existUser) {
|
type EventListener = NodeIKernelProfileListener['onProfileDetailInfoChanged'];
|
||||||
// return existUser;
|
let [_retData, profile] = await NTEventDispatch.CallNormalEvent
|
||||||
// }
|
<EventService, EventListener>
|
||||||
const profileService = napCatCore.session.getProfileService();
|
(
|
||||||
// console.log('getUserDetailInfo', result);
|
'NodeIKernelProfileService/getUserDetailInfoWithBizInfo',
|
||||||
return new Promise((resolve, reject) => {
|
'NodeIKernelProfileListener/onProfileDetailInfoChanged',
|
||||||
const uuid = randomUUID();
|
2,
|
||||||
let completed = false;
|
5000,
|
||||||
let retData: User | undefined = undefined;
|
(profile: User) => {
|
||||||
let isFirst = true;
|
if (profile.uid === uid) {
|
||||||
// 不管返回几次 超时有数据就该返回 兼容就好了
|
return true;
|
||||||
setTimeout(() => {
|
|
||||||
if (!completed) {
|
|
||||||
if (retData) {
|
|
||||||
resolve(retData);
|
|
||||||
} else {
|
|
||||||
reject('getUserDetailInfo timeout');
|
|
||||||
}
|
}
|
||||||
}
|
return false;
|
||||||
userDetailHandlers.delete(uuid);
|
},
|
||||||
}, 5000);
|
uid,
|
||||||
userDetailHandlers.set(uuid, (profile) => {
|
[0]
|
||||||
if (profile.uid === uid) {
|
);
|
||||||
if (isFirst) {
|
return profile;
|
||||||
retData = profile;
|
|
||||||
isFirst = false;
|
|
||||||
// console.log('getUserDetailInfo', profile);
|
|
||||||
} else {
|
|
||||||
completed = true;
|
|
||||||
resolve(profile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
profileService.getUserDetailInfoWithBizInfo(uid, [0]).then(result => {
|
|
||||||
// console.log('getUserDetailInfo', result);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
static async modifySelfProfile(param: ModifyProfileParams) {
|
static async modifySelfProfile(param: ModifyProfileParams) {
|
||||||
return napCatCore.session.getProfileService().modifyDesktopMiniProfile(param);
|
return napCatCore.session.getProfileService().modifyDesktopMiniProfile(param);
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import BaseAction from '../BaseAction';
|
import BaseAction from '../BaseAction';
|
||||||
import { ActionName, BaseCheckResult } from '../types';
|
import { ActionName } from '../types';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { join as joinPath } from 'node:path';
|
import { join as joinPath } from 'node:path';
|
||||||
import { calculateFileMD5, getTempDir, httpDownload } from '@/common/utils/file';
|
import { calculateFileMD5, getTempDir, httpDownload } from '@/common/utils/file';
|
||||||
import { v4 as uuid4 } from 'uuid';
|
import { randomUUID } from 'crypto';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
import Ajv from 'ajv';
|
|
||||||
interface FileResponse {
|
interface FileResponse {
|
||||||
file: string;
|
file: string;
|
||||||
}
|
}
|
||||||
@ -32,7 +31,7 @@ export default class GoCQHTTPDownloadFile extends BaseAction<Payload, FileRespon
|
|||||||
PayloadSchema = SchemaData;
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload): Promise<FileResponse> {
|
protected async _handle(payload: Payload): Promise<FileResponse> {
|
||||||
const isRandomName = !payload.name;
|
const isRandomName = !payload.name;
|
||||||
const name = payload.name || uuid4();
|
const name = payload.name || randomUUID();
|
||||||
const filePath = joinPath(getTempDir(), name);
|
const filePath = joinPath(getTempDir(), name);
|
||||||
|
|
||||||
if (payload.base64) {
|
if (payload.base64) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user