import { IConfig } from 'config'
import { dirname, join } from 'path'
-import { VideosRedundancy } from '../../shared/models'
+import { VideosRedundancyStrategy } from '../../shared/models'
// Do not use barrels, remain constants as independent as possible
import { buildPath, parseBytes, parseDurationToMs, root } from '../helpers/core-utils'
import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type'
import * as bytes from 'bytes'
+import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type'
+import { BroadcastMessageLevel } from '@shared/models/server'
// Use a variable to reload the configuration if we need
let config: IConfig = require('config')
HOSTNAME: config.get<string>('listen.hostname')
},
DATABASE: {
- DBNAME: 'peertube' + config.get<string>('database.suffix'),
+ DBNAME: config.has('database.name') ? config.get<string>('database.name') : 'peertube' + config.get<string>('database.suffix'),
HOSTNAME: config.get<string>('database.hostname'),
PORT: config.get<number>('database.port'),
+ SSL: config.get<boolean>('database.ssl'),
USERNAME: config.get<string>('database.username'),
PASSWORD: config.get<string>('database.password'),
POOL: {
DB: config.has('redis.db') ? config.get<number>('redis.db') : null
},
SMTP: {
+ TRANSPORT: config.has('smtp.transport') ? config.get<string>('smtp.transport') : 'smtp',
+ SENDMAIL: config.has('smtp.sendmail') ? config.get<string>('smtp.sendmail') : null,
HOSTNAME: config.get<string>('smtp.hostname'),
PORT: config.get<number>('smtp.port'),
USERNAME: config.get<string>('smtp.username'),
CA_FILE: config.get<string>('smtp.ca_file'),
FROM_ADDRESS: config.get<string>('smtp.from_address')
},
+ EMAIL: {
+ BODY: {
+ SIGNATURE: config.get<string>('email.body.signature')
+ },
+ SUBJECT: {
+ PREFIX: config.get<string>('email.subject.prefix') + ' '
+ }
+ },
STORAGE: {
TMP_DIR: buildPath(config.get<string>('storage.tmp')),
AVATARS_DIR: buildPath(config.get<string>('storage.avatars')),
PREVIEWS_DIR: buildPath(config.get<string>('storage.previews')),
CAPTIONS_DIR: buildPath(config.get<string>('storage.captions')),
TORRENTS_DIR: buildPath(config.get<string>('storage.torrents')),
- CACHE_DIR: buildPath(config.get<string>('storage.cache'))
+ CACHE_DIR: buildPath(config.get<string>('storage.cache')),
+ PLUGINS_DIR: buildPath(config.get<string>('storage.plugins')),
+ CLIENT_OVERRIDES_DIR: buildPath(config.get<string>('storage.client_overrides'))
},
WEBSERVER: {
SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
HOSTNAME: config.get<string>('webserver.hostname'),
PORT: config.get<number>('webserver.port')
},
+ RATES_LIMIT: {
+ API: {
+ WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.api.window')),
+ MAX: config.get<number>('rates_limit.api.max')
+ },
+ SIGNUP: {
+ WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.signup.window')),
+ MAX: config.get<number>('rates_limit.signup.max')
+ },
+ LOGIN: {
+ WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.login.window')),
+ MAX: config.get<number>('rates_limit.login.max')
+ },
+ ASK_SEND_EMAIL: {
+ WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.ask_send_email.window')),
+ MAX: config.get<number>('rates_limit.ask_send_email.max')
+ }
+ },
TRUST_PROXY: config.get<string[]>('trust_proxy'),
LOG: {
- LEVEL: config.get<string>('log.level')
- },
- SEARCH: {
- REMOTE_URI: {
- USERS: config.get<boolean>('search.remote_uri.users'),
- ANONYMOUS: config.get<boolean>('search.remote_uri.anonymous')
- }
+ LEVEL: config.get<string>('log.level'),
+ ROTATION: {
+ ENABLED: config.get<boolean>('log.rotation.enabled'),
+ MAX_FILE_SIZE: bytes.parse(config.get<string>('log.rotation.maxFileSize')),
+ MAX_FILES: config.get<number>('log.rotation.maxFiles')
+ },
+ ANONYMIZE_IP: config.get<boolean>('log.anonymizeIP'),
+ LOG_PING_REQUESTS: config.get<boolean>('log.log_ping_requests'),
+ PRETTIFY_SQL: config.get<boolean>('log.prettify_sql')
},
TRENDING: {
VIDEOS: {
- INTERVAL_DAYS: config.get<number>('trending.videos.interval_days')
+ INTERVAL_DAYS: config.get<number>('trending.videos.interval_days'),
+ ALGORITHMS: {
+ get ENABLED () { return config.get<string[]>('trending.videos.algorithms.enabled') },
+ get DEFAULT () { return config.get<string>('trending.videos.algorithms.default') }
+ }
}
},
REDUNDANCY: {
STRATEGIES: buildVideosRedundancy(config.get<any[]>('redundancy.videos.strategies'))
}
},
+ REMOTE_REDUNDANCY: {
+ VIDEOS: {
+ ACCEPT_FROM: config.get<VideoRedundancyConfigFilter>('remote_redundancy.videos.accept_from')
+ }
+ },
CSP: {
ENABLED: config.get<boolean>('csp.enabled'),
REPORT_ONLY: config.get<boolean>('csp.report_only'),
- REPORT_URI: config.get<boolean>('csp.report_uri')
+ REPORT_URI: config.get<string>('csp.report_uri')
},
TRACKER: {
ENABLED: config.get<boolean>('tracker.enabled'),
}
}
},
+ PLUGINS: {
+ INDEX: {
+ ENABLED: config.get<boolean>('plugins.index.enabled'),
+ CHECK_LATEST_VERSIONS_INTERVAL: parseDurationToMs(config.get<string>('plugins.index.check_latest_versions_interval')),
+ URL: config.get<string>('plugins.index.url')
+ }
+ },
+ FEDERATION: {
+ VIDEOS: {
+ FEDERATE_UNLISTED: config.get<boolean>('federation.videos.federate_unlisted')
+ }
+ },
ADMIN: {
get EMAIL () { return config.get<string>('admin.email') }
},
TRANSCODING: {
get ENABLED () { return config.get<boolean>('transcoding.enabled') },
get ALLOW_ADDITIONAL_EXTENSIONS () { return config.get<boolean>('transcoding.allow_additional_extensions') },
+ get ALLOW_AUDIO_FILES () { return config.get<boolean>('transcoding.allow_audio_files') },
get THREADS () { return config.get<number>('transcoding.threads') },
+ get CONCURRENCY () { return config.get<number>('transcoding.concurrency') },
+ get PROFILE () { return config.get<string>('transcoding.profile') },
RESOLUTIONS: {
+ get '0p' () { return config.get<boolean>('transcoding.resolutions.0p') },
get '240p' () { return config.get<boolean>('transcoding.resolutions.240p') },
get '360p' () { return config.get<boolean>('transcoding.resolutions.360p') },
get '480p' () { return config.get<boolean>('transcoding.resolutions.480p') },
get '720p' () { return config.get<boolean>('transcoding.resolutions.720p') },
- get '1080p' () { return config.get<boolean>('transcoding.resolutions.1080p') }
+ get '1080p' () { return config.get<boolean>('transcoding.resolutions.1080p') },
+ get '1440p' () { return config.get<boolean>('transcoding.resolutions.1440p') },
+ get '2160p' () { return config.get<boolean>('transcoding.resolutions.2160p') }
},
HLS: {
get ENABLED () { return config.get<boolean>('transcoding.hls.enabled') }
+ },
+ WEBTORRENT: {
+ get ENABLED () { return config.get<boolean>('transcoding.webtorrent.enabled') }
+ }
+ },
+ LIVE: {
+ get ENABLED () { return config.get<boolean>('live.enabled') },
+
+ get MAX_DURATION () { return parseDurationToMs(config.get<string>('live.max_duration')) },
+ get MAX_INSTANCE_LIVES () { return config.get<number>('live.max_instance_lives') },
+ get MAX_USER_LIVES () { return config.get<number>('live.max_user_lives') },
+
+ get ALLOW_REPLAY () { return config.get<boolean>('live.allow_replay') },
+
+ RTMP: {
+ get PORT () { return config.get<number>('live.rtmp.port') }
+ },
+
+ TRANSCODING: {
+ get ENABLED () { return config.get<boolean>('live.transcoding.enabled') },
+ get THREADS () { return config.get<number>('live.transcoding.threads') },
+ get PROFILE () { return config.get<string>('live.transcoding.profile') },
+
+ RESOLUTIONS: {
+ get '240p' () { return config.get<boolean>('live.transcoding.resolutions.240p') },
+ get '360p' () { return config.get<boolean>('live.transcoding.resolutions.360p') },
+ get '480p' () { return config.get<boolean>('live.transcoding.resolutions.480p') },
+ get '720p' () { return config.get<boolean>('live.transcoding.resolutions.720p') },
+ get '1080p' () { return config.get<boolean>('live.transcoding.resolutions.1080p') },
+ get '1440p' () { return config.get<boolean>('live.transcoding.resolutions.1440p') },
+ get '2160p' () { return config.get<boolean>('live.transcoding.resolutions.2160p') }
+ }
}
},
IMPORT: {
VIDEOS: {
+ get CONCURRENCY () { return config.get<number>('import.videos.concurrency') },
+
HTTP: {
- get ENABLED () { return config.get<boolean>('import.videos.http.enabled') }
+ get ENABLED () { return config.get<boolean>('import.videos.http.enabled') },
+ get FORCE_IPV4 () { return config.get<boolean>('import.videos.http.force_ipv4') },
+ PROXY: {
+ get ENABLED () { return config.get<boolean>('import.videos.http.proxy.enabled') },
+ get URL () { return config.get<string>('import.videos.http.proxy.url') }
+ }
},
TORRENT: {
get ENABLED () { return config.get<boolean>('import.videos.torrent.enabled') }
},
VIDEO_CAPTIONS: {
get SIZE () { return config.get<number>('cache.captions.size') }
+ },
+ TORRENTS: {
+ get SIZE () { return config.get<number>('cache.torrents.size') }
}
},
INSTANCE: {
get SHORT_DESCRIPTION () { return config.get<string>('instance.short_description') },
get DESCRIPTION () { return config.get<string>('instance.description') },
get TERMS () { return config.get<string>('instance.terms') },
+ get CODE_OF_CONDUCT () { return config.get<string>('instance.code_of_conduct') },
+
+ get CREATION_REASON () { return config.get<string>('instance.creation_reason') },
+
+ get MODERATION_INFORMATION () { return config.get<string>('instance.moderation_information') },
+ get ADMINISTRATOR () { return config.get<string>('instance.administrator') },
+ get MAINTENANCE_LIFETIME () { return config.get<string>('instance.maintenance_lifetime') },
+ get BUSINESS_MODEL () { return config.get<string>('instance.business_model') },
+ get HARDWARE_INFORMATION () { return config.get<string>('instance.hardware_information') },
+
+ get LANGUAGES () { return config.get<string[]>('instance.languages') || [] },
+ get CATEGORIES () { return config.get<number[]>('instance.categories') || [] },
+
get IS_NSFW () { return config.get<boolean>('instance.is_nsfw') },
- get DEFAULT_CLIENT_ROUTE () { return config.get<string>('instance.default_client_route') },
get DEFAULT_NSFW_POLICY () { return config.get<NSFWPolicyType>('instance.default_nsfw_policy') },
+
+ get DEFAULT_CLIENT_ROUTE () { return config.get<string>('instance.default_client_route') },
+
CUSTOMIZATIONS: {
get JAVASCRIPT () { return config.get<string>('instance.customizations.javascript') },
get CSS () { return config.get<string>('instance.customizations.css') }
get ENABLED () { return config.get<boolean>('followers.instance.enabled') },
get MANUAL_APPROVAL () { return config.get<boolean>('followers.instance.manual_approval') }
}
+ },
+ FOLLOWINGS: {
+ INSTANCE: {
+ AUTO_FOLLOW_BACK: {
+ get ENABLED () {
+ return config.get<boolean>('followings.instance.auto_follow_back.enabled')
+ }
+ },
+ AUTO_FOLLOW_INDEX: {
+ get ENABLED () {
+ return config.get<boolean>('followings.instance.auto_follow_index.enabled')
+ },
+ get INDEX_URL () {
+ return config.get<string>('followings.instance.auto_follow_index.index_url')
+ }
+ }
+ }
+ },
+ THEME: {
+ get DEFAULT () { return config.get<string>('theme.default') }
+ },
+ BROADCAST_MESSAGE: {
+ get ENABLED () { return config.get<boolean>('broadcast_message.enabled') },
+ get MESSAGE () { return config.get<string>('broadcast_message.message') },
+ get LEVEL () { return config.get<BroadcastMessageLevel>('broadcast_message.level') },
+ get DISMISSABLE () { return config.get<boolean>('broadcast_message.dismissable') }
+ },
+ SEARCH: {
+ REMOTE_URI: {
+ get USERS () { return config.get<boolean>('search.remote_uri.users') },
+ get ANONYMOUS () { return config.get<boolean>('search.remote_uri.anonymous') }
+ },
+ SEARCH_INDEX: {
+ get ENABLED () { return config.get<boolean>('search.search_index.enabled') },
+ get URL () { return config.get<string>('search.search_index.url') },
+ get DISABLE_LOCAL_SEARCH () { return config.get<boolean>('search.search_index.disable_local_search') },
+ get IS_DEFAULT_SEARCH () { return config.get<boolean>('search.search_index.is_default_search') }
+ }
}
}
configChangedHandlers.push(fun)
}
+function isEmailEnabled () {
+ if (CONFIG.SMTP.TRANSPORT === 'sendmail' && CONFIG.SMTP.SENDMAIL) return true
+
+ if (CONFIG.SMTP.TRANSPORT === 'smtp' && CONFIG.SMTP.HOSTNAME && CONFIG.SMTP.PORT) return true
+
+ return false
+}
+
// ---------------------------------------------------------------------------
export {
CONFIG,
- registerConfigChangedHandler
+ registerConfigChangedHandler,
+ isEmailEnabled
}
// ---------------------------------------------------------------------------
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')
+ return join(dirname(configSources[0].name), filename + '.json')
}
-function buildVideosRedundancy (objs: any[]): VideosRedundancy[] {
+function buildVideosRedundancy (objs: any[]): VideosRedundancyStrategy[] {
if (!objs) return []
if (!Array.isArray(objs)) return objs
function purge () {
for (const fileName in require.cache) {
- if (-1 === fileName.indexOf(directory())) {
+ if (fileName.includes(directory()) === false) {
continue
}