aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/config.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/config.ts')
-rw-r--r--server/lib/config.ts45
1 files changed, 32 insertions, 13 deletions
diff --git a/server/lib/config.ts b/server/lib/config.ts
index b4c4c9299..18d49f05a 100644
--- a/server/lib/config.ts
+++ b/server/lib/config.ts
@@ -2,18 +2,13 @@ import { isSignupAllowed, isSignupAllowedForCurrentIP } from '@server/helpers/si
2import { getServerCommit } from '@server/helpers/utils' 2import { getServerCommit } from '@server/helpers/utils'
3import { CONFIG, isEmailEnabled } from '@server/initializers/config' 3import { CONFIG, isEmailEnabled } from '@server/initializers/config'
4import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '@server/initializers/constants' 4import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '@server/initializers/constants'
5import { RegisteredExternalAuthConfig, RegisteredIdAndPassAuthConfig, ServerConfig } from '@shared/models' 5import { HTMLServerConfig, RegisteredExternalAuthConfig, RegisteredIdAndPassAuthConfig, ServerConfig } from '@shared/models'
6import { Hooks } from './plugins/hooks' 6import { Hooks } from './plugins/hooks'
7import { PluginManager } from './plugins/plugin-manager' 7import { PluginManager } from './plugins/plugin-manager'
8import { getThemeOrDefault } from './plugins/theme-utils' 8import { getThemeOrDefault } from './plugins/theme-utils'
9import { getEnabledResolutions } from './video-transcoding' 9import { VideoTranscodingProfilesManager } from './transcoding/video-transcoding-profiles'
10import { VideoTranscodingProfilesManager } from './video-transcoding-profiles'
11
12let serverCommit: string
13 10
14async function getServerConfig (ip?: string): Promise<ServerConfig> { 11async function getServerConfig (ip?: string): Promise<ServerConfig> {
15 if (serverCommit === undefined) serverCommit = await getServerCommit()
16
17 const { allowed } = await Hooks.wrapPromiseFun( 12 const { allowed } = await Hooks.wrapPromiseFun(
18 isSignupAllowed, 13 isSignupAllowed,
19 { 14 {
@@ -23,6 +18,23 @@ async function getServerConfig (ip?: string): Promise<ServerConfig> {
23 ) 18 )
24 19
25 const allowedForCurrentIP = isSignupAllowedForCurrentIP(ip) 20 const allowedForCurrentIP = isSignupAllowedForCurrentIP(ip)
21
22 const signup = {
23 allowed,
24 allowedForCurrentIP,
25 requiresEmailVerification: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION
26 }
27
28 const htmlConfig = await getHTMLServerConfig()
29
30 return { ...htmlConfig, signup }
31}
32
33// Config injected in HTML
34let serverCommit: string
35async function getHTMLServerConfig (): Promise<HTMLServerConfig> {
36 if (serverCommit === undefined) serverCommit = await getServerCommit()
37
26 const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME) 38 const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME)
27 39
28 return { 40 return {
@@ -66,11 +78,6 @@ async function getServerConfig (ip?: string): Promise<ServerConfig> {
66 }, 78 },
67 serverVersion: PEERTUBE_VERSION, 79 serverVersion: PEERTUBE_VERSION,
68 serverCommit, 80 serverCommit,
69 signup: {
70 allowed,
71 allowedForCurrentIP,
72 requiresEmailVerification: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION
73 },
74 transcoding: { 81 transcoding: {
75 hls: { 82 hls: {
76 enabled: CONFIG.TRANSCODING.HLS.ENABLED 83 enabled: CONFIG.TRANSCODING.HLS.ENABLED
@@ -208,12 +215,24 @@ function getRegisteredPlugins () {
208 })) 215 }))
209} 216}
210 217
218function getEnabledResolutions (type: 'vod' | 'live') {
219 const transcoding = type === 'vod'
220 ? CONFIG.TRANSCODING
221 : CONFIG.LIVE.TRANSCODING
222
223 return Object.keys(transcoding.RESOLUTIONS)
224 .filter(key => transcoding.ENABLED && transcoding.RESOLUTIONS[key] === true)
225 .map(r => parseInt(r, 10))
226}
227
211// --------------------------------------------------------------------------- 228// ---------------------------------------------------------------------------
212 229
213export { 230export {
214 getServerConfig, 231 getServerConfig,
215 getRegisteredThemes, 232 getRegisteredThemes,
216 getRegisteredPlugins 233 getEnabledResolutions,
234 getRegisteredPlugins,
235 getHTMLServerConfig
217} 236}
218 237
219// --------------------------------------------------------------------------- 238// ---------------------------------------------------------------------------