Log_service/screenshot.js

180 lines
5.4 KiB
JavaScript

// const puppeteer = require("puppeteer");
// (async () => {
// // Launch a headless browser
// const browser = await puppeteer.launch({
// headless: true,
// args: ["--no-sandbox"],
// });
// // Open a new page
// const page = await browser.newPage();
// await page.goto(
// "https://logs.danielvu.com/screenShot/20230913-TEST01-Session.Port4-6-172.16.20.7.log"
// );
// const bodyHandle = await page.$("body");
// const { height } = await bodyHandle.boundingBox();
// await bodyHandle.dispose();
// await page.setViewport({ width: 1920, height: 500 });
// setTimeout(async () => {
// await page.screenshot({ path: "screenshot.png" });
// await browser.close();
// }, 5000);
// // } else {
// // console.error(`Element with class name '${className}' not found.`);
// // }
// // Close the browser
// })();
// const zulip = require("zulip-js");
// const config = {
// zuliprc: "./download",
// zulipVersion: "v2",
// };
// 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 = "test";
// 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();
// const zulip = require("zulip-js");
// const fs = require("fs");
// const config = {
// zuliprc: "./download",
// zulipVersion: "v2", // Use the appropriate API version
// };
// const imageFilePath = "./screenshot.png";
// const imageBase64 = fs.readFileSync(imageFilePath, { encoding: "base64" });
// async function send() {
// const client = await zulip(config);
// try {
// const message = {
// type: "stream",
// to: "Result test - auto.nswteam.net", // Replace with the target stream name or recipient email
// topic: "AU-dev", // Replace with the message topic
// content: "Check out this image:",
// filename: "asakfga",
// file: imageBase64
// };
// client.messages.sendFile(message).then((response) => {
// console.log("Message sent successfully:", response);
// });
// } catch (error) {
// console.error("Error:", error);
// }
// }
// send();
// Usage example
// const filePath = __dirname+'\\screenshot.png';
// uploadFileToZulip(filePath);
// const zulip = require('zulip-js');
// // Configure your Zulip API details
// const config = {
// username: 'joseph.le@apactech.io',
// apiKey: '7XGrpwzFtQyUVDQzdwL3hjdVSbLx55yt',
// realm: 'https://zulip.ipsupply.com.au',
// };
// async function uploadFileToZulip(filePath) {
// try {
// const client = await zulip(config);
// // Read the file as binary data
// const fs = require('fs');
// const fileData = fs.readFileSync(filePath);
// // Create a FormData object
// const formData = new FormData();
// formData.append('file', fileData);
// // Upload the file
// const response = await client.callEndpoint('POST', 'user_uploads', formData, {headers:{
// 'Content-Type': 'multipart/form-data',
// // other headers if needed
// }});
// // if (response.result === 'success') {
// // const uploadedFileURL = response.uri;
// // console.log('File uploaded successfully. URL:', uploadedFileURL);
// // } else {
// // console.error('Failed to upload file:', response.msg);
// // }
// } catch (error) {
// console.error('Error uploading file:', error);
// }
// }
// 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();
// })();