X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fcore%2Fserver%2Fserver.service.ts;h=c868ccdcc26abc8e6a746234398fa6bab5339ed4;hb=092092969633bbcf6d4891a083ea497a7d5c3154;hp=56d33339ebdf0e663df98506efa92ce0ac7c04e9;hpb=7ce44a74a3b052190cfacd4bd5ee6b92cfc620ac;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.ts index 56d33339e..c868ccdcc 100644 --- a/client/src/app/core/server/server.service.ts +++ b/client/src/app/core/server/server.service.ts @@ -1,17 +1,19 @@ -import { map, share, switchMap, tap } from 'rxjs/operators' +import { map, shareReplay, switchMap, tap } from 'rxjs/operators' import { HttpClient } from '@angular/common/http' import { Inject, Injectable, LOCALE_ID } from '@angular/core' import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' -import { Observable, ReplaySubject } from 'rxjs' -import { ServerConfig } from '../../../../../shared' +import { Observable, of, ReplaySubject } from 'rxjs' +import { getCompleteLocale, ServerConfig } from '../../../../../shared' import { About } from '../../../../../shared/models/server/about.model' import { environment } from '../../../environments/environment' import { VideoConstant, VideoPrivacy } from '../../../../../shared/models/videos' -import { buildFileLocale, getDefaultLocale } from '../../../../../shared/models/i18n' -import { peertubeTranslate } from '@app/shared/i18n/i18n-utils' +import { isDefaultLocale, peertubeTranslate } from '../../../../../shared/models/i18n' +import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' +import { sortBy } from '@app/shared/misc/utils' @Injectable() export class ServerService { + private static BASE_SERVER_URL = environment.apiUrl + '/api/v1/server/' private static BASE_CONFIG_URL = environment.apiUrl + '/api/v1/config/' private static BASE_VIDEO_URL = environment.apiUrl + '/api/v1/videos/' private static BASE_LOCALE_URL = environment.apiUrl + '/client/locales/' @@ -36,13 +38,23 @@ export class ServerService { css: '' } }, + email: { + enabled: false + }, + contactForm: { + enabled: false + }, serverVersion: 'Unknown', signup: { allowed: false, - allowedForCurrentIP: false + allowedForCurrentIP: false, + requiresEmailVerification: false }, transcoding: { - enabledResolutions: [] + enabledResolutions: [], + hls: { + enabled: false + } }, avatar: { file: { @@ -59,8 +71,30 @@ export class ServerService { extensions: [] } }, + videoCaption: { + file: { + size: { max: 0 }, + extensions: [] + } + }, user: { - videoQuota: -1 + videoQuota: -1, + videoQuotaDaily: -1 + }, + import: { + videos: { + http: { + enabled: false + }, + torrent: { + enabled: false + } + } + }, + trending: { + videos: { + intervalDays: 0 + } } } private videoCategories: Array> = [] @@ -72,8 +106,8 @@ export class ServerService { private http: HttpClient, @Inject(LOCALE_ID) private localeId: string ) { - this.loadConfigLocally() this.loadServerLocale() + this.loadConfigLocally() } loadConfig () { @@ -122,20 +156,16 @@ export class ServerService { return this.videoPrivacies } - getAbout () { - return this.http.get(ServerService.BASE_CONFIG_URL + '/about') - } - private loadVideoAttributeEnum ( attributeName: 'categories' | 'licences' | 'languages' | 'privacies', - hashToPopulate: VideoConstant[], + hashToPopulate: VideoConstant[], notifier: ReplaySubject, sort = false ) { this.localeObservable .pipe( switchMap(translations => { - return this.http.get(ServerService.BASE_VIDEO_URL + attributeName) + return this.http.get<{ [id: string]: string }>(ServerService.BASE_VIDEO_URL + attributeName) .pipe(map(data => ({ data, translations }))) }) ) @@ -145,33 +175,29 @@ export class ServerService { const label = data[ dataKey ] hashToPopulate.push({ - id: dataKey, + id: attributeName === 'languages' ? dataKey : parseInt(dataKey, 10), label: peertubeTranslate(label, translations) }) }) - if (sort === true) { - hashToPopulate.sort((a, b) => { - if (a.label < b.label) return -1 - if (a.label === b.label) return 0 - return 1 - }) - } + if (sort === true) sortBy(hashToPopulate, 'label') notifier.next(true) }) } private loadServerLocale () { - const fileLocale = buildFileLocale(environment.production === true ? this.localeId : 'fr') + const completeLocale = isOnDevLocale() ? getDevLocale() : getCompleteLocale(this.localeId) // Default locale, nothing to translate - const defaultFileLocale = buildFileLocale(getDefaultLocale()) - if (fileLocale === defaultFileLocale) return {} + if (isDefaultLocale(completeLocale)) { + this.localeObservable = of({}).pipe(shareReplay()) + return + } this.localeObservable = this.http - .get(ServerService.BASE_LOCALE_URL + fileLocale + '/server.json') - .pipe(share()) + .get(ServerService.BASE_LOCALE_URL + completeLocale + '/server.json') + .pipe(shareReplay()) } private saveConfigLocally (config: ServerConfig) {