create function sendDeviceInfor to mail

This commit is contained in:
joseph le 2023-10-09 16:13:23 +07:00
parent 1aa8acc161
commit f941cc615b
1 changed files with 38 additions and 24 deletions

View File

@ -1,4 +1,4 @@
import Env from '@ioc:Adonis/Core/Env';
import Env from "@ioc:Adonis/Core/Env";
import fs from "fs";
import moment from "moment/moment";
import dotenv from "dotenv";
@ -17,7 +17,7 @@ export const sendDeviceInfora = async () => {
let html = "";
//List file today
const listFile = fs
.readdirSync(Env.get('FOLDER_LOGS'))
.readdirSync(Env.get("FOLDER_LOGS"))
.filter((f) => f.includes("TEST01"));
//Configure mail
@ -34,7 +34,7 @@ export const sendDeviceInfora = async () => {
//Read file in listFile
await listFile.map((file) => {
fs.readFile(Env.get('FOLDER_LOGS') + "/" + file, "utf8", (err, data) => {
fs.readFile(Env.get("FOLDER_LOGS") + "/" + file, "utf8", (err, data) => {
if (err) {
console.log(`Error reading file: ${err}`);
} else {
@ -123,16 +123,23 @@ export const sendDeviceInfora = async () => {
if (index > 0) {
if (PID !== "" && SN !== "") {
let RAM =
(
parseInt(
showVersion
.filter((line) => line.includes("bytes of memory"))
.join("<br>")
.match(regexMemory)[0]
) /
1024 /
1024
).toFixed(2) + "G";
showVersion
.filter((line) => line.includes("bytes of memory"))
.join("<br>")
.match(regexMemory) !== null
? (
parseInt(
showVersion
.filter((line) =>
line.includes("bytes of memory")
)
.join("<br>")
.match(regexMemory)[0]
) /
1024 /
1024
).toFixed(2) + "G"
: "";
let flash = showVersion
.filter((line) =>
@ -173,16 +180,23 @@ export const sendDeviceInfora = async () => {
} else {
if (PID !== "" && SN !== "") {
let RAM =
(
parseInt(
showVersion
.filter((line) => line.includes("bytes of memory"))
.join("<br>")
.match(regexMemory)[0]
) /
1024 /
1024
).toFixed(2) + "G";
showVersion
.filter((line) => line.includes("bytes of memory"))
.join("<br>")
.match(regexMemory) !== null
? (
parseInt(
showVersion
.filter((line) =>
line.includes("bytes of memory")
)
.join("<br>")
.match(regexMemory)[0]
) /
1024 /
1024
).toFixed(2) + "G"
: "";
let flash = showVersion
.filter((line) =>
@ -312,4 +326,4 @@ export const sendDeviceInfora = async () => {
} catch (error) {
console.log(error);
}
}
};