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", "name": "LLOneBot",
"slug": "LLOneBot", "slug": "LLOneBot",
"description": "LiteLoaderQQNT的OneBotApi", "description": "LiteLoaderQQNT的OneBotApi",
"version": "1.2.4", "version": "1.2.5",
"thumbnail": "./icon.png", "thumbnail": "./icon.png",
"author": { "author": {
"name": "linyuchen", "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_POST_ONEBOT_DATA = "llonebot_post_onebot_data"
export const CHANNEL_SET_SELF_INFO= "llonebot_set_self_info" export const CHANNEL_SET_SELF_INFO= "llonebot_set_self_info"
export const CHANNEL_DOWNLOAD_FILE= "llonebot_download_file" 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>; getConfig():Promise<Config>;
setSelfInfo(selfInfo: SelfInfo):void; setSelfInfo(selfInfo: SelfInfo):void;
downloadFile(arg: {uri: string, localFilePath: string}):Promise<string>; downloadFile(arg: {uri: string, localFilePath: string}):Promise<string>;
deleteFile(path: string[]):Promise<void>;
}; };
declare global { declare global {

View File

@ -13,7 +13,7 @@ import {
CHANNEL_SET_CONFIG, CHANNEL_SET_CONFIG,
CHANNEL_START_HTTP_SERVER, CHANNEL_START_HTTP_SERVER,
CHANNEL_UPDATE_FRIENDS, CHANNEL_UPDATE_FRIENDS,
CHANNEL_UPDATE_GROUPS CHANNEL_UPDATE_GROUPS, CHANNEL_DELETE_FILE
} from "../common/IPCChannel"; } from "../common/IPCChannel";
import {ConfigUtil} from "./config"; import {ConfigUtil} from "./config";
import {startExpress} from "./HttpServer"; import {startExpress} from "./HttpServer";
@ -123,6 +123,12 @@ function onLoad(plugin: any) {
selfInfo.user_id = arg.user_id; selfInfo.user_id = arg.user_id;
selfInfo.nickname = arg.nickname; 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_GET_CONFIG, CHANNEL_SET_SELF_INFO, CHANNEL_LOG, CHANNEL_POST_ONEBOT_DATA,
CHANNEL_RECALL_MSG, CHANNEL_SEND_MSG, CHANNEL_RECALL_MSG, CHANNEL_SEND_MSG,
CHANNEL_SET_CONFIG, 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"; } from "./common/IPCChannel";
@ -50,8 +50,11 @@ contextBridge.exposeInMainWorld("llonebot", {
setSelfInfo(selfInfo: SelfInfo){ setSelfInfo(selfInfo: SelfInfo){
ipcRenderer.invoke(CHANNEL_SET_SELF_INFO, 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); return ipcRenderer.invoke(CHANNEL_DOWNLOAD_FILE, arg);
}, },
deleteFile: async (localFilePath: string[]) => {
ipcRenderer.send(CHANNEL_DELETE_FILE, localFilePath);
}
// startExpress, // startExpress,
}); });

View File

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