+ VIDEO_MIMETYPE_EXT,
+ VIDEO_TRANSCODING_FPS,
+ FFMPEG_NICE,
+ VIDEO_ABUSE_STATES,
+ JOB_REQUEST_TIMEOUT,
+ USER_PASSWORD_RESET_LIFETIME,
+ MEMOIZE_TTL,
+ USER_EMAIL_VERIFY_LIFETIME,
+ IMAGE_MIMETYPE_EXT,
+ OVERVIEWS,
+ SCHEDULER_INTERVALS_MS,
+ REPEAT_JOBS,
+ STATIC_DOWNLOAD_PATHS,
+ RATES_LIMIT,
+ VIDEO_EXT_MIMETYPE,
+ CRAWL_REQUEST_CONCURRENCY,
+ JOB_COMPLETED_LIFETIME,
+ VIDEO_IMPORT_STATES,
+ VIDEO_VIEW_LIFETIME,
+ buildLanguages
+}
+
+// ---------------------------------------------------------------------------
+
+function getLocalConfigFilePath () {
+ const configSources = config.util.getConfigSources()
+ if (configSources.length === 0) throw new Error('Invalid config source.')
+
+ let filename = 'local'
+ if (process.env.NODE_ENV) filename += `-${process.env.NODE_ENV}`
+ if (process.env.NODE_APP_INSTANCE) filename += `-${process.env.NODE_APP_INSTANCE}`
+
+ return join(dirname(configSources[ 0 ].name), filename + '.json')
+}
+
+function updateWebserverConfig () {
+ CONFIG.WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT)
+ CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP)
+}
+
+function buildVideosRedundancy (objs: VideosRedundancy[]): VideosRedundancy[] {
+ if (!objs) return []
+
+ return objs.map(obj => Object.assign(obj, { size: bytes.parse(obj.size) }))
+}
+
+function buildLanguages () {
+ const iso639 = require('iso-639-3')
+
+ const languages: { [ id: string ]: string } = {}
+
+ const additionalLanguages = {
+ 'sgn': true, // Sign languages (macro language)
+ 'ase': true, // American sign language
+ 'sdl': true, // Arabian sign language
+ 'bfi': true, // British sign language
+ 'bzs': true, // Brazilian sign language
+ 'csl': true, // Chinese sign language
+ 'cse': true, // Czech sign language
+ 'dsl': true, // Danish sign language
+ 'fsl': true, // French sign language
+ 'gsg': true, // German sign language
+ 'pks': true, // Pakistan sign language
+ 'jsl': true, // Japanese sign language
+ 'sfs': true, // South African sign language
+ 'swl': true, // Swedish sign language
+ 'rsl': true, // Russian sign language: true
+
+ 'epo': true, // Esperanto
+ 'tlh': true, // Klingon
+ 'jbo': true, // Lojban
+ 'avk': true // Kotava
+ }
+
+ // Only add ISO639-1 languages and some sign languages (ISO639-3)
+ iso639
+ .filter(l => {
+ return (l.iso6391 !== null && l.type === 'living') ||
+ additionalLanguages[l.iso6393] === true
+ })
+ .forEach(l => languages[l.iso6391 || l.iso6393] = l.name)
+
+ // Override Occitan label
+ languages['oc'] = 'Occitan'
+
+ return languages
+}
+
+export function reloadConfig () {
+
+ function directory () {
+ if (process.env.NODE_CONFIG_DIR) {
+ return process.env.NODE_CONFIG_DIR
+ }
+
+ return join(root(), 'config')
+ }
+
+ function purge () {
+ for (const fileName in require.cache) {
+ if (-1 === fileName.indexOf(directory())) {
+ continue
+ }
+
+ delete require.cache[fileName]
+ }
+
+ delete require.cache[require.resolve('config')]
+ }
+
+ purge()
+
+ config = require('config')
+
+ updateWebserverConfig()