mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
refactor: log path
This commit is contained in:
parent
465b7eaf6e
commit
19dfc06822
@ -11,13 +11,13 @@
|
|||||||
"link": "https://github.com/linyuchen"
|
"link": "https://github.com/linyuchen"
|
||||||
}],
|
}],
|
||||||
"repository": {
|
"repository": {
|
||||||
"repo": "linyuchen/LiteLoaderQQNT-OneBotApi",
|
"repo": "linyuchen/LiteLoaderQQNT-OneBotApi",
|
||||||
"branch": "main",
|
"branch": "main",
|
||||||
"release": {
|
"release": {
|
||||||
"tag": "latest",
|
"tag": "latest",
|
||||||
"name": "LLOneBot.zip"
|
"name": "LLOneBot.zip"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"platform": [
|
"platform": [
|
||||||
"win32",
|
"win32",
|
||||||
"linux",
|
"linux",
|
||||||
|
2
src/global.d.ts
vendored
2
src/global.d.ts
vendored
@ -43,7 +43,7 @@ declare var llonebot: {
|
|||||||
setConfig(config: Config):void;
|
setConfig(config: Config):void;
|
||||||
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, fileName: string}):Promise<string>;
|
||||||
deleteFile(path: string[]):Promise<void>;
|
deleteFile(path: string[]):Promise<void>;
|
||||||
getRunningStatus(): Promise<boolean>;
|
getRunningStatus(): Promise<boolean>;
|
||||||
};
|
};
|
||||||
|
@ -17,7 +17,7 @@ import {
|
|||||||
} from "../common/IPCChannel";
|
} from "../common/IPCChannel";
|
||||||
import {ConfigUtil} from "./config";
|
import {ConfigUtil} from "./config";
|
||||||
import {startExpress} from "./HttpServer";
|
import {startExpress} from "./HttpServer";
|
||||||
import {isGIF, log} from "./utils";
|
import {CONFIG_DIR, isGIF, log} from "./utils";
|
||||||
import {friends, groups, selfInfo} from "./data";
|
import {friends, groups, selfInfo} from "./data";
|
||||||
import {} from "../global";
|
import {} from "../global";
|
||||||
|
|
||||||
@ -30,39 +30,39 @@ let running = false;
|
|||||||
function onLoad() {
|
function onLoad() {
|
||||||
log("main onLoaded");
|
log("main onLoaded");
|
||||||
// const config_dir = browserWindow.LiteLoader.plugins["LLOneBot"].path.data;
|
// const config_dir = browserWindow.LiteLoader.plugins["LLOneBot"].path.data;
|
||||||
const config_dir = global.LiteLoader.plugins["LLOneBot"].path.data;
|
|
||||||
function getConfigUtil() {
|
function getConfigUtil() {
|
||||||
const configFilePath = path.join(config_dir, `config_${selfInfo.user_id}.json`)
|
const configFilePath = path.join(CONFIG_DIR, `config_${selfInfo.user_id}.json`)
|
||||||
return new ConfigUtil(configFilePath)
|
return new ConfigUtil(configFilePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fs.existsSync(config_dir)) {
|
if (!fs.existsSync(CONFIG_DIR)) {
|
||||||
fs.mkdirSync(config_dir, {recursive: true});
|
fs.mkdirSync(CONFIG_DIR, {recursive: true});
|
||||||
}
|
}
|
||||||
ipcMain.handle(CHANNEL_GET_CONFIG, (event: any, arg: any) => {
|
ipcMain.handle(CHANNEL_GET_CONFIG, (event: any, arg: any) => {
|
||||||
return getConfigUtil().getConfig()
|
return getConfigUtil().getConfig()
|
||||||
})
|
})
|
||||||
ipcMain.handle(CHANNEL_DOWNLOAD_FILE, async (event: any, arg: {uri: string, localFilePath: string}) => {
|
ipcMain.handle(CHANNEL_DOWNLOAD_FILE, async (event: any, arg: {uri: string, fileName: string}) => {
|
||||||
|
let filePath = path.join(CONFIG_DIR, arg.fileName)
|
||||||
let url = new URL(arg.uri);
|
let url = new URL(arg.uri);
|
||||||
if (url.protocol == "base64:"){
|
if (url.protocol == "base64:"){
|
||||||
// base64转成文件
|
// base64转成文件
|
||||||
let base64Data = arg.uri.split("base64://")[1]
|
let base64Data = arg.uri.split("base64://")[1]
|
||||||
const buffer = Buffer.from(base64Data, 'base64');
|
const buffer = Buffer.from(base64Data, 'base64');
|
||||||
|
|
||||||
fs.writeFileSync(arg.localFilePath, buffer);
|
fs.writeFileSync(filePath, buffer);
|
||||||
}
|
}
|
||||||
else if (url.protocol == "http:" || url.protocol == "https:") {
|
else if (url.protocol == "http:" || url.protocol == "https:") {
|
||||||
// 下载文件
|
// 下载文件
|
||||||
let res = await fetch(url)
|
let res = await fetch(url)
|
||||||
let blob = await res.blob();
|
let blob = await res.blob();
|
||||||
let buffer = await blob.arrayBuffer();
|
let buffer = await blob.arrayBuffer();
|
||||||
fs.writeFileSync(arg.localFilePath, Buffer.from(buffer));
|
fs.writeFileSync(filePath, Buffer.from(buffer));
|
||||||
}
|
}
|
||||||
if (isGIF(arg.localFilePath)) {
|
if (isGIF(filePath)) {
|
||||||
fs.renameSync(arg.localFilePath, arg.localFilePath + ".gif");
|
fs.renameSync(filePath, filePath + ".gif");
|
||||||
arg.localFilePath += ".gif";
|
filePath += ".gif";
|
||||||
}
|
}
|
||||||
return arg.localFilePath;
|
return filePath;
|
||||||
})
|
})
|
||||||
ipcMain.on(CHANNEL_SET_CONFIG, (event: any, arg: Config) => {
|
ipcMain.on(CHANNEL_SET_CONFIG, (event: any, arg: Config) => {
|
||||||
getConfigUtil().setConfig(arg)
|
getConfigUtil().setConfig(arg)
|
||||||
@ -113,7 +113,7 @@ function onLoad() {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify(arg)
|
body: JSON.stringify(arg)
|
||||||
}).then((res: any) => {
|
}).then((res: any) => {
|
||||||
log("新消息事件上传");
|
log("新消息事件上传成功:" + JSON.stringify(arg));
|
||||||
}, (err: any) => {
|
}, (err: any) => {
|
||||||
log("新消息事件上传失败:" + err + JSON.stringify(arg));
|
log("新消息事件上传失败:" + err + JSON.stringify(arg));
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,17 @@
|
|||||||
|
import * as path from "path";
|
||||||
|
import {json} from "express";
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
|
export const CONFIG_DIR = global.LiteLoader.plugins["LLOneBot"].path.data;
|
||||||
export function log(msg: any) {
|
export function log(msg: any) {
|
||||||
let currentDateTime = new Date().toLocaleString();
|
let currentDateTime = new Date().toLocaleString();
|
||||||
fs.appendFile("./llonebot.log", currentDateTime + ":" + msg + "\n", (err: any) => {
|
const date = new Date();
|
||||||
|
const year = date.getFullYear();
|
||||||
|
const month = date.getMonth() + 1;
|
||||||
|
const day = date.getDate();
|
||||||
|
const currentDate = `${year}-${month}-${day}`;
|
||||||
|
fs.appendFile(path.join(CONFIG_DIR , `llonebot-${currentDate}.log`), currentDateTime + ":" + JSON.stringify(msg) + "\n", (err: any) => {
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -13,4 +22,5 @@ export function isGIF(path: string) {
|
|||||||
fs.readSync(fd, buffer, 0, 4, 0);
|
fs.readSync(fd, buffer, 0, 4, 0);
|
||||||
fs.closeSync(fd);
|
fs.closeSync(fd);
|
||||||
return buffer.toString() === 'GIF8'
|
return buffer.toString() === 'GIF8'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ async function listenSendMessage(postData: PostDataSendMsg) {
|
|||||||
if (uri.protocol == "file:") {
|
if (uri.protocol == "file:") {
|
||||||
localFilePath = url.split("file://")[1]
|
localFilePath = url.split("file://")[1]
|
||||||
} else {
|
} else {
|
||||||
localFilePath = await window.llonebot.downloadFile({uri: url, localFilePath: localFilePath})
|
localFilePath = await window.llonebot.downloadFile({uri: url, fileName: localFilePath})
|
||||||
}
|
}
|
||||||
message.file = localFilePath
|
message.file = localFilePath
|
||||||
sendFiles.push(localFilePath);
|
sendFiles.push(localFilePath);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user