feat: refactor logs (#2555)

* feat: refactor logs

* chore: comments

* feat: add system logs

* feat: update shared logs
This commit is contained in:
Alex Inkin
2024-02-06 06:26:00 +04:00
committed by GitHub
parent 4410d7f195
commit 9a0ae549f6
33 changed files with 676 additions and 180 deletions

View File

@@ -1,7 +1,9 @@
import { DOCUMENT } from '@angular/common'
import { Inject, Injectable } from '@angular/core'
@Injectable()
@Injectable({
providedIn: 'root',
})
export class DownloadHTMLService {
constructor(@Inject(DOCUMENT) private readonly document: Document) {}

View File

@@ -1,8 +1,9 @@
import { StaticClassProvider } from '@angular/core'
import { defer, Observable, switchMap } from 'rxjs'
import { bufferTime, defer, map, Observable, scan, switchMap } from 'rxjs'
import { WebSocketSubjectConfig } from 'rxjs/webSocket'
import { FollowLogsReq, FollowLogsRes, Log } from '../types/api'
import { Constructor } from '../types/constructor'
import { convertAnsi } from '../util/convert-ansi'
interface Api {
followServerLogs: (params: FollowLogsReq) => Promise<FollowLogsRes>
@@ -19,11 +20,14 @@ export function provideSetupLogsService(
}
}
export class SetupLogsService extends Observable<Log> {
export class SetupLogsService extends Observable<readonly string[]> {
private readonly log$ = defer(() => this.api.followServerLogs({})).pipe(
switchMap(({ guid }) =>
this.api.openLogsWebsocket$({ url: `/rpc/${guid}` }),
),
bufferTime(1000),
map(convertAnsi),
scan((logs: readonly string[], log) => [...logs, log], []),
)
constructor(private readonly api: Api) {