X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Babout%2Fabout-instance%2Fabout-instance.resolver.ts;h=5c09b0f46f07f18d56832c3a59b682788cd0eadf;hb=52798aa5f277492d4dd2482bca9396d2e982fa19;hp=8818fc5825f6113ee9f64b173bed47f92683d14d;hpb=4e4c23c5b8d55ab0aa48a7be8c53ec71d1d7e796;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+about/about-instance/about-instance.resolver.ts b/client/src/app/+about/about-instance/about-instance.resolver.ts index 8818fc582..5c09b0f46 100644 --- a/client/src/app/+about/about-instance/about-instance.resolver.ts +++ b/client/src/app/+about/about-instance/about-instance.resolver.ts @@ -1,12 +1,13 @@ -import { forkJoin } from 'rxjs' +import { forkJoin, Observable } from 'rxjs' import { map, switchMap } from 'rxjs/operators' import { Injectable } from '@angular/core' -import { Resolve } from '@angular/router' +import { ServerService } from '@app/core' import { CustomMarkupService } from '@app/shared/shared-custom-markup' import { AboutHTML, InstanceService } from '@app/shared/shared-instance' -import { About } from '@shared/models/server' +import { About, ServerStats } from '@shared/models/server' export type ResolverData = { + serverStats: ServerStats about: About languages: string[] categories: string[] @@ -15,29 +16,51 @@ export type ResolverData = { } @Injectable() -export class AboutInstanceResolver implements Resolve { +export class AboutInstanceResolver { constructor ( private instanceService: InstanceService, - private customMarkupService: CustomMarkupService - + private customMarkupService: CustomMarkupService, + private serverService: ServerService ) {} - resolve () { + resolve (): Observable { + return forkJoin([ + this.buildInstanceAboutObservable(), + this.buildInstanceStatsObservable() + ]).pipe( + map(([ + [ about, languages, categories, aboutHTML, { rootElement } ], + serverStats + ]) => { + return { + serverStats, + about, + languages, + categories, + aboutHTML, + descriptionElement: rootElement + } + }) + ) + } + + private buildInstanceAboutObservable () { return this.instanceService.getAbout() - .pipe( - switchMap(about => { - return forkJoin([ - Promise.resolve(about), - this.instanceService.buildTranslatedLanguages(about), - this.instanceService.buildTranslatedCategories(about), - this.instanceService.buildHtml(about), - this.customMarkupService.buildElement(about.instance.description) - ]) - }), - map(([ about, languages, categories, aboutHTML, { rootElement } ]) => { - return { about, languages, categories, aboutHTML, descriptionElement: rootElement } as ResolverData - }) - ) + .pipe( + switchMap(about => { + return forkJoin([ + Promise.resolve(about), + this.instanceService.buildTranslatedLanguages(about), + this.instanceService.buildTranslatedCategories(about), + this.instanceService.buildHtml(about), + this.customMarkupService.buildElement(about.instance.description) + ]) + }) + ) + } + + private buildInstanceStatsObservable () { + return this.serverService.getServerStats() } }