mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Possible answers penalty fixes, logging imporvements, added tests
This commit is contained in:
parent
39cb92308d
commit
f5ad460e24
8 changed files with 396 additions and 48 deletions
|
@ -52,7 +52,7 @@ let uvData = {} // visit data, but per user
|
|||
let udvData = {} // visit data, but per user and daily
|
||||
let writes = 0
|
||||
|
||||
let noLogips: string[] = []
|
||||
let noLogIds: string[] = []
|
||||
|
||||
function getColoredDateString(): string {
|
||||
const date = new Date()
|
||||
|
@ -86,7 +86,9 @@ function Log(msg: string | object, color?: string): void {
|
|||
log = getColoredDateString() + delimiter + C(color) + msg + C()
|
||||
}
|
||||
|
||||
console.log(log)
|
||||
if (!process.env.NS_NOLOG) {
|
||||
console.log(log)
|
||||
}
|
||||
utils.AppendToFile(
|
||||
typeof log === 'string' ? log : JSON.stringify(log),
|
||||
logDir + logFileName
|
||||
|
@ -160,20 +162,20 @@ function LogReq(
|
|||
utils.AppendToFile(defLogs, vlogDir + logFileName)
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
console.error(err)
|
||||
Log('Error at logging lol', GetColor('redbg'))
|
||||
}
|
||||
}
|
||||
|
||||
function parseNoLogFile(newData: string) {
|
||||
noLogips = newData.split('\n')
|
||||
if (noLogips[noLogips.length - 1] === '') {
|
||||
noLogips.pop()
|
||||
noLogIds = newData.split('\n')
|
||||
if (noLogIds[noLogIds.length - 1] === '') {
|
||||
noLogIds.pop()
|
||||
}
|
||||
noLogips = noLogips.filter((noLogip) => {
|
||||
return noLogip !== ''
|
||||
noLogIds = noLogIds.filter((noLogId) => {
|
||||
return noLogId !== ''
|
||||
})
|
||||
Log('\tNo Log IP-s changed: ' + noLogips.join(', '))
|
||||
Log('\tNo Log user ID-s changed: ' + noLogIds.join(', '))
|
||||
}
|
||||
|
||||
function setNoLogReadInterval() {
|
||||
|
@ -219,16 +221,23 @@ function Load(): void {
|
|||
setNoLogReadInterval()
|
||||
}
|
||||
|
||||
function LogStat(url: string, hostname: string, userId: number): void {
|
||||
function LogStat(url: string, hostname: string, userId: number | string): void {
|
||||
const nolog = noLogIds.some((noLogId) => {
|
||||
return noLogId === userId.toString()
|
||||
})
|
||||
if (nolog) {
|
||||
return
|
||||
}
|
||||
|
||||
url = hostname + url.split('?')[0]
|
||||
Inc(url)
|
||||
AddUserIdStat(userId)
|
||||
IncUserStat(userId)
|
||||
AddUserIdStat(userId.toString())
|
||||
IncUserStat(userId.toString())
|
||||
AddVisitStat(url)
|
||||
Save()
|
||||
}
|
||||
|
||||
function IncUserStat(userId: number) {
|
||||
function IncUserStat(userId: string) {
|
||||
try {
|
||||
if (uvData[userId] === undefined) {
|
||||
uvData[userId] = 0
|
||||
|
@ -240,7 +249,7 @@ function IncUserStat(userId: number) {
|
|||
}
|
||||
}
|
||||
|
||||
function AddUserIdStat(userId: number) {
|
||||
function AddUserIdStat(userId: string) {
|
||||
try {
|
||||
const date = new Date()
|
||||
const now =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue