update folder watcher
This commit is contained in:
parent
ffc12a7f9e
commit
80458b4738
|
|
@ -40,12 +40,13 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
|
||||
folderWatcher.on("add", async (filePath) => {
|
||||
//import log new file
|
||||
console.log(filePath.split("/")[filePath.split("/").length - 1]?.split("-")[0] + "&&&&" + moment(Date.now()).format("YYYYMMDD").toString())
|
||||
console.log(filePath.split("/")[filePath.split("/").length - 1]?.split("-")[0] === moment(Date.now()).format("YYYYMMDD").toString())
|
||||
if (filePath?.split(".")[filePath.split(".").length - 1] === "log" && filePath.split("/")[filePath.split("/").length - 1]?.split("-")[0] === moment(Date.now()).format("YYYYMMDD").toString()) {
|
||||
console.log('New file added: ', filePath);
|
||||
console.log("first")
|
||||
const conn = await LogDetectFile.firstOrCreate(
|
||||
if (
|
||||
filePath?.split(".")[filePath.split(".").length - 1] === "log" &&
|
||||
filePath.split("/")[filePath.split("/").length - 1]?.split("-")[0] ===
|
||||
moment(Date.now()).format("YYYYMMDD").toString()
|
||||
) {
|
||||
console.log("New file added: ", filePath);
|
||||
await LogDetectFile.firstOrCreate(
|
||||
{ file_name: filePath.split("/")[filePath.split("/").length - 1] },
|
||||
{ file_name: filePath.split("/")[filePath.split("/").length - 1] }
|
||||
);
|
||||
|
|
@ -57,8 +58,6 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
fileList_old = fileList;
|
||||
updateFileList();
|
||||
watchFilesInList();
|
||||
|
||||
await Database.manager.close("conn")
|
||||
}
|
||||
// updateFile;
|
||||
});
|
||||
|
|
@ -97,27 +96,27 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
// }
|
||||
// });
|
||||
// if (value.length === keyWord.length) {
|
||||
const log = await LogDetectFile.findBy(
|
||||
"file_name",
|
||||
fileName
|
||||
);
|
||||
let checkLog = await Database.rawQuery(
|
||||
"select * from log_reports where id_file = " +
|
||||
log?.id_ldf +
|
||||
" and line = " +
|
||||
(index + 1) +
|
||||
" and detected_content='" +
|
||||
value +
|
||||
"'"
|
||||
);
|
||||
if (checkLog[0].length === 0) {
|
||||
await LogReport.create({
|
||||
detected_content: value,
|
||||
line: index + 1,
|
||||
id_file: log?.id_ldf,
|
||||
});
|
||||
lines.push(index + 1);
|
||||
}
|
||||
const log = await LogDetectFile.findBy(
|
||||
"file_name",
|
||||
fileName
|
||||
);
|
||||
let checkLog = await Database.rawQuery(
|
||||
"select * from log_reports where id_file = " +
|
||||
log?.id_ldf +
|
||||
" and line = " +
|
||||
(index + 1) +
|
||||
" and detected_content='" +
|
||||
value +
|
||||
"'"
|
||||
);
|
||||
if (checkLog[0].length === 0) {
|
||||
await LogReport.create({
|
||||
detected_content: value,
|
||||
line: index + 1,
|
||||
id_file: log?.id_ldf,
|
||||
});
|
||||
lines.push(index + 1);
|
||||
}
|
||||
// }
|
||||
}
|
||||
});
|
||||
|
|
@ -127,7 +126,6 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
if (lines.length === 0) {
|
||||
console.log(`${fileName} has changed (${eventType})---Good`);
|
||||
} else {
|
||||
|
||||
console.log(
|
||||
`${fileName} has changed (${eventType})---SOS---${lines.length}`
|
||||
);
|
||||
|
|
@ -142,20 +140,27 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
fileDetect?.id_ldf
|
||||
);
|
||||
|
||||
let content = "| |Detected at | Line | Item/error | Content | Report\n|---|:---:|:---:|:---:|:---|:-----------:\n";
|
||||
let content =
|
||||
"| |Detected at | Line | Item/error | Content | Report\n|---|:---:|:---:|:---:|:---|:-----------:\n";
|
||||
let spoiler = "";
|
||||
let file = await fs
|
||||
.readFileSync(filePath)
|
||||
.toString()
|
||||
?.split("\n");
|
||||
.readFileSync(filePath)
|
||||
.toString()
|
||||
?.split("\n");
|
||||
if (logsDetect[0].length > 10) {
|
||||
spoiler = spoiler + "```spoiler ..."+ (logsDetect[0].length - 5) +" more items\n" + content
|
||||
spoiler =
|
||||
spoiler +
|
||||
"```spoiler ..." +
|
||||
(logsDetect[0].length - 5) +
|
||||
" more items\n" +
|
||||
content;
|
||||
|
||||
logsDetect[0].reverse()
|
||||
logsDetect[0]
|
||||
.reverse()
|
||||
.slice(0, 5)
|
||||
?.map((log, index) => {
|
||||
content =
|
||||
content +
|
||||
content +
|
||||
"|" +
|
||||
(logsDetect[0].length - index) +
|
||||
"|**" +
|
||||
|
|
@ -163,7 +168,9 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
"**|" +
|
||||
log.line +
|
||||
"|" +
|
||||
log.detected_content + "|"+ file[log.line-1] +
|
||||
log.detected_content +
|
||||
"|" +
|
||||
file[log.line - 1] +
|
||||
"|[View](https://logs.danielvu.com/api/log/showLog/" +
|
||||
fileName +
|
||||
")\n";
|
||||
|
|
@ -181,7 +188,9 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
"**|" +
|
||||
log.line +
|
||||
"|" +
|
||||
log.detected_content + "|"+ file[log.line-1] +
|
||||
log.detected_content +
|
||||
"|" +
|
||||
file[log.line - 1] +
|
||||
"|[View](https://logs.danielvu.com/api/log/showLog/" +
|
||||
fileName +
|
||||
")\n";
|
||||
|
|
@ -196,13 +205,15 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
(logsDetect[0].length - index) +
|
||||
"|**" +
|
||||
moment(log.created_at).format("HH:mm - DD/MM") +
|
||||
"**|" +
|
||||
log.line +
|
||||
"|" +
|
||||
log.detected_content + "|"+ file[log.line-1] +
|
||||
"|[View](https://logs.danielvu.com/api/log/showLog/" +
|
||||
fileName +
|
||||
")\n";
|
||||
"**|" +
|
||||
log.line +
|
||||
"|" +
|
||||
log.detected_content +
|
||||
"|" +
|
||||
file[log.line - 1] +
|
||||
"|[View](https://logs.danielvu.com/api/log/showLog/" +
|
||||
fileName +
|
||||
")\n";
|
||||
});
|
||||
}
|
||||
// setTimeout(() => {
|
||||
|
|
@ -211,8 +222,11 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
"Result test - auto.nswteam.net",
|
||||
"Log Alert",
|
||||
":warning: :warning: **" +
|
||||
fileName +
|
||||
"**\n\n"+content+"\n\n"+spoiler
|
||||
fileName +
|
||||
"**\n\n" +
|
||||
content +
|
||||
"\n\n" +
|
||||
spoiler
|
||||
);
|
||||
// }, 3000);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue