mirror of
				https://gitlab.com/MrFry/mrfrys-node-server
				synced 2025-04-01 20:24:18 +02:00 
			
		
		
		
	Added no log to logger
This commit is contained in:
		
							
								
								
									
										15
									
								
								src/tests/shouldLog.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/tests/shouldLog.test.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					import { shouldLog } from '../utils/logger'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const noLogIds = ['1', '2', '10', '40']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const truthy = [1, 2, '10', '40']
 | 
				
			||||||
 | 
					const falsey = [5, '55', 47832, 'fhs']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test('ShouldLog works', () => {
 | 
				
			||||||
 | 
					  truthy.forEach((x) => {
 | 
				
			||||||
 | 
					    expect(shouldLog(x, noLogIds)).toBeTruthy()
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					  falsey.forEach((x) => {
 | 
				
			||||||
 | 
					    expect(shouldLog(x, noLogIds)).toBeFalsy()
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
@@ -113,6 +113,9 @@ function LogReq(
 | 
				
			|||||||
    if (req.url.includes('lred')) {
 | 
					    if (req.url.includes('lred')) {
 | 
				
			||||||
      dl += C('red')
 | 
					      dl += C('red')
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    if (!shouldLog(req.session.user.id, noLogIds)) {
 | 
				
			||||||
 | 
					      return
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let hostname
 | 
					    let hostname
 | 
				
			||||||
    if (req.hostname) {
 | 
					    if (req.hostname) {
 | 
				
			||||||
@@ -221,10 +224,14 @@ function Load(): void {
 | 
				
			|||||||
  setNoLogReadInterval()
 | 
					  setNoLogReadInterval()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function LogStat(url: string, hostname: string, userId: number | string): void {
 | 
					export function shouldLog(userId: string | number, nolog: string[]): boolean {
 | 
				
			||||||
  const nolog = noLogIds.some((noLogId) => {
 | 
					  return nolog.some((noLogId) => {
 | 
				
			||||||
    return noLogId === userId.toString()
 | 
					    return noLogId === userId.toString()
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function LogStat(url: string, hostname: string, userId: number | string): void {
 | 
				
			||||||
 | 
					  const nolog = shouldLog(userId, noLogIds)
 | 
				
			||||||
  if (nolog) {
 | 
					  if (nolog) {
 | 
				
			||||||
    return
 | 
					    return
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user