'use strict' ; import os from 'os' ; import { Router , RequestHandler , Request , Response , NextFunction } from 'express' ; import { setupMetaverseAPI , finishMetaverseAPI , param1FromParams } from '@Route-Tools/middleware' ; import { accountFromAuthToken } from '@Route-Tools/middleware' ; import { Monitoring } from '@Monitoring/Monitoring' ; import { Logger } from '@Tools/Logging' ; const procGetStat = async ( req , resp , next ) => { if ( req . vAuthAccount ) { if ( req . vParam1 ) { let includeHistory = true ; if ( req . query . history ) { if ( typeof ( req . query . history ) === 'string' ) { includeHistory = [ 'false' , 'no' ] . includes ( req . query . history ) ? false : true ; } ; } ; const stat = Monitoring . getStat ( req . vParam1 ) ; if ( stat ) { req . vRestResp . Data = { 'stat' : stat . Report ( includeHistory ) } ; } else { req . vRestResp . respondFailure ( 'Unknown stat' ) ; } ; } else { req . vRestResp . respondFailure ( 'missing parameter' ) ; } ; } else { req . vRestResp . respondFailure ( req . vAccountError ?? 'Not logged in' ) ; } ; next ( ) ; } ; export const name = '/api/v1/stats/stat/:name' ; export const router = Router ( ) ; router . get ( '/api/v1/stats/stat/:param1' , [ setupMetaverseAPI , accountFromAuthToken , param1FromParams , procGetStat , finishMetaverseAPI ] ) ;