diff options
author | Chocobozzz <me@florianbigard.com> | 2021-05-14 12:04:44 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-05-14 13:37:23 +0200 |
commit | aea0b0e7cde7495e60fe07b4444067f53d35ce3f (patch) | |
tree | 61d1e161bb32be144d46b9f5f51f1386e6819b0b /server/lib/config.ts | |
parent | c76ecc3ff746d78519404db4c525fd024f9a51c0 (diff) | |
download | PeerTube-aea0b0e7cde7495e60fe07b4444067f53d35ce3f.tar.gz PeerTube-aea0b0e7cde7495e60fe07b4444067f53d35ce3f.tar.zst PeerTube-aea0b0e7cde7495e60fe07b4444067f53d35ce3f.zip |
Inject server config in HTML
Diffstat (limited to 'server/lib/config.ts')
-rw-r--r-- | server/lib/config.ts | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/server/lib/config.ts b/server/lib/config.ts index fed468fe1..18d49f05a 100644 --- a/server/lib/config.ts +++ b/server/lib/config.ts | |||
@@ -2,17 +2,13 @@ import { isSignupAllowed, isSignupAllowedForCurrentIP } from '@server/helpers/si | |||
2 | import { getServerCommit } from '@server/helpers/utils' | 2 | import { getServerCommit } from '@server/helpers/utils' |
3 | import { CONFIG, isEmailEnabled } from '@server/initializers/config' | 3 | import { CONFIG, isEmailEnabled } from '@server/initializers/config' |
4 | import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '@server/initializers/constants' | 4 | import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '@server/initializers/constants' |
5 | import { RegisteredExternalAuthConfig, RegisteredIdAndPassAuthConfig, ServerConfig } from '@shared/models' | 5 | import { HTMLServerConfig, RegisteredExternalAuthConfig, RegisteredIdAndPassAuthConfig, ServerConfig } from '@shared/models' |
6 | import { Hooks } from './plugins/hooks' | 6 | import { Hooks } from './plugins/hooks' |
7 | import { PluginManager } from './plugins/plugin-manager' | 7 | import { PluginManager } from './plugins/plugin-manager' |
8 | import { getThemeOrDefault } from './plugins/theme-utils' | 8 | import { getThemeOrDefault } from './plugins/theme-utils' |
9 | import { VideoTranscodingProfilesManager } from './transcoding/video-transcoding-profiles' | 9 | import { VideoTranscodingProfilesManager } from './transcoding/video-transcoding-profiles' |
10 | 10 | ||
11 | let serverCommit: string | ||
12 | |||
13 | async function getServerConfig (ip?: string): Promise<ServerConfig> { | 11 | async function getServerConfig (ip?: string): Promise<ServerConfig> { |
14 | if (serverCommit === undefined) serverCommit = await getServerCommit() | ||
15 | |||
16 | const { allowed } = await Hooks.wrapPromiseFun( | 12 | const { allowed } = await Hooks.wrapPromiseFun( |
17 | isSignupAllowed, | 13 | isSignupAllowed, |
18 | { | 14 | { |
@@ -22,6 +18,23 @@ async function getServerConfig (ip?: string): Promise<ServerConfig> { | |||
22 | ) | 18 | ) |
23 | 19 | ||
24 | 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 | ||
34 | let serverCommit: string | ||
35 | async function getHTMLServerConfig (): Promise<HTMLServerConfig> { | ||
36 | if (serverCommit === undefined) serverCommit = await getServerCommit() | ||
37 | |||
25 | const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME) | 38 | const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME) |
26 | 39 | ||
27 | return { | 40 | return { |
@@ -65,11 +78,6 @@ async function getServerConfig (ip?: string): Promise<ServerConfig> { | |||
65 | }, | 78 | }, |
66 | serverVersion: PEERTUBE_VERSION, | 79 | serverVersion: PEERTUBE_VERSION, |
67 | serverCommit, | 80 | serverCommit, |
68 | signup: { | ||
69 | allowed, | ||
70 | allowedForCurrentIP, | ||
71 | requiresEmailVerification: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION | ||
72 | }, | ||
73 | transcoding: { | 81 | transcoding: { |
74 | hls: { | 82 | hls: { |
75 | enabled: CONFIG.TRANSCODING.HLS.ENABLED | 83 | enabled: CONFIG.TRANSCODING.HLS.ENABLED |
@@ -223,7 +231,8 @@ export { | |||
223 | getServerConfig, | 231 | getServerConfig, |
224 | getRegisteredThemes, | 232 | getRegisteredThemes, |
225 | getEnabledResolutions, | 233 | getEnabledResolutions, |
226 | getRegisteredPlugins | 234 | getRegisteredPlugins, |
235 | getHTMLServerConfig | ||
227 | } | 236 | } |
228 | 237 | ||
229 | // --------------------------------------------------------------------------- | 238 | // --------------------------------------------------------------------------- |