diff --git a/app/store/logs/20230919-TEST.log b/app/store/logs/20230919-TEST.log new file mode 100644 index 0000000..8483dc6 --- /dev/null +++ b/app/store/logs/20230919-TEST.log @@ -0,0 +1,8 @@ +adfasf +anfasll ak shflks as klhfalk la EHWIC- fsjl +123 PVDM3- hui 800G2-POE-2 +sdhgksd sjk hk error +abc 123 fail +abc 123 fail +sdhgksd sjk hk error +123 PVDM3- hui 800G2-POE-2 \ No newline at end of file diff --git a/app/utils/deleteMessageZulip.ts b/app/utils/deleteMessageZulip.ts new file mode 100644 index 0000000..dfe3555 --- /dev/null +++ b/app/utils/deleteMessageZulip.ts @@ -0,0 +1,44 @@ +const zulip = require("zulip-js"); + +export async function deleteMessagesZulip(streamName, topicName, numOfDay) { + const config = { + zuliprc: "./download", + zulipVersion: "v2", + }; + const client = await zulip(config); + try { + const messages = await client.messages.retrieve({ + anchor: "oldest", + num_before: 0, + num_after: 5000, + narrow: [ + { operator: "stream", operand: streamName }, + { operator: "topic", operand: topicName }, + ], + }); + // console.log(messages.messages.map(u=>u.reactions)) + const members = await client.users.retrieve(); + + // console.log(members.members) + for (const message of messages.messages) { + if ( + message.reactions.filter( + (i) => + i.emoji_name === "working_on_it" && + members.members.filter((u) => u.user_id === i.user_id)[0] + .is_admin === true + ).length === 0 && + message.timestamp < + Math.floor((Date.now() - 60000 * 60 * 24 * numOfDay) / 1000) + ) { + const res = await client.messages.deleteById({ + message_id: message.id, + }); + console.log(`Deleted message ID ${message.id}`); + // console.log(res) + } + } + } catch (error) { + console.error("Error:", error); + } +} diff --git a/app/utils/runtimeCheckLogs.ts b/app/utils/runtimeCheckLogs.ts index cae0462..2266c70 100644 --- a/app/utils/runtimeCheckLogs.ts +++ b/app/utils/runtimeCheckLogs.ts @@ -7,8 +7,6 @@ import KeyValue from "App/Models/KeyValue"; import Database from "@ioc:Adonis/Lucid/Database"; import { sendMessToZulip } from "./sendMessToZulip"; import { getListLineByItem } from "./getListLineByItem"; -import { screenShot } from "./screenShot"; -import { uploadFileToZulip } from "./uploadFileZulip"; // export default class loggerAPI { export async function runtimeCheckLogs(folderPath) { @@ -45,9 +43,11 @@ export async function runtimeCheckLogs(folderPath) { //import log new file // console.log(filePath) if ( - //Sua \\ --> / + filePath?.split(".")[filePath.split(".").length - 1] === "log" && filePath.split("/")[filePath.split("/").length - 1]?.split("-")[0] === + //localhost + // filePath.split("\\")[filePath.split("\\").length - 1]?.split("-")[0] === moment(Date.now()).format("YYYYMMDD").toString() ) { console.log("New file added: ", filePath); @@ -55,6 +55,7 @@ export async function runtimeCheckLogs(folderPath) { { file_name: filePath.split("/")[filePath.split("/").length - 1] }, { file_name: filePath.split("/")[filePath.split("/").length - 1] } ); + //localhost // await LogDetectFile.firstOrCreate( // { file_name: filePath.split("\\")[filePath.split("\\").length - 1] }, // { file_name: filePath.split("\\")[filePath.split("\\").length - 1] } @@ -191,15 +192,24 @@ export async function runtimeCheckLogs(folderPath) { let item = listExtraItem.includes(log.detected_content) ? ":medal: **" + log.detected_content + "**" : ":small_orange_diamond: " + log.detected_content; - - log.line?.map((line)=>{ + + log.line?.map((line) => { issueFound = - issueFound + - "\n" + - line + - "$" + - contentFile[line-1]?.replace(log.detected_content, "`" + log.detected_content + "`") - }) + issueFound + + "\n`" + + line + + "` " + + contentFile[line - 1]?.replace( + log.detected_content, + "[" + + log.detected_content + + "](https://logs.danielvu.com/logs/" + + fileName + + "#" + + line + + ")" + ); + }); content = content + "|" + @@ -228,23 +238,24 @@ export async function runtimeCheckLogs(folderPath) { content + "\n\n" + spoiler + - "\n\n*Issue found:*\n" + issueFound + "\n\n***Issue found:***\n" + + issueFound // uriImage + // ")\n" ); - sendMessToZulip( - "stream", - "AUS_VN_Test", - "Test Log Alerts", - "------------\n\n:warning: :warning: **" + - fileName + - "**\n\n" + - content + - "\n\n" + - spoiler + - "\n\n*Issue found:*\n" + issueFound - ); + // sendMessToZulip( + // "stream", + // "AUS_VN_Test", + // "Test Log Alerts", + // "------------\n\n:warning: :warning: **" + + // fileName + + // "**\n\n" + + // content + + // "\n\n" + + // spoiler + + // "\n\n*Issue found:*\n" + issueFound + // ); // }, 10000); // }, 3000); diff --git a/app/utils/screenShot.ts b/app/utils/screenShot.ts index f9c9b80..cc0a212 100644 --- a/app/utils/screenShot.ts +++ b/app/utils/screenShot.ts @@ -6,6 +6,7 @@ export const screenShot = async (filename, time) => { args: ["--no-sandbox"], }); + try { // Open a new page const page = await browser.newPage(); diff --git a/manage-view/public/favicon.ico b/manage-view/public/favicon.ico index a11777c..b636d9a 100644 Binary files a/manage-view/public/favicon.ico and b/manage-view/public/favicon.ico differ diff --git a/manage-view/public/index.html b/manage-view/public/index.html index aa069f2..b6a27e0 100644 --- a/manage-view/public/index.html +++ b/manage-view/public/index.html @@ -24,7 +24,7 @@ work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> - React App + Log View diff --git a/screenshot.js b/screenshot.js index a773459..6397d4b 100644 --- a/screenshot.js +++ b/screenshot.js @@ -26,48 +26,63 @@ // // Close the browser // })(); -const zulip = require("zulip-js"); +// const zulip = require("zulip-js"); -const config = { - zuliprc: "./zuliprc", - zulipVersion: "v2", -}; +// const config = { +// zuliprc: "./download", +// zulipVersion: "v2", +// }; -async function deleteMessages() { - const client = await zulip(config); +// async function deleteMessages() { +// const client = await zulip(config); - // Thay thế "stream-name", "topic-name", và các mốc thời gian cụ thể - const streamName = "Result test - auto.nswteam.net"; - const topicName = "AU-dev"; - const startTime = Date.parse("2023-09-11T00:00:00Z"); - const endTime = Date.parse("2023-09-11T23:59:59Z"); +// // Thay thế "stream-name", "topic-name", và các mốc thời gian cụ thể +// const streamName = "Result test - auto.nswteam.net"; +// const topicName = "test"; - try { - const messages = await client.messages.retrieve({ - anchor: "oldest", - num_before: 0, - num_after: 3, // Điều chỉnh theo nhu cầu của bạn - narrow: [ - { operator: "stream", operand: streamName }, - { operator: "topic", operand: topicName }, - // { - // operator: , - // operand: `169457100,1694571399`, - // }, - ], - }); - console.log(messages.messages.map(obj=>obj.reactions)) - // for (const message of messages.messages) { - // const res = await client.messages.deleteById({ message_id: message.id }); - // console.log(`Deleted message ID ${message.id}`); - // console.log(res) - // } - } catch (error) { - console.error("Error:", error); - } -} +// try { +// const messages = await client.messages.retrieve({ +// anchor: "oldest", +// num_before: 0, +// num_after: 5000, // Điều chỉnh theo nhu cầu của bạn +// narrow: [ +// { operator: "stream", operand: streamName }, +// { operator: "topic", operand: topicName }, +// // { +// // operator: , +// // operand: `169457100,1694571399`, +// // }, +// ], +// }); +// // console.log(messages.messages.map(u=>u.reactions)) +// const members = await client.users.retrieve(); +// // console.log(members.members) +// console.log(messages.messages.length) +// // await client.messages.deleteById([159454, 159455]); +// for (const message of messages.messages) { +// console.log(message.id) +// if ( +// message.reactions.filter( +// (i) => +// i.emoji_name === "working_on_it" && +// members.members.filter((u) => u.user_id === i.user_id)[0] +// .is_admin === true +// ).length === 0 && +// message.timestamp < Math.floor((Date.now() - 60000*60*24*10) / 1000) +// ) { +// const res = await client.messages.deleteById({ +// message_id: message.id, +// }); +// console.log(`Deleted message ID ${message.id}`); +// console.log(res) +// } +// } +// } catch (error) { +// console.error("Error:", error); +// } +// } -deleteMessages(); +// deleteMessages(); // const zulip = require("zulip-js"); // const fs = require("fs"); @@ -145,3 +160,20 @@ deleteMessages(); // const filePath = 'screenshot.png'; // Replace with your file path // uploadFileToZulip(filePath); + + +// const puppeteer = require("puppeteer"); + +// (async () => { +// const browser = await puppeteer.launch(); +// // Store the endpoint to be able to reconnect to the browser. +// const browserWSEndpoint = browser.wsEndpoint("https://pptr.dev/api/puppeteer.browser"); +// // Disconnect puppeteer from the browser. +// browser.disconnect(); + +// // Use the endpoint to reestablish a connection +// const browser2 = await puppeteer.connect({browserWSEndpoint}); +// // Close the browser. +// await browser2.close(); +// })(); +