]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+about/about-instance/about-instance.resolver.ts
f52a95b88e6233003f5bf9613655b7a782089676
[github/Chocobozzz/PeerTube.git] / client / src / app / +about / about-instance / about-instance.resolver.ts
1 import { forkJoin, Observable } from 'rxjs'
2 import { map, switchMap } from 'rxjs/operators'
3 import { Injectable } from '@angular/core'
4 import { ServerService } from '@app/core'
5 import { CustomMarkupService } from '@app/shared/shared-custom-markup'
6 import { AboutHTML, InstanceService } from '@app/shared/shared-instance'
7 import { About, ServerStats } from '@shared/models/server'
8
9 export type ResolverData = {
10 serverStats: ServerStats
11 about: About
12 languages: string[]
13 categories: string[]
14 aboutHTML: AboutHTML
15 descriptionElement: HTMLDivElement
16 }
17
18 @Injectable()
19 export class AboutInstanceResolver {
20
21 constructor (
22 private instanceService: InstanceService,
23 private customMarkupService: CustomMarkupService,
24 private serverService: ServerService
25 ) {}
26
27 resolve (): Observable<ResolverData> {
28 return forkJoin([
29 this.buildInstanceAboutObservable(),
30 this.buildInstanceStatsObservable()
31 ]).pipe(
32 map(([
33 [ about, languages, categories, aboutHTML, { rootElement } ],
34 serverStats
35 ]) => {
36 return {
37 serverStats,
38 about,
39 languages,
40 categories,
41 aboutHTML,
42 descriptionElement: rootElement
43 }
44 })
45 )
46 }
47
48 private buildInstanceAboutObservable () {
49 return this.instanceService.getAbout()
50 .pipe(
51 switchMap(about => {
52 return forkJoin([
53 Promise.resolve(about),
54 this.instanceService.buildTranslatedLanguages(about),
55 this.instanceService.buildTranslatedCategories(about),
56 this.instanceService.buildHtml(about),
57 this.customMarkupService.buildElement(about.instance.description)
58 ])
59 })
60 )
61 }
62
63 private buildInstanceStatsObservable () {
64 return this.serverService.getServerStats()
65 }
66 }