-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 { VideoConstant } from '../../../../../shared/models/videos'
+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 {
serverVersion: 'Unknown',
signup: {
allowed: false,
- allowedForCurrentIP: false
+ allowedForCurrentIP: false,
+ requiresEmailVerification: false
},
transcoding: {
enabledResolutions: []
extensions: []
}
},
+ videoCaption: {
+ file: {
+ size: { max: 0 },
+ extensions: []
+ }
+ },
user: {
- videoQuota: -1
+ videoQuota: -1,
+ videoQuotaDaily: -1
+ },
+ import: {
+ videos: {
+ http: {
+ enabled: false
+ },
+ torrent: {
+ enabled: false
+ }
+ }
}
}
- private videoCategories: Array<VideoConstant<number>> = []
- private videoLicences: Array<VideoConstant<number>> = []
+ private videoCategories: Array<VideoConstant<string>> = []
+ private videoLicences: Array<VideoConstant<string>> = []
private videoLanguages: Array<VideoConstant<string>> = []
- private videoPrivacies: Array<VideoConstant<VideoPrivacy>> = []
+ private videoPrivacies: Array<VideoConstant<string>> = []
constructor (
private http: HttpClient,
@Inject(LOCALE_ID) private localeId: string
) {
- this.loadConfigLocally()
this.loadServerLocale()
+ this.loadConfigLocally()
}
loadConfig () {
private loadVideoAttributeEnum (
attributeName: 'categories' | 'licences' | 'languages' | 'privacies',
- hashToPopulate: VideoConstant<number | string>[],
+ hashToPopulate: VideoConstant<string>[],
notifier: ReplaySubject<boolean>,
sort = false
) {
})
})
- 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) {