perf: auto remove send files

This commit is contained in:
linyuchen 2023-12-12 20:45:54 +08:00
parent 923f72e5d3
commit f07f0111cd
6 changed files with 24 additions and 8 deletions

View File

@ -4,7 +4,7 @@
"name": "LLOneBot",
"slug": "LLOneBot",
"description": "LiteLoaderQQNT的OneBotApi",
"version": "1.2.4",
"version": "1.2.5",
"thumbnail": "./icon.png",
"author": {
"name": "linyuchen",

View File

@ -9,3 +9,4 @@ export const CHANNEL_LOG = "llonebot_log"
export const CHANNEL_POST_ONEBOT_DATA = "llonebot_post_onebot_data"
export const CHANNEL_SET_SELF_INFO= "llonebot_set_self_info"
export const CHANNEL_DOWNLOAD_FILE= "llonebot_download_file"
export const CHANNEL_DELETE_FILE= "llonebot_delete_file"

1
src/global.d.ts vendored
View File

@ -44,6 +44,7 @@ declare var llonebot: {
getConfig():Promise<Config>;
setSelfInfo(selfInfo: SelfInfo):void;
downloadFile(arg: {uri: string, localFilePath: string}):Promise<string>;
deleteFile(path: string[]):Promise<void>;
};
declare global {

View File

@ -13,7 +13,7 @@ import {
CHANNEL_SET_CONFIG,
CHANNEL_START_HTTP_SERVER,
CHANNEL_UPDATE_FRIENDS,
CHANNEL_UPDATE_GROUPS
CHANNEL_UPDATE_GROUPS, CHANNEL_DELETE_FILE
} from "../common/IPCChannel";
import {ConfigUtil} from "./config";
import {startExpress} from "./HttpServer";
@ -123,6 +123,12 @@ function onLoad(plugin: any) {
selfInfo.user_id = arg.user_id;
selfInfo.nickname = arg.nickname;
})
ipcMain.on(CHANNEL_DELETE_FILE, (event: any, arg: string[]) => {
for (const path of arg) {
fs.unlinkSync(path);
}
})
}

View File

@ -6,7 +6,7 @@ import {
CHANNEL_GET_CONFIG, CHANNEL_SET_SELF_INFO, CHANNEL_LOG, CHANNEL_POST_ONEBOT_DATA,
CHANNEL_RECALL_MSG, CHANNEL_SEND_MSG,
CHANNEL_SET_CONFIG,
CHANNEL_START_HTTP_SERVER, CHANNEL_UPDATE_FRIENDS, CHANNEL_UPDATE_GROUPS
CHANNEL_START_HTTP_SERVER, CHANNEL_UPDATE_FRIENDS, CHANNEL_UPDATE_GROUPS, CHANNEL_DELETE_FILE
} from "./common/IPCChannel";
@ -50,8 +50,11 @@ contextBridge.exposeInMainWorld("llonebot", {
setSelfInfo(selfInfo: SelfInfo){
ipcRenderer.invoke(CHANNEL_SET_SELF_INFO, selfInfo)
},
downloadFile: async (arg: {uri: string, localFilePath: string}) => {
downloadFile: (arg: {uri: string, localFilePath: string}) => {
return ipcRenderer.invoke(CHANNEL_DOWNLOAD_FILE, arg);
},
deleteFile: async (localFilePath: string[]) => {
ipcRenderer.send(CHANNEL_DELETE_FILE, localFilePath);
}
// startExpress,
});

View File

@ -20,7 +20,7 @@ async function getUserInfo(uid: string): Promise<User> {
return user
}
async function getFriends(){
async function getFriends() {
let _friends = await window.LLAPI.getFriendsList(false)
for (let friend of _friends) {
let existFriend = friends.find(f => f.uin == friend.uin)
@ -210,6 +210,7 @@ async function listenSendMessage(postData: PostDataSendMsg) {
}
}
if (peer) {
let sendFiles: string[] = [];
for (let message of postData.params.message) {
if (message.type == "at") {
// @ts-ignore
@ -242,6 +243,7 @@ async function listenSendMessage(postData: PostDataSendMsg) {
await window.llonebot.downloadFile({uri: url, localFilePath: localFilePath})
}
message.file = localFilePath
sendFiles.push(localFilePath);
} else if (message.type == "reply") {
let msgId = message.data?.id || message.msgId
let replyMessage = msgHistory.find(msg => msg.raw.msgId == msgId)
@ -249,9 +251,11 @@ async function listenSendMessage(postData: PostDataSendMsg) {
message.msgSeq = replyMessage?.raw.msgSeq || ""
}
}
// 发送完之后要删除下载的文件
console.log("发送消息", postData)
window.LLAPI.sendMessage(peer, postData.params.message).then(res => console.log("消息发送成功:", peer, postData.params.message),
window.LLAPI.sendMessage(peer, postData.params.message).then(res => {
console.log("消息发送成功:", peer, postData.params.message)
window.llonebot.deleteFile(sendFiles);
},
err => console.log("消息发送失败", postData, err))
}
}
@ -305,6 +309,7 @@ function onLoad() {
})
console.log("chatListEle", chatListEle)
}
getFriends().then();
getGroups().then(() => {
getGroupsMembers(groups).then(() => {