'use strict' ; import { Router , RequestHandler , Request , Response , NextFunction } from 'express' ; import { setupMetaverseAPI , finishMetaverseAPI , finishReturnData } from '@Route-Tools/middleware' ; import { accountFromAuthToken } from '@Route-Tools/middleware' ; import { Accounts } from '@Entities/Accounts' ; import { Places } from '@Entities/Places' ; import { Domains } from '@Entities/Domains' ; import { PaginationInfo } from '@Entities/EntityFilters/PaginationInfo' ; import { PlaceFilterInfo } from '@Entities/EntityFilters/PlaceFilterInfo' ; import { IsNotNullOrEmpty , IsNullOrEmpty } from '@Tools/Misc' ; import { VKeyedCollection } from '@Tools/vTypes' ; import { Logger } from '@Tools/Logging' ; import { buildPlaceInfoSmall } from '@Route-Tools/Util' ; const procGetExplore = async ( req , resp , next ) => { const pager = new PaginationInfo ( ) ; const placer = new PlaceFilterInfo ( ) ; pager . parametersFromRequest ( req ) ; placer . parametersFromRequest ( req ) ; const allPlaces = [ ] ; for await ( const place of Places . enumerateAsync ( placer , pager ) ) { const aDomain = await Domains . getDomainWithId ( place . domainId ) ; if ( aDomain && IsNotNullOrEmpty ( aDomain . networkAddr ) ) { const placeDesc = { 'Domain Name' : place . name , } ; placeDesc . Address = await Places . getAddressString ( place ) ; placeDesc . Visit = 'hifi://' + placeDesc . Address ; placeDesc . DomainId = aDomain . id ; placeDesc [ 'Network Address' ] = aDomain . networkAddr ; placeDesc [ 'Network Port' ] = aDomain . networkPort ; placeDesc . Owner = '' ; if ( IsNotNullOrEmpty ( aDomain . sponsorAccountId ) ) { const aAccount = await Accounts . getAccountWithId ( aDomain . sponsorAccountId ) ; if ( IsNotNullOrEmpty ( aAccount ) ) { placeDesc . Owner = aAccount . username ; } ; } ; placeDesc . People = place . currentAttendance ?? 0 ; placeDesc . Place = await buildPlaceInfoSmall ( place , aDomain ) ; allPlaces . push ( placeDesc ) ; } ; } ; req . vRestResp . Data = allPlaces ; placer . addResponseFields ( req ) ; pager . addResponseFields ( req ) ; next ( ) ; } ; export const name = '/explore' ; export const router = Router ( ) ; router . get ( '/explore.json' , [ setupMetaverseAPI , accountFromAuthToken , procGetExplore , finishReturnData ] ) ;