Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
aliazmoodehvaldi committed Oct 29, 2022
1 parent 5d17a51 commit 9930acc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wfl",
"version": "1.0.2",
"version": "1.0.3",
"description": "Log Management System",
"main": "index.js",
"scripts": {
Expand Down
26 changes: 9 additions & 17 deletions src/util/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ let isRelease = wflType === 'release';

function getMaximumTimeForDeleteOldFiles(offset) {
let twoHours = 7200;
return (typeof offset === 'string') ? ms(offset) : twoHours;
return typeof offset === 'string' ? ms(offset) : twoHours;
}

function getMaximumSizeForWriteFile() {
let MaxFileSize = 26214400;
return (typeof size === 'string') ? Util.sizeToByte(size) : MaxFileSize;
return typeof size === 'string' ? Util.sizeToByte(size) : MaxFileSize;
}


Expand Down Expand Up @@ -97,16 +97,8 @@ function getMessageInJsonObject(type, message) {


function mkRootDir() {
if (pathDir !== undefined && !fs.existsSync(pathDir)) {
if (pathDir && !isExistFile(pathDir) || !isExistFile(slash + 'log'))
return mkAllDirsFromList();
}

if (pathDir !== undefined && fs.existsSync(pathDir))
return;

pathDir = slash + 'log';
if (!fs.existsSync(pathDir))
mkAllDirsFromList();
}

function mkIgnoreFileInUserRootProject(fileName) {
Expand Down Expand Up @@ -163,7 +155,7 @@ function getFileName(path) {
} catch (e) {

}
return (fileNameInDisk === undefined) ? Util.getRandomFileName() : fileNameInDisk.toString();
return !fileNameInDisk ? Util.getRandomFileName() : fileNameInDisk.toString();
}

function fileHandlerFoEachDir(type, message) {
Expand Down Expand Up @@ -200,9 +192,9 @@ function DeleteFileAfterSpecifiedPeriod() {
files.forEach(file => {
fs.stat(realPath + file, (err, stat) => {
let endTime, now;
if (err) {
if (err)
return;
}

now = new Date().getTime();
endTime = new Date(stat.ctime).getTime() + ms(where[key]);
if (now > endTime) {
Expand All @@ -228,9 +220,9 @@ function DeleteFileAfterSpecifiedPeriod() {
files.forEach(file => {
fs.stat(realPath + file, (err, stat) => {
let endTime, now;
if (err) {
if (err)
return;
}

now = new Date().getTime();
endTime = new Date(stat.ctime).getTime() + getMaximumTimeForDeleteOldFiles();
if (now > endTime) {
Expand All @@ -252,7 +244,7 @@ module.exports = {
if (isRelease) {
mkRootDir();
fileIgnoreHandler();
if (accessToDelete || accessToDelete === undefined)
if (accessToDelete === true)
DeleteFileAfterSpecifiedPeriod();
}
},
Expand Down

0 comments on commit 9930acc

Please sign in to comment.