- return this.http.get(ServerService.BASE_VIDEO_URL + attributeName)
- .subscribe(data => {
- Object.keys(data)
- .forEach(dataKey => {
- hashToPopulate.push({
- id: parseInt(dataKey, 10),
- label: data[dataKey]
- })
- })
-
- notifier.next(true)
- })
+ return this.getServerLocale()
+ .pipe(
+ switchMap(translations => {
+ return this.http.get<{ [ id: string ]: string }>(baseUrl + attributeName)
+ .pipe(map(data => ({ data, translations })))
+ }),
+ map(({ data, translations }) => {
+ const hashToPopulate: VideoConstant<T>[] = []
+
+ Object.keys(data)
+ .forEach(dataKey => {
+ const label = data[ dataKey ]
+
+ hashToPopulate.push({
+ id: (attributeName === 'languages' ? dataKey : parseInt(dataKey, 10)) as T,
+ label: peertubeTranslate(label, translations)
+ })
+ })
+
+ if (sort === true) sortBy(hashToPopulate, 'label')
+
+ return hashToPopulate
+ }),
+ shareReplay()
+ )
+ }
+
+ private saveConfigLocally (config: ServerConfig) {
+ peertubeLocalStorage.setItem(ServerService.CONFIG_LOCAL_STORAGE_KEY, JSON.stringify(config))
+ }
+
+ private loadConfigLocally () {
+ const configString = peertubeLocalStorage.getItem(ServerService.CONFIG_LOCAL_STORAGE_KEY)
+
+ if (configString) {
+ try {
+ const parsed = JSON.parse(configString)
+ Object.assign(this.config, parsed)
+ } catch (err) {
+ console.error('Cannot parse config saved in local storage.', err)
+ }
+ }