diff options
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/app/app-routing.module.ts | 2 | ||||
-rw-r--r-- | client/src/app/app.module.ts | 16 | ||||
-rw-r--r-- | client/src/app/core/server/server.service.ts | 180 |
3 files changed, 34 insertions, 164 deletions
diff --git a/client/src/app/app-routing.module.ts b/client/src/app/app-routing.module.ts index e35f540be..b04e6a42b 100644 --- a/client/src/app/app-routing.module.ts +++ b/client/src/app/app-routing.module.ts | |||
@@ -114,7 +114,7 @@ const routes: Routes = [ | |||
114 | path: 'w', | 114 | path: 'w', |
115 | loadChildren: () => import('@app/+videos/+video-watch/video-watch.module').then(m => m.VideoWatchModule), | 115 | loadChildren: () => import('@app/+videos/+video-watch/video-watch.module').then(m => m.VideoWatchModule), |
116 | data: { | 116 | data: { |
117 | preload: 3000 | 117 | preload: 5000 |
118 | } | 118 | } |
119 | }, | 119 | }, |
120 | { | 120 | { |
diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts index 9f46d49a2..8fc054d79 100644 --- a/client/src/app/app.module.ts +++ b/client/src/app/app.module.ts | |||
@@ -1,13 +1,13 @@ | |||
1 | import 'focus-visible' | 1 | import 'focus-visible' |
2 | import { environment } from 'src/environments/environment' | 2 | import { environment } from 'src/environments/environment' |
3 | import { APP_BASE_HREF, registerLocaleData } from '@angular/common' | 3 | import { APP_BASE_HREF, registerLocaleData } from '@angular/common' |
4 | import { NgModule } from '@angular/core' | 4 | import { APP_INITIALIZER, NgModule } from '@angular/core' |
5 | import { BrowserModule } from '@angular/platform-browser' | 5 | import { BrowserModule } from '@angular/platform-browser' |
6 | import { ServiceWorkerModule } from '@angular/service-worker' | 6 | import { ServiceWorkerModule } from '@angular/service-worker' |
7 | import localeOc from '@app/helpers/locales/oc' | 7 | import localeOc from '@app/helpers/locales/oc' |
8 | import { AppRoutingModule } from './app-routing.module' | 8 | import { AppRoutingModule } from './app-routing.module' |
9 | import { AppComponent } from './app.component' | 9 | import { AppComponent } from './app.component' |
10 | import { CoreModule } from './core' | 10 | import { CoreModule, ServerService } from './core' |
11 | import { EmptyComponent } from './empty.component' | 11 | import { EmptyComponent } from './empty.component' |
12 | import { HeaderComponent, SearchTypeaheadComponent, SuggestionComponent } from './header' | 12 | import { HeaderComponent, SearchTypeaheadComponent, SuggestionComponent } from './header' |
13 | import { HighlightPipe } from './header/highlight.pipe' | 13 | import { HighlightPipe } from './header/highlight.pipe' |
@@ -26,6 +26,10 @@ import { SharedUserInterfaceSettingsModule } from './shared/shared-user-settings | |||
26 | 26 | ||
27 | registerLocaleData(localeOc, 'oc') | 27 | registerLocaleData(localeOc, 'oc') |
28 | 28 | ||
29 | export function loadConfigFactory (server: ServerService) { | ||
30 | return () => server.loadConfig() | ||
31 | } | ||
32 | |||
29 | @NgModule({ | 33 | @NgModule({ |
30 | bootstrap: [ AppComponent ], | 34 | bootstrap: [ AppComponent ], |
31 | 35 | ||
@@ -67,7 +71,13 @@ registerLocaleData(localeOc, 'oc') | |||
67 | { | 71 | { |
68 | provide: APP_BASE_HREF, | 72 | provide: APP_BASE_HREF, |
69 | useValue: '/' | 73 | useValue: '/' |
70 | } | 74 | }, |
75 | { | ||
76 | provide: APP_INITIALIZER, | ||
77 | useFactory: loadConfigFactory, | ||
78 | deps: [ ServerService ], | ||
79 | multi: true | ||
80 | } | ||
71 | ] | 81 | ] |
72 | }) | 82 | }) |
73 | export class AppModule {} | 83 | export class AppModule {} |
diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.ts index 6918957f4..251963858 100644 --- a/client/src/app/core/server/server.service.ts +++ b/client/src/app/core/server/server.service.ts | |||
@@ -4,7 +4,7 @@ import { HttpClient } from '@angular/common/http' | |||
4 | import { Inject, Injectable, LOCALE_ID } from '@angular/core' | 4 | import { Inject, Injectable, LOCALE_ID } from '@angular/core' |
5 | import { getDevLocale, isOnDevLocale, sortBy } from '@app/helpers' | 5 | import { getDevLocale, isOnDevLocale, sortBy } from '@app/helpers' |
6 | import { getCompleteLocale, isDefaultLocale, peertubeTranslate } from '@shared/core-utils/i18n' | 6 | import { getCompleteLocale, isDefaultLocale, peertubeTranslate } from '@shared/core-utils/i18n' |
7 | import { SearchTargetType, ServerConfig, ServerStats, VideoConstant } from '@shared/models' | 7 | import { HTMLServerConfig, SearchTargetType, ServerConfig, ServerStats, VideoConstant } from '@shared/models' |
8 | import { environment } from '../../../environments/environment' | 8 | import { environment } from '../../../environments/environment' |
9 | 9 | ||
10 | @Injectable() | 10 | @Injectable() |
@@ -28,163 +28,26 @@ export class ServerService { | |||
28 | private configReset = false | 28 | private configReset = false |
29 | 29 | ||
30 | private configLoaded = false | 30 | private configLoaded = false |
31 | private config: ServerConfig = { | 31 | private config: ServerConfig |
32 | instance: { | 32 | private htmlConfig: HTMLServerConfig |
33 | name: 'PeerTube', | ||
34 | shortDescription: 'PeerTube, a federated (ActivityPub) video streaming platform ' + | ||
35 | 'using P2P (BitTorrent) directly in the web browser with WebTorrent and Angular.', | ||
36 | isNSFW: false, | ||
37 | defaultNSFWPolicy: 'do_not_list' as 'do_not_list', | ||
38 | defaultClientRoute: '', | ||
39 | customizations: { | ||
40 | javascript: '', | ||
41 | css: '' | ||
42 | } | ||
43 | }, | ||
44 | plugin: { | ||
45 | registered: [], | ||
46 | registeredExternalAuths: [], | ||
47 | registeredIdAndPassAuths: [] | ||
48 | }, | ||
49 | theme: { | ||
50 | registered: [], | ||
51 | default: 'default' | ||
52 | }, | ||
53 | email: { | ||
54 | enabled: false | ||
55 | }, | ||
56 | contactForm: { | ||
57 | enabled: false | ||
58 | }, | ||
59 | serverVersion: 'Unknown', | ||
60 | signup: { | ||
61 | allowed: false, | ||
62 | allowedForCurrentIP: false, | ||
63 | requiresEmailVerification: false, | ||
64 | minimumAge: 16 | ||
65 | }, | ||
66 | transcoding: { | ||
67 | profile: 'default', | ||
68 | availableProfiles: [ 'default' ], | ||
69 | enabledResolutions: [], | ||
70 | hls: { | ||
71 | enabled: false | ||
72 | }, | ||
73 | webtorrent: { | ||
74 | enabled: true | ||
75 | } | ||
76 | }, | ||
77 | live: { | ||
78 | enabled: false, | ||
79 | allowReplay: true, | ||
80 | maxDuration: null, | ||
81 | maxInstanceLives: -1, | ||
82 | maxUserLives: -1, | ||
83 | transcoding: { | ||
84 | enabled: false, | ||
85 | profile: 'default', | ||
86 | availableProfiles: [ 'default' ], | ||
87 | enabledResolutions: [] | ||
88 | }, | ||
89 | rtmp: { | ||
90 | port: 1935 | ||
91 | } | ||
92 | }, | ||
93 | avatar: { | ||
94 | file: { | ||
95 | size: { max: 0 }, | ||
96 | extensions: [] | ||
97 | } | ||
98 | }, | ||
99 | banner: { | ||
100 | file: { | ||
101 | size: { max: 0 }, | ||
102 | extensions: [] | ||
103 | } | ||
104 | }, | ||
105 | video: { | ||
106 | image: { | ||
107 | size: { max: 0 }, | ||
108 | extensions: [] | ||
109 | }, | ||
110 | file: { | ||
111 | extensions: [] | ||
112 | } | ||
113 | }, | ||
114 | videoCaption: { | ||
115 | file: { | ||
116 | size: { max: 0 }, | ||
117 | extensions: [] | ||
118 | } | ||
119 | }, | ||
120 | user: { | ||
121 | videoQuota: -1, | ||
122 | videoQuotaDaily: -1 | ||
123 | }, | ||
124 | import: { | ||
125 | videos: { | ||
126 | http: { | ||
127 | enabled: false | ||
128 | }, | ||
129 | torrent: { | ||
130 | enabled: false | ||
131 | } | ||
132 | } | ||
133 | }, | ||
134 | trending: { | ||
135 | videos: { | ||
136 | intervalDays: 0, | ||
137 | algorithms: { | ||
138 | enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ], | ||
139 | default: 'most-viewed' | ||
140 | } | ||
141 | } | ||
142 | }, | ||
143 | autoBlacklist: { | ||
144 | videos: { | ||
145 | ofUsers: { | ||
146 | enabled: false | ||
147 | } | ||
148 | } | ||
149 | }, | ||
150 | tracker: { | ||
151 | enabled: true | ||
152 | }, | ||
153 | followings: { | ||
154 | instance: { | ||
155 | autoFollowIndex: { | ||
156 | indexUrl: 'https://instances.joinpeertube.org' | ||
157 | } | ||
158 | } | ||
159 | }, | ||
160 | broadcastMessage: { | ||
161 | enabled: false, | ||
162 | message: '', | ||
163 | level: 'info', | ||
164 | dismissable: false | ||
165 | }, | ||
166 | search: { | ||
167 | remoteUri: { | ||
168 | users: true, | ||
169 | anonymous: false | ||
170 | }, | ||
171 | searchIndex: { | ||
172 | enabled: false, | ||
173 | url: '', | ||
174 | disableLocalSearch: false, | ||
175 | isDefaultSearch: false | ||
176 | } | ||
177 | }, | ||
178 | homepage: { | ||
179 | enabled: false | ||
180 | } | ||
181 | } | ||
182 | 33 | ||
183 | constructor ( | 34 | constructor ( |
184 | private http: HttpClient, | 35 | private http: HttpClient, |
185 | @Inject(LOCALE_ID) private localeId: string | 36 | @Inject(LOCALE_ID) private localeId: string |
186 | ) { | 37 | ) { |
187 | this.loadConfigLocally() | 38 | } |
39 | |||
40 | loadConfig () { | ||
41 | try { | ||
42 | return this.loadConfigLocally() | ||
43 | } catch (err) { | ||
44 | // Expected in dev mode since we can't inject the config in the HTML | ||
45 | if (environment.production !== false) { | ||
46 | console.error('Cannot load config locally. Fallback to API.') | ||
47 | } | ||
48 | |||
49 | return this.getConfig() | ||
50 | } | ||
188 | } | 51 | } |
189 | 52 | ||
190 | getServerVersionAndCommit () { | 53 | getServerVersionAndCommit () { |
@@ -343,13 +206,10 @@ export class ServerService { | |||
343 | 206 | ||
344 | private loadConfigLocally () { | 207 | private loadConfigLocally () { |
345 | const configString = window['PeerTubeServerConfig'] | 208 | const configString = window['PeerTubeServerConfig'] |
346 | if (!configString) return | 209 | if (!configString) { |
347 | 210 | throw new Error('Could not find PeerTubeServerConfig in HTML') | |
348 | try { | ||
349 | const parsed = JSON.parse(configString) | ||
350 | Object.assign(this.config, parsed) | ||
351 | } catch (err) { | ||
352 | console.error('Cannot parse config saved in from index.html.', err) | ||
353 | } | 211 | } |
212 | |||
213 | this.config = JSON.parse(configString) | ||
354 | } | 214 | } |
355 | } | 215 | } |