update format message, update favion icon and title
This commit is contained in:
		
							parent
							
								
									425ca91172
								
							
						
					
					
						commit
						382b74ad83
					
				| 
						 | 
					@ -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
 | 
				
			||||||
| 
						 | 
					@ -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);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -7,8 +7,6 @@ import KeyValue from "App/Models/KeyValue";
 | 
				
			||||||
import Database from "@ioc:Adonis/Lucid/Database";
 | 
					import Database from "@ioc:Adonis/Lucid/Database";
 | 
				
			||||||
import { sendMessToZulip } from "./sendMessToZulip";
 | 
					import { sendMessToZulip } from "./sendMessToZulip";
 | 
				
			||||||
import { getListLineByItem } from "./getListLineByItem";
 | 
					import { getListLineByItem } from "./getListLineByItem";
 | 
				
			||||||
import { screenShot } from "./screenShot";
 | 
					 | 
				
			||||||
import { uploadFileToZulip } from "./uploadFileZulip";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// export default class loggerAPI {
 | 
					// export default class loggerAPI {
 | 
				
			||||||
export async function runtimeCheckLogs(folderPath) {
 | 
					export async function runtimeCheckLogs(folderPath) {
 | 
				
			||||||
| 
						 | 
					@ -45,9 +43,11 @@ export async function runtimeCheckLogs(folderPath) {
 | 
				
			||||||
      //import log new file
 | 
					      //import log new file
 | 
				
			||||||
      // console.log(filePath)
 | 
					      // console.log(filePath)
 | 
				
			||||||
      if (
 | 
					      if (
 | 
				
			||||||
        //Sua \\ --> /
 | 
					        
 | 
				
			||||||
        filePath?.split(".")[filePath.split(".").length - 1] === "log" &&
 | 
					        filePath?.split(".")[filePath.split(".").length - 1] === "log" &&
 | 
				
			||||||
        filePath.split("/")[filePath.split("/").length - 1]?.split("-")[0] ===
 | 
					        filePath.split("/")[filePath.split("/").length - 1]?.split("-")[0] ===
 | 
				
			||||||
 | 
					         //localhost 
 | 
				
			||||||
 | 
					         // filePath.split("\\")[filePath.split("\\").length - 1]?.split("-")[0] ===
 | 
				
			||||||
          moment(Date.now()).format("YYYYMMDD").toString()
 | 
					          moment(Date.now()).format("YYYYMMDD").toString()
 | 
				
			||||||
      ) {
 | 
					      ) {
 | 
				
			||||||
        console.log("New file added: ", filePath);
 | 
					        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] },
 | 
				
			||||||
          { file_name: filePath.split("/")[filePath.split("/").length - 1] }
 | 
					          { file_name: filePath.split("/")[filePath.split("/").length - 1] }
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					        //localhost
 | 
				
			||||||
        // await LogDetectFile.firstOrCreate(
 | 
					        // await LogDetectFile.firstOrCreate(
 | 
				
			||||||
        //   { file_name: filePath.split("\\")[filePath.split("\\").length - 1] },
 | 
					        //   { file_name: filePath.split("\\")[filePath.split("\\").length - 1] },
 | 
				
			||||||
        //   { file_name: filePath.split("\\")[filePath.split("\\").length - 1] }
 | 
					        //   { file_name: filePath.split("\\")[filePath.split("\\").length - 1] }
 | 
				
			||||||
| 
						 | 
					@ -192,14 +193,23 @@ export async function runtimeCheckLogs(folderPath) {
 | 
				
			||||||
                      ? ":medal: **" + log.detected_content + "**"
 | 
					                      ? ":medal: **" + log.detected_content + "**"
 | 
				
			||||||
                      : ":small_orange_diamond: " + log.detected_content;
 | 
					                      : ":small_orange_diamond: " + log.detected_content;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    log.line?.map((line)=>{
 | 
					                    log.line?.map((line) => {
 | 
				
			||||||
                      issueFound =
 | 
					                      issueFound =
 | 
				
			||||||
                      issueFound +
 | 
					                        issueFound +
 | 
				
			||||||
                      "\n" +
 | 
					                        "\n`" +
 | 
				
			||||||
                      line +
 | 
					                        line +
 | 
				
			||||||
                      "$" +
 | 
					                        "` " +
 | 
				
			||||||
                      contentFile[line-1]?.replace(log.detected_content, "`" + log.detected_content + "`")
 | 
					                        contentFile[line - 1]?.replace(
 | 
				
			||||||
                    })
 | 
					                          log.detected_content,
 | 
				
			||||||
 | 
					                          "[" +
 | 
				
			||||||
 | 
					                            log.detected_content +
 | 
				
			||||||
 | 
					                            "](https://logs.danielvu.com/logs/" +
 | 
				
			||||||
 | 
					                            fileName +
 | 
				
			||||||
 | 
					                            "#" +
 | 
				
			||||||
 | 
					                            line +
 | 
				
			||||||
 | 
					                            ")"
 | 
				
			||||||
 | 
					                        );
 | 
				
			||||||
 | 
					                    });
 | 
				
			||||||
                    content =
 | 
					                    content =
 | 
				
			||||||
                      content +
 | 
					                      content +
 | 
				
			||||||
                      "|" +
 | 
					                      "|" +
 | 
				
			||||||
| 
						 | 
					@ -228,23 +238,24 @@ export async function runtimeCheckLogs(folderPath) {
 | 
				
			||||||
                      content +
 | 
					                      content +
 | 
				
			||||||
                      "\n\n" +
 | 
					                      "\n\n" +
 | 
				
			||||||
                      spoiler +
 | 
					                      spoiler +
 | 
				
			||||||
                      "\n\n*Issue found:*\n" + issueFound
 | 
					                      "\n\n***Issue found:***\n" +
 | 
				
			||||||
 | 
					                      issueFound
 | 
				
			||||||
                    // uriImage +
 | 
					                    // uriImage +
 | 
				
			||||||
                    // ")\n"
 | 
					                    // ")\n"
 | 
				
			||||||
                  );
 | 
					                  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                  sendMessToZulip(
 | 
					                  // sendMessToZulip(
 | 
				
			||||||
                    "stream",
 | 
					                  //   "stream",
 | 
				
			||||||
                    "AUS_VN_Test",
 | 
					                  //   "AUS_VN_Test",
 | 
				
			||||||
                    "Test Log Alerts",
 | 
					                  //   "Test Log Alerts",
 | 
				
			||||||
                    "------------\n\n:warning: :warning: **" +
 | 
					                  //   "------------\n\n:warning: :warning: **" +
 | 
				
			||||||
                      fileName +
 | 
					                  //     fileName +
 | 
				
			||||||
                      "**\n\n" +
 | 
					                  //     "**\n\n" +
 | 
				
			||||||
                      content +
 | 
					                  //     content +
 | 
				
			||||||
                      "\n\n" +
 | 
					                  //     "\n\n" +
 | 
				
			||||||
                      spoiler +
 | 
					                  //     spoiler +
 | 
				
			||||||
                      "\n\n*Issue found:*\n" + issueFound
 | 
					                  //     "\n\n*Issue found:*\n" + issueFound
 | 
				
			||||||
                  );
 | 
					                  // );
 | 
				
			||||||
                  // }, 10000);
 | 
					                  // }, 10000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                  // }, 3000);
 | 
					                  // }, 3000);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,6 +6,7 @@ export const screenShot = async (filename, time) => {
 | 
				
			||||||
    args: ["--no-sandbox"],
 | 
					    args: ["--no-sandbox"],
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
  try {
 | 
					  try {
 | 
				
			||||||
    // Open a new page
 | 
					    // Open a new page
 | 
				
			||||||
    const page = await browser.newPage();
 | 
					    const page = await browser.newPage();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 15 KiB  | 
| 
						 | 
					@ -24,7 +24,7 @@
 | 
				
			||||||
      work correctly both with client-side routing and a non-root public URL.
 | 
					      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`.
 | 
					      Learn how to configure a non-root public URL by running `npm run build`.
 | 
				
			||||||
    -->
 | 
					    -->
 | 
				
			||||||
    <title>React App</title>
 | 
					    <title>Log View</title>
 | 
				
			||||||
  </head>
 | 
					  </head>
 | 
				
			||||||
  <body>
 | 
					  <body>
 | 
				
			||||||
    <noscript>You need to enable JavaScript to run this app.</noscript>
 | 
					    <noscript>You need to enable JavaScript to run this app.</noscript>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										106
									
								
								screenshot.js
								
								
								
								
							
							
						
						
									
										106
									
								
								screenshot.js
								
								
								
								
							| 
						 | 
					@ -26,48 +26,63 @@
 | 
				
			||||||
//   // Close the browser
 | 
					//   // Close the browser
 | 
				
			||||||
// })();
 | 
					// })();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const zulip = require("zulip-js");
 | 
					// const zulip = require("zulip-js");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const config = {
 | 
					// const config = {
 | 
				
			||||||
  zuliprc: "./zuliprc",
 | 
					//   zuliprc: "./download",
 | 
				
			||||||
  zulipVersion: "v2",
 | 
					//   zulipVersion: "v2",
 | 
				
			||||||
};
 | 
					// };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function deleteMessages() {
 | 
					// async function deleteMessages() {
 | 
				
			||||||
  const client = await zulip(config);
 | 
					//   const client = await zulip(config);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Thay thế "stream-name", "topic-name", và các mốc thời gian cụ thể
 | 
					//   // Thay thế "stream-name", "topic-name", và các mốc thời gian cụ thể
 | 
				
			||||||
  const streamName = "Result test - auto.nswteam.net";
 | 
					//   const streamName = "Result test - auto.nswteam.net";
 | 
				
			||||||
  const topicName = "AU-dev";
 | 
					//   const topicName = "test";
 | 
				
			||||||
  const startTime = Date.parse("2023-09-11T00:00:00Z");
 | 
					 | 
				
			||||||
  const endTime = Date.parse("2023-09-11T23:59:59Z");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  try {
 | 
					//   try {
 | 
				
			||||||
    const messages = await client.messages.retrieve({
 | 
					//     const messages = await client.messages.retrieve({
 | 
				
			||||||
      anchor: "oldest",
 | 
					//       anchor: "oldest",
 | 
				
			||||||
      num_before: 0,
 | 
					//       num_before: 0,
 | 
				
			||||||
      num_after: 3, // Điều chỉnh theo nhu cầu của bạn
 | 
					//       num_after: 5000, // Điều chỉnh theo nhu cầu của bạn
 | 
				
			||||||
      narrow: [
 | 
					//       narrow: [
 | 
				
			||||||
        { operator: "stream", operand: streamName },
 | 
					//         { operator: "stream", operand: streamName },
 | 
				
			||||||
        { operator: "topic", operand: topicName },
 | 
					//         { operator: "topic", operand: topicName },
 | 
				
			||||||
        // {
 | 
					//         // {
 | 
				
			||||||
        //   operator: ,
 | 
					//         //   operator: ,
 | 
				
			||||||
        //   operand: `169457100,1694571399`,
 | 
					//         //   operand: `169457100,1694571399`,
 | 
				
			||||||
        // },
 | 
					//         // },
 | 
				
			||||||
      ],
 | 
					//       ],
 | 
				
			||||||
    });
 | 
					//     });
 | 
				
			||||||
    console.log(messages.messages.map(obj=>obj.reactions))
 | 
					//     // console.log(messages.messages.map(u=>u.reactions))
 | 
				
			||||||
    // for (const message of messages.messages) {
 | 
					//     const members = await client.users.retrieve();
 | 
				
			||||||
    //   const res = await client.messages.deleteById({ message_id: message.id });
 | 
					//     // console.log(members.members)
 | 
				
			||||||
    //   console.log(`Deleted message ID ${message.id}`);
 | 
					//     console.log(messages.messages.length)
 | 
				
			||||||
    //   console.log(res)
 | 
					//     // await client.messages.deleteById([159454, 159455]);
 | 
				
			||||||
    // }
 | 
					//     for (const message of messages.messages) {
 | 
				
			||||||
  } catch (error) {
 | 
					//       console.log(message.id)
 | 
				
			||||||
    console.error("Error:", error);
 | 
					//       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 zulip = require("zulip-js");
 | 
				
			||||||
// const fs = require("fs");
 | 
					// const fs = require("fs");
 | 
				
			||||||
| 
						 | 
					@ -145,3 +160,20 @@ deleteMessages();
 | 
				
			||||||
// const filePath = 'screenshot.png'; // Replace with your file path
 | 
					// const filePath = 'screenshot.png'; // Replace with your file path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// uploadFileToZulip(filePath);
 | 
					// 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();
 | 
				
			||||||
 | 
					// })();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue