diff options
Diffstat (limited to 'server/initializers/config.ts')
-rw-r--r-- | server/initializers/config.ts | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/server/initializers/config.ts b/server/initializers/config.ts index 7fd77f3e8..6932b41e1 100644 --- a/server/initializers/config.ts +++ b/server/initializers/config.ts | |||
@@ -1,10 +1,11 @@ | |||
1 | import { IConfig } from 'config' | 1 | import { IConfig } from 'config' |
2 | import { dirname, join } from 'path' | 2 | import { dirname, join } from 'path' |
3 | import { VideosRedundancy } from '../../shared/models' | 3 | import { VideosRedundancyStrategy } from '../../shared/models' |
4 | // Do not use barrels, remain constants as independent as possible | 4 | // Do not use barrels, remain constants as independent as possible |
5 | import { buildPath, parseBytes, parseDurationToMs, root } from '../helpers/core-utils' | 5 | import { buildPath, parseBytes, parseDurationToMs, root } from '../helpers/core-utils' |
6 | import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' | 6 | import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' |
7 | import * as bytes from 'bytes' | 7 | import * as bytes from 'bytes' |
8 | import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type' | ||
8 | 9 | ||
9 | // Use a variable to reload the configuration if we need | 10 | // Use a variable to reload the configuration if we need |
10 | let config: IConfig = require('config') | 11 | let config: IConfig = require('config') |
@@ -35,6 +36,8 @@ const CONFIG = { | |||
35 | DB: config.has('redis.db') ? config.get<number>('redis.db') : null | 36 | DB: config.has('redis.db') ? config.get<number>('redis.db') : null |
36 | }, | 37 | }, |
37 | SMTP: { | 38 | SMTP: { |
39 | TRANSPORT: config.has('smtp.transport') ? config.get<string>('smtp.transport') : 'smtp', | ||
40 | SENDMAIL: config.has('smtp.sendmail') ? config.get<string>('smtp.sendmail') : null, | ||
38 | HOSTNAME: config.get<string>('smtp.hostname'), | 41 | HOSTNAME: config.get<string>('smtp.hostname'), |
39 | PORT: config.get<number>('smtp.port'), | 42 | PORT: config.get<number>('smtp.port'), |
40 | USERNAME: config.get<string>('smtp.username'), | 43 | USERNAME: config.get<string>('smtp.username'), |
@@ -117,6 +120,11 @@ const CONFIG = { | |||
117 | STRATEGIES: buildVideosRedundancy(config.get<any[]>('redundancy.videos.strategies')) | 120 | STRATEGIES: buildVideosRedundancy(config.get<any[]>('redundancy.videos.strategies')) |
118 | } | 121 | } |
119 | }, | 122 | }, |
123 | REMOTE_REDUNDANCY: { | ||
124 | VIDEOS: { | ||
125 | ACCEPT_FROM: config.get<VideoRedundancyConfigFilter>('remote_redundancy.videos.accept_from') | ||
126 | } | ||
127 | }, | ||
120 | CSP: { | 128 | CSP: { |
121 | ENABLED: config.get<boolean>('csp.enabled'), | 129 | ENABLED: config.get<boolean>('csp.enabled'), |
122 | REPORT_ONLY: config.get<boolean>('csp.report_only'), | 130 | REPORT_ONLY: config.get<boolean>('csp.report_only'), |
@@ -284,11 +292,16 @@ function registerConfigChangedHandler (fun: Function) { | |||
284 | configChangedHandlers.push(fun) | 292 | configChangedHandlers.push(fun) |
285 | } | 293 | } |
286 | 294 | ||
295 | function isEmailEnabled () { | ||
296 | return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT | ||
297 | } | ||
298 | |||
287 | // --------------------------------------------------------------------------- | 299 | // --------------------------------------------------------------------------- |
288 | 300 | ||
289 | export { | 301 | export { |
290 | CONFIG, | 302 | CONFIG, |
291 | registerConfigChangedHandler | 303 | registerConfigChangedHandler, |
304 | isEmailEnabled | ||
292 | } | 305 | } |
293 | 306 | ||
294 | // --------------------------------------------------------------------------- | 307 | // --------------------------------------------------------------------------- |
@@ -301,10 +314,10 @@ function getLocalConfigFilePath () { | |||
301 | if (process.env.NODE_ENV) filename += `-${process.env.NODE_ENV}` | 314 | if (process.env.NODE_ENV) filename += `-${process.env.NODE_ENV}` |
302 | if (process.env.NODE_APP_INSTANCE) filename += `-${process.env.NODE_APP_INSTANCE}` | 315 | if (process.env.NODE_APP_INSTANCE) filename += `-${process.env.NODE_APP_INSTANCE}` |
303 | 316 | ||
304 | return join(dirname(configSources[ 0 ].name), filename + '.json') | 317 | return join(dirname(configSources[0].name), filename + '.json') |
305 | } | 318 | } |
306 | 319 | ||
307 | function buildVideosRedundancy (objs: any[]): VideosRedundancy[] { | 320 | function buildVideosRedundancy (objs: any[]): VideosRedundancyStrategy[] { |
308 | if (!objs) return [] | 321 | if (!objs) return [] |
309 | 322 | ||
310 | if (!Array.isArray(objs)) return objs | 323 | if (!Array.isArray(objs)) return objs |
@@ -330,7 +343,7 @@ export function reloadConfig () { | |||
330 | 343 | ||
331 | function purge () { | 344 | function purge () { |
332 | for (const fileName in require.cache) { | 345 | for (const fileName in require.cache) { |
333 | if (-1 === fileName.indexOf(directory())) { | 346 | if (fileName.includes(directory()) === false) { |
334 | continue | 347 | continue |
335 | } | 348 | } |
336 | 349 | ||