chore: fix comments

This commit is contained in:
waterplea
2024-04-26 13:17:25 +03:00
parent 8b89e03999
commit 7f525fa7dc
4 changed files with 91 additions and 6 deletions

View File

@@ -0,0 +1,19 @@
import { inject, Injectable } from '@angular/core'
import { Observable, retry, shareReplay } from 'rxjs'
import { Metrics } from 'src/app/services/api/api.types'
import { ApiService } from 'src/app/services/api/embassy-api.service'
@Injectable({
providedIn: 'root',
})
export class MetricsService extends Observable<Metrics> {
private readonly metrics$ = inject(ApiService)
.openMetricsWebsocket$({
url: '',
})
.pipe(retry(), shareReplay(1))
constructor() {
super(subscriber => this.metrics$.subscribe(subscriber))
}
}

View File

@@ -0,0 +1,52 @@
import { inject, Injectable } from '@angular/core'
import { PatchDB } from 'patch-db-client'
import {
combineLatest,
defer,
map,
shareReplay,
startWith,
switchMap,
timer,
} from 'rxjs'
import { ApiService } from 'src/app/services/api/embassy-api.service'
import { DataModel } from 'src/app/services/patch-db/data-model'
@Injectable({
providedIn: 'root',
})
export class TimeService {
private readonly patch = inject(PatchDB<DataModel>)
private readonly time$ = defer(() =>
inject(ApiService).getSystemTime({}),
).pipe(
switchMap(({ now, uptime }) =>
timer(0, 1000).pipe(
map(index => ({
now: new Date(now).valueOf() + 1000 * index,
uptime: uptime + index,
})),
),
),
shareReplay(1),
)
readonly now$ = combineLatest([
this.time$,
this.patch.watch$('serverInfo', 'ntpSynced'),
]).pipe(map(([{ now }, synced]) => ({ now, synced })))
readonly uptime$ = this.time$.pipe(
map(({ uptime }) => {
const days = Math.floor(uptime / (24 * 60 * 60))
const daysSec = uptime % (24 * 60 * 60)
const hours = Math.floor(daysSec / (60 * 60))
const hoursSec = uptime % (60 * 60)
const minutes = Math.floor(hoursSec / 60)
const seconds = uptime % 60
return `${days}:${hours}:${minutes}:${seconds}`
}),
startWith('-:-:-:-'),
)
}