File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { metaApi } from '$lib/api' ;
1+ import { PUBLIC_BACKEND_API_DOMAIN } from '$env/static/public' ;
2+ import { Configuration , MetaApi } from '$lib/api/internal/v1' ;
23
3- export async function load ( { setHeaders } ) : Promise < { ok : false , error : string } | { ok : true , deviceCount : number } > {
4+ type ResponseType = Promise < { ok : false ; error : string } | { ok : true ; deviceCount : number } > ;
5+
6+ export async function load ( { setHeaders } ) : ResponseType {
47 setHeaders ( {
5- 'cache-control' : 'public, max-age=300'
6- } )
8+ 'cache-control' : 'public, max-age=300' ,
9+ } ) ;
10+
11+ let deviceCount : number ;
12+
13+ try {
14+ const metaApi = new MetaApi (
15+ new Configuration ( {
16+ basePath : 'https://' + PUBLIC_BACKEND_API_DOMAIN ,
17+ headers : {
18+ 'User-Agent' : 'OpenShockFrontend/1.0 (ServerSide)' ,
19+ } ,
20+ credentials : 'omit' ,
21+ } )
22+ ) ;
23+
24+ const { data } = await metaApi . publicGetOnlineDevicesStatistics ( ) ;
25+
26+ deviceCount = data . devicesOnline ;
27+ } catch ( e ) {
28+ console . error ( e ) ;
729
8- const { data } = await metaApi . publicGetOnlineDevicesStatistics ( ) ;
30+ return {
31+ ok : false ,
32+ error : 'Failed to fetch device count' ,
33+ } ;
34+ }
935
10- return { ok : true , deviceCount : data . devicesOnline } ;
36+ return { ok : true , deviceCount } ;
1137}
You can’t perform that action at this time.
0 commit comments