private log

This commit is contained in:
joseph le 2023-10-31 13:33:05 +07:00
parent 865f65decd
commit 5c30c5aa89
1 changed files with 36 additions and 0 deletions

View File

@ -1,3 +1,4 @@
import { fs } from 'fs';
import axios from "axios";
/*
|--------------------------------------------------------------------------
@ -300,6 +301,41 @@ Route.post("/api/sendMailInforDevice", async () => {
"writeLog"
);
Route.post("/private-log/getFileOnFolder", async ({ request, response }) => {
try {
let result = [];
let path = request.all().folerPath;
return new Promise((resolve, reject) => {
fs.readdir(path, (err, entries) => {
if (err) {
reject(err);
return;
}
entries.forEach((entry) => {
const entryPath = path+"/"+entry;
fs.stat(entryPath, (statErr, stats) => {
if (statErr) {
reject(statErr);
return;
}
const type = stats.isFile() ? "file" : "directory";
result.push({ name: entryPath, type: type });
if (result.length === entries.length) {
resolve(result);
}
});
});
});
});
} catch (error) {
console.log(error);
}
})
Route.post("/api/test", async () => {
try {
const logs = await Cache.get('logs')