diff --git a/modules/api/api.js b/modules/api/api.js index 3e6e484..c4692b3 100644 --- a/modules/api/api.js +++ b/modules/api/api.js @@ -47,7 +47,7 @@ const usersDbBackupPath = 'data/dbs/backup' const maxVeteranPwGetCount = 10 const addPWPerDay = 1 // every x day a user can give a pw -const maxPWCount = 4 // maximum pw give opportunities a user can have at once +const maxPWCount = 6 // maximum pw give opportunities a user can have at once const daysAfterUserGetsPWs = 2 // days after user gets pw-s let userDB @@ -144,7 +144,7 @@ function GetApp () { created: utils.GetDateString() }) - logger.Log(`User #${requestingUser.id} creted new user #${insertRes.lastInsertRowid}`, logger.GetColor('cyan')) + logger.Log(`User #${requestingUser.id} created new user #${insertRes.lastInsertRowid}`, logger.GetColor('cyan')) res.json({ result: 'success', @@ -590,6 +590,7 @@ function GetApp () { function IncrementAvaiblePWs () { // FIXME: check this if this is legit and works + logger.Log('Incrementing avaible PW-s ...') const users = dbtools.SelectAll(userDB, 'users') const today = new Date() const getDayDiff = (dateString) => { @@ -619,14 +620,14 @@ function GetApp () { }) } - function DailyActions () { + function DailyAction () { ExportDailyDataCount() BackupDB() IncrementAvaiblePWs() } return { - DailyActions: DailyActions, + dailyAction: DailyAction, app: app } } diff --git a/server.js b/server.js index 344a583..7a77706 100755 --- a/server.js +++ b/server.js @@ -17,7 +17,7 @@ along with this program. If not, see . ------------------------------------------------------------------------- */ -console.clear() +process.stdout.write('\u001b[2J\u001b[0;0H') // console.clear() const startHTTPS = true const isRoot = process.getuid && process.getuid() === 0 @@ -125,7 +125,7 @@ Object.keys(modules).forEach(function (k, i) { const modApp = mod.getApp() x.app = modApp.app - x.dailyAction = modApp.DailyAction + x.dailyAction = modApp.dailyAction x.cleanup = modApp.cleanup x.urls.forEach((url) => { @@ -169,10 +169,20 @@ function setLogTimer () { const night = new Date( now.getFullYear(), now.getMonth(), - now.getDate() + 1, // the next day, ... - 0, 0, 0 // ...at 00:00:00 hours + now.getDate() + 1, + 0, + 0, + 0 ) + logger.DebugLog(`Next daily action: ${night}`, 'daily', 1) const msToMidnight = night.getTime() - now.getTime() + logger.DebugLog(`msToMidnight: ${msToMidnight}`, 'daily', 1) + logger.DebugLog(`Seconds To Midnight: ${msToMidnight / 1000}`, 'daily', 1) + + if (msToMidnight < 0) { + logger.Log(`Error setting up Log Timer, msToMidnight is negative! (${msToMidnight})`, logger.GetColor('redbg')) + return + } setTimeout(function () { LogTimerAction() @@ -181,10 +191,13 @@ function setLogTimer () { } function LogTimerAction () { + logger.DebugLog(`Running Log Timer Action`, 'daily', 1) Object.keys(modules).forEach((k, i) => { const x = modules[k] + logger.DebugLog(`Ckecking ${k}`, 'daily', 1) if (x.dailyAction) { try { + logger.Log(`Running daily action of ${k}`) x.dailyAction() } catch (e) { logger.Log(`Error in ${k} daily action! Details in STDERR`, logger.GetColor('redbg'))