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