]>
Commit | Line | Data |
---|---|---|
f6cf8e8d | 1 | import { forkJoin, Observable } from 'rxjs' |
67ed6552 | 2 | import { map, switchMap } from 'rxjs/operators' |
b42f9c40 | 3 | import { Injectable } from '@angular/core' |
f6cf8e8d | 4 | import { ServerService } from '@app/core' |
789ba349 C |
5 | import { CustomMarkupService } from '@app/shared/shared-custom-markup' |
6 | import { AboutHTML, InstanceService } from '@app/shared/shared-instance' | |
f6cf8e8d | 7 | import { About, ServerStats } from '@shared/models/server' |
b42f9c40 | 8 | |
789ba349 | 9 | export type ResolverData = { |
f6cf8e8d | 10 | serverStats: ServerStats |
789ba349 C |
11 | about: About |
12 | languages: string[] | |
13 | categories: string[] | |
14 | aboutHTML: AboutHTML | |
15 | descriptionElement: HTMLDivElement | |
16 | } | |
b42f9c40 C |
17 | |
18 | @Injectable() | |
d0fbc9fd | 19 | export class AboutInstanceResolver { |
67ed6552 | 20 | |
12c8a463 | 21 | constructor ( |
789ba349 | 22 | private instanceService: InstanceService, |
f6cf8e8d C |
23 | private customMarkupService: CustomMarkupService, |
24 | private serverService: ServerService | |
12c8a463 | 25 | ) {} |
b42f9c40 | 26 | |
f6cf8e8d C |
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 () { | |
b42f9c40 | 49 | return this.instanceService.getAbout() |
f6cf8e8d C |
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() | |
b42f9c40 C |
65 | } |
66 | } |