mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
68 lines
1.6 KiB
JavaScript
68 lines
1.6 KiB
JavaScript
module.exports = {
|
|
ReadFile: ReadFile,
|
|
WriteFile: WriteFile,
|
|
writeFileAsync: WriteFileAsync,
|
|
AppendToFile: AppendToFile,
|
|
Beep: Beep,
|
|
WriteBackup: WriteBackup
|
|
};
|
|
|
|
var fs = require('fs');
|
|
|
|
var logger = require('./logger.js');
|
|
|
|
const recievedFile = "stats/recieved";
|
|
const staticFile = "public/data/static";
|
|
const manFile = "public/man.html";
|
|
const logFile = "stats/logs";
|
|
const dataFile = "public/data.json";
|
|
|
|
function ReadFile(name) {
|
|
return fs.readFileSync(name, "utf8");
|
|
}
|
|
|
|
function WriteFile(content, path) {
|
|
fs.writeFileSync(path, content);
|
|
}
|
|
|
|
function WriteFileAsync(content, path) {
|
|
fs.writeFile(path, content, function(err) {
|
|
if (err) {
|
|
logger.Log("[ERR ]: Error writing file: " + path + " (sync)", logger.GetColor("redbg"));
|
|
}
|
|
});
|
|
}
|
|
|
|
function AppendToFile(data, file) {
|
|
fs.appendFile(file, "\n" + data, function(err) {
|
|
if (err)
|
|
logger.Log("[ERR ]: Error writing log file: " + file + " (sync)", logger.GetColor("redbg"));
|
|
});
|
|
}
|
|
|
|
function Beep() {
|
|
try {
|
|
process.stdout.write('\x07');
|
|
} catch (e) {
|
|
console.log("error beepin");
|
|
}
|
|
}
|
|
|
|
function WriteBackup() {
|
|
try {
|
|
WriteFileAsync(ReadFile(recievedFile), 'public/backs/recieved_' + new Date().toString());
|
|
//logger.Log('[SAVE]: New questions backup wrote');
|
|
|
|
} catch (e) {
|
|
logger.Log("[ERR ]: Error backing up recieved file!", logger.GetColor("redbg"));
|
|
console.log(e);
|
|
}
|
|
|
|
try {
|
|
WriteFileAsync(ReadFile(dataFile), 'public/backs/data_' + new Date().toString());
|
|
|
|
} catch (e) {
|
|
logger.Log("[ERR ]: Error backing up data json file!", logger.GetColor("redbg"));
|
|
console.log(e);
|
|
}
|
|
}
|