UnknownSec Bypass
403
:
/
var
/
www
/
stp-bhaktisagar-backend
/
src
/
util
/ [
drwxrwxr-x
]
Menu
Upload
Mass depes
Mass delete
Terminal
Info server
About
name :
app.util.js
const fs = require("fs"); const path = require("path"); let converter = require("json-2-csv"); const Excel = require("exceljs"); function bufferToStream(buffer) { let stream = new Duplex(); stream.push(buffer); stream.push(null); return stream; } exports.sleep = (delay = 1000) => { return new Promise((res, rej) => { setTimeout(() => { res(); }, delay); }); }; exports.writeJsonFile = (filename, data) => { let filePath = path.resolve("build", `${filename}.json`); ////json file //////// fs.writeFileSync(filePath, JSON.stringify(data)); ////////// }; exports.writeCSVFile = async (filename, data) => { let csvfilePath = path.resolve("build", `${filename}.csv`); const csv = await converter.json2csv(data); fs.writeFileSync(csvfilePath, csv); }; exports.getRndInteger = (min, max) => { return Math.floor(Math.random() * (max - min + 1)) + min; }; exports.csvToJson = (filePath) => { return new Promise(async (res, rej) => { let pathData = path.parse(filePath); const workbook = new Excel.Workbook(); const reader = fs.createReadStream(filePath); console.log("file reading...", filePath); const worksheet = await workbook.csv.read(reader); let header = []; let data = []; worksheet.eachRow(function (row, rowNumber) { // console.log(row.values); if (rowNumber == 1) { row.eachCell(function (cell, colNumber) { header = [...header, cell.value]; // console.log('Cell ' + colNumber + ' = ' + cell.value); }); } else { let item = {}; row.eachCell(function (cell, colNumber) { // console.log(colNumber,header[colNumber - 1]) item = { ...item, [header[colNumber - 1]]: cell.value }; // console.log('Cell ' + colNumber ); }); data.push(item); } }); console.log("csvToJson Success", header); res(data); }); }; exports.trimDirFiles = (no = 10) => { let dirPath = path.resolve("bkp"); fs.readdir(dirPath, (err, files) => { let filterFiles = files .map((file) => { let filePath = path.resolve("bkp", file); let stat = fs.statSync(filePath); return { filePath, file, ctime: stat.ctime }; }) .sort((a, b) => { return b.ctime.getTime() - a.ctime.getTime(); }) .slice(no); filterFiles.forEach((r) => { fs.unlink(r.filePath, () => {}); }); }); }; /////get columns //Array.from( $0.children).map(o=>o.innerText).join('=?,') // Object.keys({ // }).map(p=>`data['${p}']`).join()
Copyright © 2025 - UnknownSec