147 lines
4.3 KiB
JavaScript
147 lines
4.3 KiB
JavaScript
// const puppeteer = require("puppeteer");
|
|
|
|
// (async () => {
|
|
// // Launch a headless browser
|
|
// const browser = await puppeteer.launch();
|
|
|
|
// // Open a new page
|
|
// const page = await browser.newPage();
|
|
// await page.goto(
|
|
// "http://localhost:3000/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 = "Log Alert";
|
|
// const startTime = Date.parse("2023-09-11T00:00:00Z");
|
|
// const endTime = Date.parse("2023-09-11T23:59:59Z");
|
|
|
|
// 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.length)
|
|
// // 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);
|
|
// }
|
|
// }
|
|
|
|
// 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);
|