mirror of
				https://gitlab.com/MrFry/mrfrys-node-server
				synced 2025-04-01 20:24:18 +02:00 
			
		
		
		
	added / fixed some types
This commit is contained in:
		@@ -1,3 +1,7 @@
 | 
			
		||||
import type { Response, NextFunction } from 'express'
 | 
			
		||||
import type { Request } from '../types/basicTypes'
 | 
			
		||||
import type { Database } from 'better-sqlite3'
 | 
			
		||||
 | 
			
		||||
import logger from '../utils/logger'
 | 
			
		||||
import utils from '../utils/utils'
 | 
			
		||||
import dbtools from '../utils/dbtools'
 | 
			
		||||
@@ -18,8 +22,8 @@ export const testUser = {
 | 
			
		||||
  createdBy: 1,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function renderLogin(req, res, jsonResponse) {
 | 
			
		||||
  res.status('401') // Unauthorized
 | 
			
		||||
function renderLogin(_req: Request, res: Response, jsonResponse: boolean) {
 | 
			
		||||
  res.status(401) // Unauthorized
 | 
			
		||||
  if (jsonResponse) {
 | 
			
		||||
    res.json({
 | 
			
		||||
      result: 'nouser',
 | 
			
		||||
@@ -33,9 +37,17 @@ function renderLogin(req, res, jsonResponse) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default function (options: Options): any {
 | 
			
		||||
  const { userDB, jsonResponse, exceptions } = options
 | 
			
		||||
  const {
 | 
			
		||||
    userDB,
 | 
			
		||||
    jsonResponse,
 | 
			
		||||
    exceptions,
 | 
			
		||||
  }: {
 | 
			
		||||
    userDB: Database
 | 
			
		||||
    jsonResponse: boolean
 | 
			
		||||
    exceptions: string[]
 | 
			
		||||
  } = options
 | 
			
		||||
 | 
			
		||||
  return function (req, res, next) {
 | 
			
		||||
  return function (req: Request, res: Response, next: NextFunction) {
 | 
			
		||||
    const sessionID = req.cookies.sessionID
 | 
			
		||||
    const isException = exceptions.some((exc) => {
 | 
			
		||||
      return req.url.split('?')[0] === exc
 | 
			
		||||
@@ -44,7 +56,7 @@ export default function (options: Options): any {
 | 
			
		||||
    if (process.env.NS_NOUSER) {
 | 
			
		||||
      req.session = {
 | 
			
		||||
        user: testUser,
 | 
			
		||||
        sessionID: sessionID || 111111111111111111,
 | 
			
		||||
        sessionID: sessionID || 11111111111,
 | 
			
		||||
        isException: false,
 | 
			
		||||
      }
 | 
			
		||||
      next()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user