diff options
Diffstat (limited to 'client/src/app/core')
-rw-r--r-- | client/src/app/core/menu/menu.service.ts | 4 | ||||
-rw-r--r-- | client/src/app/core/routing/meta.service.ts | 4 | ||||
-rw-r--r-- | client/src/app/core/routing/redirect.service.ts | 21 | ||||
-rw-r--r-- | client/src/app/core/server/server.service.ts | 27 | ||||
-rw-r--r-- | client/src/app/core/theme/theme.service.ts | 19 |
5 files changed, 23 insertions, 52 deletions
diff --git a/client/src/app/core/menu/menu.service.ts b/client/src/app/core/menu/menu.service.ts index 4e00d0bce..a30766b29 100644 --- a/client/src/app/core/menu/menu.service.ts +++ b/client/src/app/core/menu/menu.service.ts | |||
@@ -3,7 +3,7 @@ import { debounceTime } from 'rxjs/operators' | |||
3 | import { Injectable } from '@angular/core' | 3 | import { Injectable } from '@angular/core' |
4 | import { GlobalIconName } from '@app/shared/shared-icons' | 4 | import { GlobalIconName } from '@app/shared/shared-icons' |
5 | import { sortObjectComparator } from '@shared/core-utils/miscs/miscs' | 5 | import { sortObjectComparator } from '@shared/core-utils/miscs/miscs' |
6 | import { ServerConfig } from '@shared/models/server' | 6 | import { HTMLServerConfig } from '@shared/models/server' |
7 | import { ScreenService } from '../wrappers' | 7 | import { ScreenService } from '../wrappers' |
8 | 8 | ||
9 | export type MenuLink = { | 9 | export type MenuLink = { |
@@ -59,7 +59,7 @@ export class MenuService { | |||
59 | this.isMenuDisplayed = window.innerWidth >= 800 && !this.isMenuChangedByUser | 59 | this.isMenuDisplayed = window.innerWidth >= 800 && !this.isMenuChangedByUser |
60 | } | 60 | } |
61 | 61 | ||
62 | buildCommonLinks (config: ServerConfig) { | 62 | buildCommonLinks (config: HTMLServerConfig) { |
63 | let entries: MenuLink[] = [ | 63 | let entries: MenuLink[] = [ |
64 | { | 64 | { |
65 | icon: 'globe' as 'globe', | 65 | icon: 'globe' as 'globe', |
diff --git a/client/src/app/core/routing/meta.service.ts b/client/src/app/core/routing/meta.service.ts index a5ac778dc..97e440faf 100644 --- a/client/src/app/core/routing/meta.service.ts +++ b/client/src/app/core/routing/meta.service.ts | |||
@@ -16,9 +16,7 @@ export class MetaService { | |||
16 | private meta: Meta, | 16 | private meta: Meta, |
17 | private server: ServerService | 17 | private server: ServerService |
18 | ) { | 18 | ) { |
19 | this.config = this.server.getTmpConfig() | 19 | this.config = this.server.getHTMLConfig() |
20 | this.server.getConfig() | ||
21 | .subscribe(config => this.config = config) | ||
22 | } | 20 | } |
23 | 21 | ||
24 | setTitle (subTitle?: string) { | 22 | setTitle (subTitle?: string) { |
diff --git a/client/src/app/core/routing/redirect.service.ts b/client/src/app/core/routing/redirect.service.ts index cf690a4d0..198332b00 100644 --- a/client/src/app/core/routing/redirect.service.ts +++ b/client/src/app/core/routing/redirect.service.ts | |||
@@ -20,24 +20,14 @@ export class RedirectService { | |||
20 | private serverService: ServerService | 20 | private serverService: ServerService |
21 | ) { | 21 | ) { |
22 | // The config is first loaded from the cache so try to get the default route | 22 | // The config is first loaded from the cache so try to get the default route |
23 | const tmpConfig = this.serverService.getTmpConfig() | 23 | const config = this.serverService.getHTMLConfig() |
24 | if (tmpConfig?.instance?.defaultClientRoute) { | 24 | if (config?.instance?.defaultClientRoute) { |
25 | this.defaultRoute = tmpConfig.instance.defaultClientRoute | 25 | this.defaultRoute = config.instance.defaultClientRoute |
26 | } | 26 | } |
27 | if (tmpConfig?.trending?.videos?.algorithms?.default) { | 27 | if (config?.trending?.videos?.algorithms?.default) { |
28 | this.defaultTrendingAlgorithm = tmpConfig.trending.videos.algorithms.default | 28 | this.defaultTrendingAlgorithm = config.trending.videos.algorithms.default |
29 | } | 29 | } |
30 | 30 | ||
31 | // Load default route | ||
32 | this.serverService.getConfig() | ||
33 | .subscribe(config => { | ||
34 | const defaultRouteConfig = config.instance.defaultClientRoute | ||
35 | const defaultTrendingConfig = config.trending.videos.algorithms.default | ||
36 | |||
37 | if (defaultRouteConfig) this.defaultRoute = defaultRouteConfig | ||
38 | if (defaultTrendingConfig) this.defaultTrendingAlgorithm = defaultTrendingConfig | ||
39 | }) | ||
40 | |||
41 | // Track previous url | 31 | // Track previous url |
42 | this.currentUrl = this.router.url | 32 | this.currentUrl = this.router.url |
43 | router.events.subscribe(event => { | 33 | router.events.subscribe(event => { |
@@ -52,6 +42,7 @@ export class RedirectService { | |||
52 | return this.defaultRoute | 42 | return this.defaultRoute |
53 | } | 43 | } |
54 | 44 | ||
45 | |||
55 | getDefaultTrendingAlgorithm () { | 46 | getDefaultTrendingAlgorithm () { |
56 | return this.defaultTrendingAlgorithm | 47 | return this.defaultTrendingAlgorithm |
57 | } | 48 | } |
diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.ts index 251963858..8f041a147 100644 --- a/client/src/app/core/server/server.service.ts +++ b/client/src/app/core/server/server.service.ts | |||
@@ -37,9 +37,9 @@ export class ServerService { | |||
37 | ) { | 37 | ) { |
38 | } | 38 | } |
39 | 39 | ||
40 | loadConfig () { | 40 | loadHTMLConfig () { |
41 | try { | 41 | try { |
42 | return this.loadConfigLocally() | 42 | return this.loadHTMLConfigLocally() |
43 | } catch (err) { | 43 | } catch (err) { |
44 | // Expected in dev mode since we can't inject the config in the HTML | 44 | // Expected in dev mode since we can't inject the config in the HTML |
45 | if (environment.production !== false) { | 45 | if (environment.production !== false) { |
@@ -76,6 +76,7 @@ export class ServerService { | |||
76 | .pipe( | 76 | .pipe( |
77 | tap(config => { | 77 | tap(config => { |
78 | this.config = config | 78 | this.config = config |
79 | this.htmlConfig = config | ||
79 | this.configLoaded = true | 80 | this.configLoaded = true |
80 | }), | 81 | }), |
81 | tap(config => { | 82 | tap(config => { |
@@ -91,8 +92,8 @@ export class ServerService { | |||
91 | return this.configObservable | 92 | return this.configObservable |
92 | } | 93 | } |
93 | 94 | ||
94 | getTmpConfig () { | 95 | getHTMLConfig () { |
95 | return this.config | 96 | return this.htmlConfig |
96 | } | 97 | } |
97 | 98 | ||
98 | getVideoCategories () { | 99 | getVideoCategories () { |
@@ -156,20 +157,6 @@ export class ServerService { | |||
156 | return this.http.get<ServerStats>(ServerService.BASE_STATS_URL) | 157 | return this.http.get<ServerStats>(ServerService.BASE_STATS_URL) |
157 | } | 158 | } |
158 | 159 | ||
159 | getDefaultSearchTarget (): Promise<SearchTargetType> { | ||
160 | return this.getConfig().pipe( | ||
161 | map(config => { | ||
162 | const searchIndexConfig = config.search.searchIndex | ||
163 | |||
164 | if (searchIndexConfig.enabled && (searchIndexConfig.isDefaultSearch || searchIndexConfig.disableLocalSearch)) { | ||
165 | return 'search-index' | ||
166 | } | ||
167 | |||
168 | return 'local' | ||
169 | }) | ||
170 | ).toPromise() | ||
171 | } | ||
172 | |||
173 | private loadAttributeEnum <T extends string | number> ( | 160 | private loadAttributeEnum <T extends string | number> ( |
174 | baseUrl: string, | 161 | baseUrl: string, |
175 | attributeName: 'categories' | 'licences' | 'languages' | 'privacies', | 162 | attributeName: 'categories' | 'licences' | 'languages' | 'privacies', |
@@ -204,12 +191,12 @@ export class ServerService { | |||
204 | ) | 191 | ) |
205 | } | 192 | } |
206 | 193 | ||
207 | private loadConfigLocally () { | 194 | private loadHTMLConfigLocally () { |
208 | const configString = window['PeerTubeServerConfig'] | 195 | const configString = window['PeerTubeServerConfig'] |
209 | if (!configString) { | 196 | if (!configString) { |
210 | throw new Error('Could not find PeerTubeServerConfig in HTML') | 197 | throw new Error('Could not find PeerTubeServerConfig in HTML') |
211 | } | 198 | } |
212 | 199 | ||
213 | this.config = JSON.parse(configString) | 200 | this.htmlConfig = JSON.parse(configString) |
214 | } | 201 | } |
215 | } | 202 | } |
diff --git a/client/src/app/core/theme/theme.service.ts b/client/src/app/core/theme/theme.service.ts index e7a5ae17a..0c7dec0a1 100644 --- a/client/src/app/core/theme/theme.service.ts +++ b/client/src/app/core/theme/theme.service.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { first } from 'rxjs/operators' | 1 | import { first } from 'rxjs/operators' |
2 | import { Injectable } from '@angular/core' | 2 | import { Injectable } from '@angular/core' |
3 | import { UserLocalStorageKeys } from '@root-helpers/users' | 3 | import { UserLocalStorageKeys } from '@root-helpers/users' |
4 | import { ServerConfig, ServerConfigTheme } from '@shared/models' | 4 | import { HTMLServerConfig, ServerConfigTheme } from '@shared/models' |
5 | import { environment } from '../../../environments/environment' | 5 | import { environment } from '../../../environments/environment' |
6 | import { AuthService } from '../auth' | 6 | import { AuthService } from '../auth' |
7 | import { PluginService } from '../plugins/plugin.service' | 7 | import { PluginService } from '../plugins/plugin.service' |
@@ -18,7 +18,7 @@ export class ThemeService { | |||
18 | private themeFromLocalStorage: ServerConfigTheme | 18 | private themeFromLocalStorage: ServerConfigTheme |
19 | private themeDOMLinksFromLocalStorage: HTMLLinkElement[] = [] | 19 | private themeDOMLinksFromLocalStorage: HTMLLinkElement[] = [] |
20 | 20 | ||
21 | private serverConfig: ServerConfig | 21 | private serverConfig: HTMLServerConfig |
22 | 22 | ||
23 | constructor ( | 23 | constructor ( |
24 | private auth: AuthService, | 24 | private auth: AuthService, |
@@ -32,18 +32,13 @@ export class ThemeService { | |||
32 | // Try to load from local storage first, so we don't have to wait network requests | 32 | // Try to load from local storage first, so we don't have to wait network requests |
33 | this.loadAndSetFromLocalStorage() | 33 | this.loadAndSetFromLocalStorage() |
34 | 34 | ||
35 | this.serverConfig = this.server.getTmpConfig() | 35 | this.serverConfig = this.server.getHTMLConfig() |
36 | this.server.getConfig() | 36 | const themes = this.serverConfig.theme.registered |
37 | .subscribe(config => { | ||
38 | this.serverConfig = config | ||
39 | 37 | ||
40 | const themes = this.serverConfig.theme.registered | 38 | this.removeThemeFromLocalStorageIfNeeded(themes) |
39 | this.injectThemes(themes) | ||
41 | 40 | ||
42 | this.removeThemeFromLocalStorageIfNeeded(themes) | 41 | this.listenUserTheme() |
43 | this.injectThemes(themes) | ||
44 | |||
45 | this.listenUserTheme() | ||
46 | }) | ||
47 | } | 42 | } |
48 | 43 | ||
49 | private injectThemes (themes: ServerConfigTheme[], fromLocalStorage = false) { | 44 | private injectThemes (themes: ServerConfigTheme[], fromLocalStorage = false) { |