added / fixed some types

This commit is contained in:
mrfry 2022-03-14 19:35:42 +01:00
parent 5f12284bb8
commit bc5c293539
41 changed files with 4378 additions and 8304 deletions

View file

@ -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 = []
let noLogips: string[] = []
function getColoredDateString(): string {
const date = new Date()
@ -93,14 +93,18 @@ function Log(msg: string | object, color?: string): void {
)
}
function expandWithSpaces(text, count) {
function expandWithSpaces(text: string, count: number) {
while (text.length < count) {
text += ' '
}
return text
}
function LogReq(req: Request, toFile?: boolean, statusCode?: string): void {
function LogReq(
req: Request,
toFile?: boolean,
statusCode?: string | number
): void {
try {
const ip: any =
req.headers['cf-connecting-ip'] || req.connection.remoteAddress
@ -173,7 +177,7 @@ function LogReq(req: Request, toFile?: boolean, statusCode?: string): void {
}
}
function parseNoLogFile(newData) {
function parseNoLogFile(newData: string) {
noLogips = newData.split('\n')
if (noLogips[noLogips.length - 1] === '') {
noLogips.pop()
@ -185,7 +189,7 @@ function parseNoLogFile(newData) {
}
function setNoLogReadInterval() {
utils.WatchFile(nologFile, (newData) => {
utils.WatchFile(nologFile, (newData: string) => {
parseNoLogFile(newData)
})
@ -227,19 +231,7 @@ function Load(): void {
setNoLogReadInterval()
}
function LogStat(
url: string,
ip: string,
hostname: string,
userId: number
): void {
const nolog = noLogips.some((noLogips) => {
return ip.includes(noLogips)
})
if (nolog) {
return
}
function LogStat(url: string, hostname: string, userId: number): void {
url = hostname + url.split('?')[0]
Inc(url)
AddUserIdStat(userId)
@ -248,7 +240,7 @@ function LogStat(
Save()
}
function IncUserStat(userId) {
function IncUserStat(userId: number) {
try {
if (uvData[userId] === undefined) {
uvData[userId] = 0
@ -260,7 +252,7 @@ function IncUserStat(userId) {
}
}
function AddUserIdStat(userId) {
function AddUserIdStat(userId: number) {
try {
const date = new Date()
const now =
@ -282,7 +274,7 @@ function AddUserIdStat(userId) {
}
}
function Inc(value) {
function Inc(value: string) {
if (value.startsWith('/?')) {
value = '/'
}
@ -292,7 +284,7 @@ function Inc(value) {
vData[value]++
}
function AddVisitStat(name) {
function AddVisitStat(name: string) {
const date = new Date()
const now =
date.getFullYear() +
@ -346,7 +338,7 @@ function logHashed(msg: string): string {
return GetRandomColor(msg.toString()) + msg + C()
}
function GetRandomColor(msg): string {
function GetRandomColor(msg: string): string {
if (!msg) {
return 'red'
}