mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
build: 1.2.0-beta
This commit is contained in:
parent
920e005366
commit
a68349c23a
37
src/common/utils/asyncQuene.ts
Normal file
37
src/common/utils/asyncQuene.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { randomUUID } from "crypto";
|
||||
|
||||
class AsyncQueue {
|
||||
private tasks: Map<string, any> = new Map<string, any>();
|
||||
private MainQuene: any = undefined;
|
||||
private callbacks: Map<string, any> = new Map<string, any>();
|
||||
private ArgList: Map<string, any> = new Map<string, any>();
|
||||
private busy = false;
|
||||
// 添加任务到队列中 返回任务ID
|
||||
public async addTask(task: any, args: any[], callBack: any) {
|
||||
let uuid = randomUUID();
|
||||
this.tasks.set(uuid, task);
|
||||
this.callbacks.set(uuid, callBack);
|
||||
this.ArgList.set(uuid, args);
|
||||
return uuid;
|
||||
}
|
||||
public async runQueue() {
|
||||
if (!this.MainQuene) {
|
||||
this.MainQuene = this.Quene();
|
||||
}
|
||||
await this.MainQuene;
|
||||
this.MainQuene = undefined;
|
||||
}
|
||||
public async Quene() {
|
||||
for (let [uuid, task] of this.tasks) {
|
||||
//console.log(uuid,...this.ArgList.get(uuid));
|
||||
let result = await task(...this.ArgList.get(uuid));
|
||||
console.log(result);
|
||||
let cb = this.callbacks.get(uuid);
|
||||
cb(result);
|
||||
this.tasks.delete(uuid);
|
||||
this.ArgList.delete(uuid);
|
||||
this.callbacks.delete(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
export const ImageQuene = new AsyncQueue();
|
@ -44,6 +44,7 @@ import { deleteGroup, getFriend, getGroupMember, groupMembers, selfInfo, tempGro
|
||||
import { NTQQFileApi, NTQQGroupApi, NTQQUserApi } from '../core/src/apis';
|
||||
import http from 'http';
|
||||
import { OB11GroupMsgEmojiLikeEvent } from '@/onebot11/event/notice/OB11MsgEmojiLikeEvent';
|
||||
import { ImageQuene } from '@/common/utils/asyncQuene';
|
||||
|
||||
|
||||
export class OB11Constructor {
|
||||
@ -143,7 +144,19 @@ export class OB11Constructor {
|
||||
message_data['data']['file'] = element.picElement.fileName;
|
||||
// message_data["data"]["path"] = element.picElement.sourcePath
|
||||
// let currentRKey = "CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64"
|
||||
message_data['data']['url'] = await NTQQFileApi.getImageUrl(msg);
|
||||
ImageQuene.addTask(NTQQFileApi.getImageUrl, [msg], (result: string) => {
|
||||
message_data['data']['url'] = result;
|
||||
});
|
||||
await ImageQuene.runQueue();
|
||||
// 缓解获取失败
|
||||
try {
|
||||
if (!message_data['data']['url']) {
|
||||
message_data['data']['url'] = "";
|
||||
}
|
||||
} catch (e) {
|
||||
message_data['data']['url'] = "";
|
||||
}
|
||||
|
||||
// message_data["data"]["file_id"] = element.picElement.fileUuid
|
||||
message_data['data']['file_size'] = element.picElement.fileSize;
|
||||
dbUtil.addFileCache({
|
||||
|
Loading…
x
Reference in New Issue
Block a user