1
0
Fork 0
peertube/server/core/initializers/config.ts

706 lines
28 KiB
TypeScript
Raw Normal View History

2021-08-27 08:32:44 -04:00
import bytes from 'bytes'
2019-04-11 05:33:44 -04:00
import { IConfig } from 'config'
import { createRequire } from 'module'
2019-04-11 05:33:44 -04:00
import { dirname, join } from 'path'
import {
BroadcastMessageLevel,
NSFWPolicyType,
VideoPrivacyType,
VideoRedundancyConfigFilter,
VideosRedundancyStrategy
} from '@peertube/peertube-models'
import { decacheModule } from '@server/helpers/decache.js'
import { buildPath, root } from '@peertube/peertube-node-utils'
import { parseBytes, parseDurationToMs } from '../helpers/core-utils.js'
const require = createRequire(import.meta.url)
2019-04-11 05:33:44 -04:00
let config: IConfig = require('config')
const configChangedHandlers: Function[] = []
const CONFIG = {
CUSTOM_FILE: getLocalConfigFilePath(),
LISTEN: {
PORT: config.get<number>('listen.port'),
HOSTNAME: config.get<string>('listen.hostname')
},
2022-10-10 05:12:23 -04:00
SECRETS: {
PEERTUBE: config.get<string>('secrets.peertube')
},
2019-04-11 05:33:44 -04:00
DATABASE: {
DBNAME: config.has('database.name') ? config.get<string>('database.name') : 'peertube' + config.get<string>('database.suffix'),
2019-04-11 05:33:44 -04:00
HOSTNAME: config.get<string>('database.hostname'),
PORT: config.get<number>('database.port'),
2020-08-24 05:38:57 -04:00
SSL: config.get<boolean>('database.ssl'),
2019-04-11 05:33:44 -04:00
USERNAME: config.get<string>('database.username'),
PASSWORD: config.get<string>('database.password'),
POOL: {
MAX: config.get<number>('database.pool.max')
}
},
REDIS: {
HOSTNAME: config.has('redis.hostname') ? config.get<string>('redis.hostname') : null,
PORT: config.has('redis.port') ? config.get<number>('redis.port') : null,
SOCKET: config.has('redis.socket') ? config.get<string>('redis.socket') : null,
AUTH: config.has('redis.auth') ? config.get<string>('redis.auth') : null,
DB: config.has('redis.db') ? config.get<number>('redis.db') : null,
SENTINEL: {
ENABLED: config.has('redis.sentinel.enabled') ? config.get<boolean>('redis.sentinel.enabled') : false,
ENABLE_TLS: config.has('redis.sentinel.enable_tls') ? config.get<boolean>('redis.sentinel.enable_tls') : false,
SENTINELS: config.has('redis.sentinel.sentinels') ? config.get<{ hostname: string, port: number }[]>('redis.sentinel.sentinels') : [],
MASTER_NAME: config.has('redis.sentinel.master_name') ? config.get<string>('redis.sentinel.master_name') : null
}
2019-04-11 05:33:44 -04:00
},
SMTP: {
2019-02-13 06:16:27 -05:00
TRANSPORT: config.has('smtp.transport') ? config.get<string>('smtp.transport') : 'smtp',
SENDMAIL: config.has('smtp.sendmail') ? config.get<string>('smtp.sendmail') : null,
2019-04-11 05:33:44 -04:00
HOSTNAME: config.get<string>('smtp.hostname'),
PORT: config.get<number>('smtp.port'),
USERNAME: config.get<string>('smtp.username'),
PASSWORD: config.get<string>('smtp.password'),
TLS: config.get<boolean>('smtp.tls'),
DISABLE_STARTTLS: config.get<boolean>('smtp.disable_starttls'),
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')
},
2019-08-22 04:22:01 -04:00
SUBJECT: {
PREFIX: config.get<string>('email.subject.prefix') + ' '
}
},
CLIENT: {
VIDEOS: {
MINIATURE: {
get PREFER_AUTHOR_DISPLAY_NAME () { return config.get<boolean>('client.videos.miniature.prefer_author_display_name') },
get DISPLAY_AUTHOR_AVATAR () { return config.get<boolean>('client.videos.miniature.display_author_avatar') }
},
RESUMABLE_UPLOAD: {
get MAX_CHUNK_SIZE () { return parseBytes(config.get<number>('client.videos.resumable_upload.max_chunk_size') || 0) }
}
},
MENU: {
LOGIN: {
get REDIRECT_ON_SINGLE_EXTERNAL_AUTH () { return config.get<boolean>('client.menu.login.redirect_on_single_external_auth') }
}
}
},
DEFAULTS: {
PUBLISH: {
DOWNLOAD_ENABLED: config.get<boolean>('defaults.publish.download_enabled'),
COMMENTS_ENABLED: config.get<boolean>('defaults.publish.comments_enabled'),
PRIVACY: config.get<VideoPrivacyType>('defaults.publish.privacy'),
LICENCE: config.get<number>('defaults.publish.licence')
},
P2P: {
WEBAPP: {
ENABLED: config.get<boolean>('defaults.p2p.webapp.enabled')
},
EMBED: {
ENABLED: config.get<boolean>('defaults.p2p.embed.enabled')
}
}
},
2019-04-11 05:33:44 -04:00
STORAGE: {
TMP_DIR: buildPath(config.get<string>('storage.tmp')),
TMP_PERSISTENT_DIR: buildPath(config.get<string>('storage.tmp_persistent')),
BIN_DIR: buildPath(config.get<string>('storage.bin')),
2023-07-11 05:23:51 -04:00
ACTOR_IMAGES_DIR: buildPath(config.get<string>('storage.avatars')),
2019-04-11 05:33:44 -04:00
LOG_DIR: buildPath(config.get<string>('storage.logs')),
2023-07-11 05:23:51 -04:00
WEB_VIDEOS_DIR: buildPath(config.get<string>('storage.web_videos')),
2019-04-11 05:33:44 -04:00
STREAMING_PLAYLISTS_DIR: buildPath(config.get<string>('storage.streaming_playlists')),
REDUNDANCY_DIR: buildPath(config.get<string>('storage.redundancy')),
THUMBNAILS_DIR: buildPath(config.get<string>('storage.thumbnails')),
2023-06-01 08:51:16 -04:00
STORYBOARDS_DIR: buildPath(config.get<string>('storage.storyboards')),
2019-04-11 05:33:44 -04:00
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')),
PLUGINS_DIR: buildPath(config.get<string>('storage.plugins')),
CLIENT_OVERRIDES_DIR: buildPath(config.get<string>('storage.client_overrides')),
WELL_KNOWN_DIR: buildPath(config.get<string>('storage.well_known'))
2019-04-11 05:33:44 -04:00
},
STATIC_FILES: {
PRIVATE_FILES_REQUIRE_AUTH: config.get<boolean>('static_files.private_files_require_auth')
},
Add support for saving video files to object storage (#4290) * Add support for saving video files to object storage * Add support for custom url generation on s3 stored files Uses two config keys to support url generation that doesn't directly go to (compatible s3). Can be used to generate urls to any cache server or CDN. * Upload files to s3 concurrently and delete originals afterwards * Only publish after move to object storage is complete * Use base url instead of url template * Fix mistyped config field * Add rudenmentary way to download before transcode * Implement Chocobozzz suggestions https://github.com/Chocobozzz/PeerTube/pull/4290#issuecomment-891670478 The remarks in question: Try to use objectStorage prefix instead of s3 prefix for your function/variables/config names Prefer to use a tree for the config: s3.streaming_playlists_bucket -> object_storage.streaming_playlists.bucket Use uppercase for config: S3.STREAMING_PLAYLISTS_BUCKETINFO.bucket -> OBJECT_STORAGE.STREAMING_PLAYLISTS.BUCKET (maybe BUCKET_NAME instead of BUCKET) I suggest to rename moveJobsRunning to pendingMovingJobs (or better, create a dedicated videoJobInfo table with a pendingMove & videoId columns so we could also use this table to track pending transcoding jobs) https://github.com/Chocobozzz/PeerTube/pull/4290/files#diff-3e26d41ca4bda1de8e1747af70ca2af642abcc1e9e0bfb94239ff2165acfbde5R19 uses a string instead of an integer I think we should store the origin object storage URL in fileUrl, without base_url injection. Instead, inject the base_url at "runtime" so admins can easily change this configuration without running a script to update DB URLs * Import correct function * Support multipart upload * Remove import of node 15.0 module stream/promises * Extend maximum upload job length Using the same value as for redundancy downloading seems logical * Use dynamic part size for really large uploads Also adds very small part size for local testing * Fix decreasePendingMove query * Resolve various PR comments * Move to object storage after optimize * Make upload size configurable and increase default * Prune webtorrent files that are stored in object storage * Move files after transcoding jobs * Fix federation * Add video path manager * Support move to external storage job in client * Fix live object storage tests Co-authored-by: Chocobozzz <me@florianbigard.com>
2021-08-17 02:26:20 -04:00
OBJECT_STORAGE: {
ENABLED: config.get<boolean>('object_storage.enabled'),
MAX_UPLOAD_PART: bytes.parse(config.get<string>('object_storage.max_upload_part')),
ENDPOINT: config.get<string>('object_storage.endpoint'),
REGION: config.get<string>('object_storage.region'),
UPLOAD_ACL: {
PUBLIC: config.get<string>('object_storage.upload_acl.public'),
PRIVATE: config.get<string>('object_storage.upload_acl.private')
},
Add support for saving video files to object storage (#4290) * Add support for saving video files to object storage * Add support for custom url generation on s3 stored files Uses two config keys to support url generation that doesn't directly go to (compatible s3). Can be used to generate urls to any cache server or CDN. * Upload files to s3 concurrently and delete originals afterwards * Only publish after move to object storage is complete * Use base url instead of url template * Fix mistyped config field * Add rudenmentary way to download before transcode * Implement Chocobozzz suggestions https://github.com/Chocobozzz/PeerTube/pull/4290#issuecomment-891670478 The remarks in question: Try to use objectStorage prefix instead of s3 prefix for your function/variables/config names Prefer to use a tree for the config: s3.streaming_playlists_bucket -> object_storage.streaming_playlists.bucket Use uppercase for config: S3.STREAMING_PLAYLISTS_BUCKETINFO.bucket -> OBJECT_STORAGE.STREAMING_PLAYLISTS.BUCKET (maybe BUCKET_NAME instead of BUCKET) I suggest to rename moveJobsRunning to pendingMovingJobs (or better, create a dedicated videoJobInfo table with a pendingMove & videoId columns so we could also use this table to track pending transcoding jobs) https://github.com/Chocobozzz/PeerTube/pull/4290/files#diff-3e26d41ca4bda1de8e1747af70ca2af642abcc1e9e0bfb94239ff2165acfbde5R19 uses a string instead of an integer I think we should store the origin object storage URL in fileUrl, without base_url injection. Instead, inject the base_url at "runtime" so admins can easily change this configuration without running a script to update DB URLs * Import correct function * Support multipart upload * Remove import of node 15.0 module stream/promises * Extend maximum upload job length Using the same value as for redundancy downloading seems logical * Use dynamic part size for really large uploads Also adds very small part size for local testing * Fix decreasePendingMove query * Resolve various PR comments * Move to object storage after optimize * Make upload size configurable and increase default * Prune webtorrent files that are stored in object storage * Move files after transcoding jobs * Fix federation * Add video path manager * Support move to external storage job in client * Fix live object storage tests Co-authored-by: Chocobozzz <me@florianbigard.com>
2021-08-17 02:26:20 -04:00
CREDENTIALS: {
ACCESS_KEY_ID: config.get<string>('object_storage.credentials.access_key_id'),
SECRET_ACCESS_KEY: config.get<string>('object_storage.credentials.secret_access_key')
},
PROXY: {
PROXIFY_PRIVATE_FILES: config.get<boolean>('object_storage.proxy.proxify_private_files')
},
2023-07-11 05:23:51 -04:00
WEB_VIDEOS: {
BUCKET_NAME: config.get<string>('object_storage.web_videos.bucket_name'),
PREFIX: config.get<string>('object_storage.web_videos.prefix'),
BASE_URL: config.get<string>('object_storage.web_videos.base_url')
Add support for saving video files to object storage (#4290) * Add support for saving video files to object storage * Add support for custom url generation on s3 stored files Uses two config keys to support url generation that doesn't directly go to (compatible s3). Can be used to generate urls to any cache server or CDN. * Upload files to s3 concurrently and delete originals afterwards * Only publish after move to object storage is complete * Use base url instead of url template * Fix mistyped config field * Add rudenmentary way to download before transcode * Implement Chocobozzz suggestions https://github.com/Chocobozzz/PeerTube/pull/4290#issuecomment-891670478 The remarks in question: Try to use objectStorage prefix instead of s3 prefix for your function/variables/config names Prefer to use a tree for the config: s3.streaming_playlists_bucket -> object_storage.streaming_playlists.bucket Use uppercase for config: S3.STREAMING_PLAYLISTS_BUCKETINFO.bucket -> OBJECT_STORAGE.STREAMING_PLAYLISTS.BUCKET (maybe BUCKET_NAME instead of BUCKET) I suggest to rename moveJobsRunning to pendingMovingJobs (or better, create a dedicated videoJobInfo table with a pendingMove & videoId columns so we could also use this table to track pending transcoding jobs) https://github.com/Chocobozzz/PeerTube/pull/4290/files#diff-3e26d41ca4bda1de8e1747af70ca2af642abcc1e9e0bfb94239ff2165acfbde5R19 uses a string instead of an integer I think we should store the origin object storage URL in fileUrl, without base_url injection. Instead, inject the base_url at "runtime" so admins can easily change this configuration without running a script to update DB URLs * Import correct function * Support multipart upload * Remove import of node 15.0 module stream/promises * Extend maximum upload job length Using the same value as for redundancy downloading seems logical * Use dynamic part size for really large uploads Also adds very small part size for local testing * Fix decreasePendingMove query * Resolve various PR comments * Move to object storage after optimize * Make upload size configurable and increase default * Prune webtorrent files that are stored in object storage * Move files after transcoding jobs * Fix federation * Add video path manager * Support move to external storage job in client * Fix live object storage tests Co-authored-by: Chocobozzz <me@florianbigard.com>
2021-08-17 02:26:20 -04:00
},
STREAMING_PLAYLISTS: {
BUCKET_NAME: config.get<string>('object_storage.streaming_playlists.bucket_name'),
PREFIX: config.get<string>('object_storage.streaming_playlists.prefix'),
BASE_URL: config.get<string>('object_storage.streaming_playlists.base_url')
}
},
2019-04-11 05:33:44 -04:00
WEBSERVER: {
SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws',
HOSTNAME: config.get<string>('webserver.hostname'),
PORT: config.get<number>('webserver.port')
},
OAUTH2: {
TOKEN_LIFETIME: {
ACCESS_TOKEN: parseDurationToMs(config.get<string>('oauth2.token_lifetime.access_token')),
REFRESH_TOKEN: parseDurationToMs(config.get<string>('oauth2.token_lifetime.refresh_token'))
}
},
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')
},
RECEIVE_CLIENT_LOG: {
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.receive_client_log.window')),
MAX: config.get<number>('rates_limit.receive_client_log.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')
2023-07-25 09:18:10 -04:00
},
PLUGINS: {
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.plugins.window')),
MAX: config.get<number>('rates_limit.plugins.max')
},
WELL_KNOWN: {
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.well_known.window')),
MAX: config.get<number>('rates_limit.well_known.max')
},
FEEDS: {
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.feeds.window')),
MAX: config.get<number>('rates_limit.feeds.max')
},
ACTIVITY_PUB: {
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.activity_pub.window')),
MAX: config.get<number>('rates_limit.activity_pub.max')
},
CLIENT: {
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.client.window')),
MAX: config.get<number>('rates_limit.client.max')
}
},
2019-04-11 05:33:44 -04:00
TRUST_PROXY: config.get<string[]>('trust_proxy'),
LOG: {
LEVEL: config.get<string>('log.level'),
ROTATION: {
ENABLED: config.get<boolean>('log.rotation.enabled'),
MAX_FILE_SIZE: bytes.parse(config.get<string>('log.rotation.max_file_size')),
MAX_FILES: config.get<number>('log.rotation.max_files')
},
ANONYMIZE_IP: config.get<boolean>('log.anonymize_ip'),
LOG_PING_REQUESTS: config.get<boolean>('log.log_ping_requests'),
LOG_TRACKER_UNKNOWN_INFOHASH: config.get<boolean>('log.log_tracker_unknown_infohash'),
2023-10-24 04:57:41 -04:00
LOG_HTTP_REQUESTS: config.get<boolean>('log.log_http_requests'),
PRETTIFY_SQL: config.get<boolean>('log.prettify_sql'),
ACCEPT_CLIENT_LOG: config.get<boolean>('log.accept_client_log')
2019-04-11 05:33:44 -04:00
},
2022-07-05 09:43:21 -04:00
OPEN_TELEMETRY: {
METRICS: {
ENABLED: config.get<boolean>('open_telemetry.metrics.enabled'),
HTTP_REQUEST_DURATION: {
ENABLED: config.get<boolean>('open_telemetry.metrics.http_request_duration.enabled')
},
2022-07-05 09:43:21 -04:00
PROMETHEUS_EXPORTER: {
HOSTNAME: config.get<string>('open_telemetry.metrics.prometheus_exporter.hostname'),
2022-07-05 09:43:21 -04:00
PORT: config.get<number>('open_telemetry.metrics.prometheus_exporter.port')
}
},
TRACING: {
ENABLED: config.get<boolean>('open_telemetry.tracing.enabled'),
JAEGER_EXPORTER: {
ENDPOINT: config.get<string>('open_telemetry.tracing.jaeger_exporter.endpoint')
}
}
},
2019-04-11 05:33:44 -04:00
TRENDING: {
VIDEOS: {
2021-01-27 11:15:21 -05:00
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') }
}
2019-04-11 05:33:44 -04:00
}
},
REDUNDANCY: {
VIDEOS: {
CHECK_INTERVAL: parseDurationToMs(config.get<string>('redundancy.videos.check_interval')),
2019-04-11 05:33:44 -04:00
STRATEGIES: buildVideosRedundancy(config.get<any[]>('redundancy.videos.strategies'))
}
},
REMOTE_REDUNDANCY: {
VIDEOS: {
ACCEPT_FROM: config.get<VideoRedundancyConfigFilter>('remote_redundancy.videos.accept_from')
}
},
2019-04-11 05:33:44 -04:00
CSP: {
ENABLED: config.get<boolean>('csp.enabled'),
REPORT_ONLY: config.get<boolean>('csp.report_only'),
2020-08-25 07:54:59 -04:00
REPORT_URI: config.get<string>('csp.report_uri')
2019-04-11 05:33:44 -04:00
},
2021-04-12 09:33:54 -04:00
SECURITY: {
FRAMEGUARD: {
ENABLED: config.get<boolean>('security.frameguard.enabled')
2023-02-27 03:22:59 -05:00
},
POWERED_BY_HEADER: {
ENABLED: config.get<boolean>('security.powered_by_header.enabled')
2021-04-12 09:33:54 -04:00
}
},
2019-04-11 05:33:44 -04:00
TRACKER: {
ENABLED: config.get<boolean>('tracker.enabled'),
PRIVATE: config.get<boolean>('tracker.private'),
REJECT_TOO_MANY_ANNOUNCES: config.get<boolean>('tracker.reject_too_many_announces')
},
HISTORY: {
VIDEOS: {
MAX_AGE: parseDurationToMs(config.get('history.videos.max_age'))
}
},
2019-04-11 11:33:36 -04:00
VIEWS: {
VIDEOS: {
REMOTE: {
MAX_AGE: parseDurationToMs(config.get('views.videos.remote.max_age'))
},
LOCAL_BUFFER_UPDATE_INTERVAL: parseDurationToMs(config.get('views.videos.local_buffer_update_interval')),
IP_VIEW_EXPIRATION: parseDurationToMs(config.get('views.videos.ip_view_expiration'))
2019-04-11 11:33:36 -04:00
}
},
GEO_IP: {
ENABLED: config.get<boolean>('geo_ip.enabled'),
COUNTRY: {
DATABASE_URL: config.get<string>('geo_ip.country.database_url')
}
},
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'),
CLEANUP_REMOTE_INTERACTIONS: config.get<boolean>('federation.videos.cleanup_remote_interactions')
},
SIGN_FEDERATED_FETCHES: config.get<boolean>('federation.sign_federated_fetches')
},
2021-03-11 10:54:52 -05:00
PEERTUBE: {
CHECK_LATEST_VERSION: {
ENABLED: config.get<boolean>('peertube.check_latest_version.enabled'),
URL: config.get<string>('peertube.check_latest_version.url')
}
},
WEBADMIN: {
CONFIGURATION: {
2021-10-14 05:35:43 -04:00
EDITION: {
ALLOWED: config.get<boolean>('webadmin.configuration.edition.allowed')
}
}
},
FEEDS: {
VIDEOS: {
COUNT: config.get<number>('feeds.videos.count')
},
COMMENTS: {
COUNT: config.get<number>('feeds.comments.count')
}
},
REMOTE_RUNNERS: {
STALLED_JOBS: {
LIVE: parseDurationToMs(config.get<string>('remote_runners.stalled_jobs.live')),
VOD: parseDurationToMs(config.get<string>('remote_runners.stalled_jobs.vod'))
}
},
THUMBNAILS: {
GENERATION_FROM_VIDEO: {
FRAMES_TO_ANALYZE: config.get<number>('thumbnails.generation_from_video.frames_to_analyze')
}
},
2019-04-11 05:33:44 -04:00
ADMIN: {
get EMAIL () { return config.get<string>('admin.email') }
},
CONTACT_FORM: {
get ENABLED () { return config.get<boolean>('contact_form.enabled') }
},
SIGNUP: {
get ENABLED () { return config.get<boolean>('signup.enabled') },
2023-01-19 03:27:16 -05:00
get REQUIRES_APPROVAL () { return config.get<boolean>('signup.requires_approval') },
2019-04-11 05:33:44 -04:00
get LIMIT () { return config.get<number>('signup.limit') },
get REQUIRES_EMAIL_VERIFICATION () { return config.get<boolean>('signup.requires_email_verification') },
get MINIMUM_AGE () { return config.get<number>('signup.minimum_age') },
2019-04-11 05:33:44 -04:00
FILTERS: {
CIDR: {
get WHITELIST () { return config.get<string[]>('signup.filters.cidr.whitelist') },
get BLACKLIST () { return config.get<string[]>('signup.filters.cidr.blacklist') }
}
}
},
USER: {
HISTORY: {
VIDEOS: {
get ENABLED () { return config.get<boolean>('user.history.videos.enabled') }
}
},
2019-04-11 05:33:44 -04:00
get VIDEO_QUOTA () { return parseBytes(config.get<number>('user.video_quota')) },
get VIDEO_QUOTA_DAILY () { return parseBytes(config.get<number>('user.video_quota_daily')) },
get DEFAULT_CHANNEL_NAME () { return config.get<string>('user.default_channel_name') }
2019-04-11 05:33:44 -04:00
},
VIDEO_CHANNELS: {
get MAX_PER_USER () { return config.get<number>('video_channels.max_per_user') }
},
2019-04-11 05:33:44 -04:00
TRANSCODING: {
get ENABLED () { return config.get<boolean>('transcoding.enabled') },
get ALLOW_ADDITIONAL_EXTENSIONS () { return config.get<boolean>('transcoding.allow_additional_extensions') },
2019-05-16 10:55:34 -04:00
get ALLOW_AUDIO_FILES () { return config.get<boolean>('transcoding.allow_audio_files') },
2019-04-11 05:33:44 -04:00
get THREADS () { return config.get<number>('transcoding.threads') },
get CONCURRENCY () { return config.get<number>('transcoding.concurrency') },
get PROFILE () { return config.get<string>('transcoding.profile') },
get ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION () { return config.get<boolean>('transcoding.always_transcode_original_resolution') },
2019-04-11 05:33:44 -04:00
RESOLUTIONS: {
get '0p' () { return config.get<boolean>('transcoding.resolutions.0p') },
get '144p' () { return config.get<boolean>('transcoding.resolutions.144p') },
2019-04-11 05:33:44 -04:00
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 '1440p' () { return config.get<boolean>('transcoding.resolutions.1440p') },
get '2160p' () { return config.get<boolean>('transcoding.resolutions.2160p') }
2019-04-11 05:33:44 -04:00
},
HLS: {
get ENABLED () { return config.get<boolean>('transcoding.hls.enabled') }
},
2023-07-11 03:52:14 -04:00
WEB_VIDEOS: {
get ENABLED () { return config.get<boolean>('transcoding.web_videos.enabled') }
},
REMOTE_RUNNERS: {
get ENABLED () { return config.get<boolean>('transcoding.remote_runners.enabled') }
2019-04-11 05:33:44 -04:00
}
},
LIVE: {
get ENABLED () { return config.get<boolean>('live.enabled') },
2020-09-25 10:19:35 -04:00
get MAX_DURATION () { return parseDurationToMs(config.get<string>('live.max_duration')) },
2020-10-28 10:24:40 -04:00
get MAX_INSTANCE_LIVES () { return config.get<number>('live.max_instance_lives') },
get MAX_USER_LIVES () { return config.get<number>('live.max_user_lives') },
2020-09-25 10:19:35 -04:00
get ALLOW_REPLAY () { return config.get<boolean>('live.allow_replay') },
2022-03-04 07:40:02 -05:00
LATENCY_SETTING: {
get ENABLED () { return config.get<boolean>('live.latency_setting.enabled') }
},
RTMP: {
2021-11-05 06:36:03 -04:00
get ENABLED () { return config.get<boolean>('live.rtmp.enabled') },
get PORT () { return config.get<number>('live.rtmp.port') },
get HOSTNAME () { return config.get<number>('live.rtmp.hostname') },
get PUBLIC_HOSTNAME () { return config.get<number>('live.rtmp.public_hostname') }
},
2021-11-05 06:36:03 -04:00
RTMPS: {
get ENABLED () { return config.get<boolean>('live.rtmps.enabled') },
get PORT () { return config.get<number>('live.rtmps.port') },
get HOSTNAME () { return config.get<number>('live.rtmps.hostname') },
get PUBLIC_HOSTNAME () { return config.get<number>('live.rtmps.public_hostname') },
2021-11-05 06:36:03 -04:00
get KEY_FILE () { return config.get<string>('live.rtmps.key_file') },
get CERT_FILE () { return config.get<string>('live.rtmps.cert_file') }
},
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') },
get ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION () { return config.get<boolean>('live.transcoding.always_transcode_original_resolution') },
RESOLUTIONS: {
get '144p' () { return config.get<boolean>('live.transcoding.resolutions.144p') },
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') }
},
REMOTE_RUNNERS: {
get ENABLED () { return config.get<boolean>('live.transcoding.remote_runners.enabled') }
}
}
},
2022-03-22 11:58:49 -04:00
VIDEO_STUDIO: {
get ENABLED () { return config.get<boolean>('video_studio.enabled') },
REMOTE_RUNNERS: {
get ENABLED () { return config.get<boolean>('video_studio.remote_runners.enabled') }
}
2022-02-11 04:51:33 -05:00
},
2023-07-19 10:02:49 -04:00
VIDEO_FILE: {
UPDATE: {
get ENABLED () { return config.get<boolean>('video_file.update.enabled') }
}
},
2019-04-11 05:33:44 -04:00
IMPORT: {
VIDEOS: {
get CONCURRENCY () { return config.get<number>('import.videos.concurrency') },
get TIMEOUT () { return parseDurationToMs(config.get<string>('import.videos.timeout')) },
2019-04-11 05:33:44 -04:00
HTTP: {
get ENABLED () { return config.get<boolean>('import.videos.http.enabled') },
YOUTUBE_DL_RELEASE: {
get URL () { return config.get<string>('import.videos.http.youtube_dl_release.url') },
get NAME () { return config.get<string>('import.videos.http.youtube_dl_release.name') },
get PYTHON_PATH () { return config.get<string>('import.videos.http.youtube_dl_release.python_path') }
},
get FORCE_IPV4 () { return config.get<boolean>('import.videos.http.force_ipv4') }
2019-04-11 05:33:44 -04:00
},
TORRENT: {
get ENABLED () { return config.get<boolean>('import.videos.torrent.enabled') }
}
Channel sync (#5135) * Add external channel URL for channel update / creation (#754) * Disallow synchronisation if user has no video quota (#754) * More constraints serverside (#754) * Disable sync if server configuration does not allow HTTP import (#754) * Working version synchronizing videos with a job (#754) TODO: refactoring, too much code duplication * More logs and try/catch (#754) * Fix eslint error (#754) * WIP: support synchronization time change (#754) * New frontend #754 * WIP: Create sync front (#754) * Enhance UI, sync creation form (#754) * Warning message when HTTP upload is disallowed * More consistent names (#754) * Binding Front with API (#754) * Add a /me API (#754) * Improve list UI (#754) * Implement creation and deletion routes (#754) * Lint (#754) * Lint again (#754) * WIP: UI for triggering import existing videos (#754) * Implement jobs for syncing and importing channels * Don't sync videos before sync creation + avoid concurrency issue (#754) * Cleanup (#754) * Cleanup: OpenAPI + API rework (#754) * Remove dead code (#754) * Eslint (#754) * Revert the mess with whitespaces in constants.ts (#754) * Some fixes after rebase (#754) * Several fixes after PR remarks (#754) * Front + API: Rename video-channels-sync to video-channel-syncs (#754) * Allow enabling channel sync through UI (#754) * getChannelInfo (#754) * Minor fixes: openapi + model + sql (#754) * Simplified API validators (#754) * Rename MChannelSync to MChannelSyncChannel (#754) * Add command for VideoChannelSync (#754) * Use synchronization.enabled config (#754) * Check parameters test + some fixes (#754) * Fix conflict mistake (#754) * Restrict access to video channel sync list API (#754) * Start adding unit test for synchronization (#754) * Continue testing (#754) * Tests finished + convertion of job to scheduler (#754) * Add lastSyncAt field (#754) * Fix externalRemoteUrl sort + creation date not well formatted (#754) * Small fix (#754) * Factorize addYoutubeDLImport and buildVideo (#754) * Check duplicates on channel not on users (#754) * factorize thumbnail generation (#754) * Fetch error should return status 400 (#754) * Separate video-channel-import and video-channel-sync-latest (#754) * Bump DB migration version after rebase (#754) * Prettier states in UI table (#754) * Add DefaultScope in VideoChannelSyncModel (#754) * Fix audit logs (#754) * Ensure user can upload when importing channel + minor fixes (#754) * Mark synchronization as failed on exception + typos (#754) * Change REST API for importing videos into channel (#754) * Add option for fully synchronize a chnanel (#754) * Return a whole sync object on creation to avoid tricks in Front (#754) * Various remarks (#754) * Single quotes by default (#754) * Rename synchronization to video_channel_synchronization * Add check.latest_videos_count and max_per_user options (#754) * Better channel rendering in list #754 * Allow sorting with channel name and state (#754) * Add missing tests for channel imports (#754) * Prefer using a parent job for channel sync * Styling * Client styling Co-authored-by: Chocobozzz <me@florianbigard.com>
2022-08-10 03:53:39 -04:00
},
VIDEO_CHANNEL_SYNCHRONIZATION: {
get ENABLED () { return config.get<boolean>('import.video_channel_synchronization.enabled') },
get MAX_PER_USER () { return config.get<number>('import.video_channel_synchronization.max_per_user') },
get CHECK_INTERVAL () { return parseDurationToMs(config.get<string>('import.video_channel_synchronization.check_interval')) },
get VIDEOS_LIMIT_PER_SYNCHRONIZATION () {
return config.get<number>('import.video_channel_synchronization.videos_limit_per_synchronization')
},
get FULL_SYNC_VIDEOS_LIMIT () {
return config.get<number>('import.video_channel_synchronization.full_sync_videos_limit')
Channel sync (#5135) * Add external channel URL for channel update / creation (#754) * Disallow synchronisation if user has no video quota (#754) * More constraints serverside (#754) * Disable sync if server configuration does not allow HTTP import (#754) * Working version synchronizing videos with a job (#754) TODO: refactoring, too much code duplication * More logs and try/catch (#754) * Fix eslint error (#754) * WIP: support synchronization time change (#754) * New frontend #754 * WIP: Create sync front (#754) * Enhance UI, sync creation form (#754) * Warning message when HTTP upload is disallowed * More consistent names (#754) * Binding Front with API (#754) * Add a /me API (#754) * Improve list UI (#754) * Implement creation and deletion routes (#754) * Lint (#754) * Lint again (#754) * WIP: UI for triggering import existing videos (#754) * Implement jobs for syncing and importing channels * Don't sync videos before sync creation + avoid concurrency issue (#754) * Cleanup (#754) * Cleanup: OpenAPI + API rework (#754) * Remove dead code (#754) * Eslint (#754) * Revert the mess with whitespaces in constants.ts (#754) * Some fixes after rebase (#754) * Several fixes after PR remarks (#754) * Front + API: Rename video-channels-sync to video-channel-syncs (#754) * Allow enabling channel sync through UI (#754) * getChannelInfo (#754) * Minor fixes: openapi + model + sql (#754) * Simplified API validators (#754) * Rename MChannelSync to MChannelSyncChannel (#754) * Add command for VideoChannelSync (#754) * Use synchronization.enabled config (#754) * Check parameters test + some fixes (#754) * Fix conflict mistake (#754) * Restrict access to video channel sync list API (#754) * Start adding unit test for synchronization (#754) * Continue testing (#754) * Tests finished + convertion of job to scheduler (#754) * Add lastSyncAt field (#754) * Fix externalRemoteUrl sort + creation date not well formatted (#754) * Small fix (#754) * Factorize addYoutubeDLImport and buildVideo (#754) * Check duplicates on channel not on users (#754) * factorize thumbnail generation (#754) * Fetch error should return status 400 (#754) * Separate video-channel-import and video-channel-sync-latest (#754) * Bump DB migration version after rebase (#754) * Prettier states in UI table (#754) * Add DefaultScope in VideoChannelSyncModel (#754) * Fix audit logs (#754) * Ensure user can upload when importing channel + minor fixes (#754) * Mark synchronization as failed on exception + typos (#754) * Change REST API for importing videos into channel (#754) * Add option for fully synchronize a chnanel (#754) * Return a whole sync object on creation to avoid tricks in Front (#754) * Various remarks (#754) * Single quotes by default (#754) * Rename synchronization to video_channel_synchronization * Add check.latest_videos_count and max_per_user options (#754) * Better channel rendering in list #754 * Allow sorting with channel name and state (#754) * Add missing tests for channel imports (#754) * Prefer using a parent job for channel sync * Styling * Client styling Co-authored-by: Chocobozzz <me@florianbigard.com>
2022-08-10 03:53:39 -04:00
}
2019-04-11 05:33:44 -04:00
}
},
AUTO_BLACKLIST: {
VIDEOS: {
OF_USERS: {
get ENABLED () { return config.get<boolean>('auto_blacklist.videos.of_users.enabled') }
}
}
},
CACHE: {
PREVIEWS: {
get SIZE () { return config.get<number>('cache.previews.size') }
},
VIDEO_CAPTIONS: {
get SIZE () { return config.get<number>('cache.captions.size') }
},
TORRENTS: {
get SIZE () { return config.get<number>('cache.torrents.size') }
2023-06-01 08:51:16 -04:00
},
STORYBOARDS: {
get SIZE () { return config.get<number>('cache.storyboards.size') }
2019-04-11 05:33:44 -04:00
}
},
INSTANCE: {
get NAME () { return config.get<string>('instance.name') },
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') },
2019-08-23 09:23:27 -04:00
get CODE_OF_CONDUCT () { return config.get<string>('instance.code_of_conduct') },
2019-09-03 03:49:04 -04:00
get CREATION_REASON () { return config.get<string>('instance.creation_reason') },
2019-08-23 09:23:27 -04:00
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') },
2019-08-23 09:23:27 -04:00
get LANGUAGES () { return config.get<string[]>('instance.languages') || [] },
get CATEGORIES () { return config.get<number[]>('instance.categories') || [] },
2019-04-11 05:33:44 -04:00
get IS_NSFW () { return config.get<boolean>('instance.is_nsfw') },
get DEFAULT_NSFW_POLICY () { return config.get<NSFWPolicyType>('instance.default_nsfw_policy') },
get DEFAULT_CLIENT_ROUTE () { return config.get<string>('instance.default_client_route') },
2019-04-11 05:33:44 -04:00
CUSTOMIZATIONS: {
get JAVASCRIPT () { return config.get<string>('instance.customizations.javascript') },
get CSS () { return config.get<string>('instance.customizations.css') }
},
get ROBOTS () { return config.get<string>('instance.robots') },
get SECURITYTXT () { return config.get<string>('instance.securitytxt') }
2019-04-11 05:33:44 -04:00
},
SERVICES: {
TWITTER: {
get USERNAME () { return config.get<string>('services.twitter.username') },
get WHITELISTED () { return config.get<boolean>('services.twitter.whitelisted') }
}
},
FOLLOWERS: {
INSTANCE: {
get ENABLED () { return config.get<boolean>('followers.instance.enabled') },
get MANUAL_APPROVAL () { return config.get<boolean>('followers.instance.manual_approval') }
}
2019-07-09 05:45:19 -04:00
},
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')
}
}
}
},
2019-07-09 05:45:19 -04:00
THEME: {
get DEFAULT () { return config.get<string>('theme.default') }
2020-05-28 05:15:38 -04:00
},
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') }
2020-05-29 10:16:24 -04:00
},
SEARCH: {
REMOTE_URI: {
2021-02-01 05:30:01 -05:00
get USERS () { return config.get<boolean>('search.remote_uri.users') },
get ANONYMOUS () { return config.get<boolean>('search.remote_uri.anonymous') }
2020-05-29 10:16:24 -04:00
},
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') }
}
2019-04-11 05:33:44 -04:00
}
Channel sync (#5135) * Add external channel URL for channel update / creation (#754) * Disallow synchronisation if user has no video quota (#754) * More constraints serverside (#754) * Disable sync if server configuration does not allow HTTP import (#754) * Working version synchronizing videos with a job (#754) TODO: refactoring, too much code duplication * More logs and try/catch (#754) * Fix eslint error (#754) * WIP: support synchronization time change (#754) * New frontend #754 * WIP: Create sync front (#754) * Enhance UI, sync creation form (#754) * Warning message when HTTP upload is disallowed * More consistent names (#754) * Binding Front with API (#754) * Add a /me API (#754) * Improve list UI (#754) * Implement creation and deletion routes (#754) * Lint (#754) * Lint again (#754) * WIP: UI for triggering import existing videos (#754) * Implement jobs for syncing and importing channels * Don't sync videos before sync creation + avoid concurrency issue (#754) * Cleanup (#754) * Cleanup: OpenAPI + API rework (#754) * Remove dead code (#754) * Eslint (#754) * Revert the mess with whitespaces in constants.ts (#754) * Some fixes after rebase (#754) * Several fixes after PR remarks (#754) * Front + API: Rename video-channels-sync to video-channel-syncs (#754) * Allow enabling channel sync through UI (#754) * getChannelInfo (#754) * Minor fixes: openapi + model + sql (#754) * Simplified API validators (#754) * Rename MChannelSync to MChannelSyncChannel (#754) * Add command for VideoChannelSync (#754) * Use synchronization.enabled config (#754) * Check parameters test + some fixes (#754) * Fix conflict mistake (#754) * Restrict access to video channel sync list API (#754) * Start adding unit test for synchronization (#754) * Continue testing (#754) * Tests finished + convertion of job to scheduler (#754) * Add lastSyncAt field (#754) * Fix externalRemoteUrl sort + creation date not well formatted (#754) * Small fix (#754) * Factorize addYoutubeDLImport and buildVideo (#754) * Check duplicates on channel not on users (#754) * factorize thumbnail generation (#754) * Fetch error should return status 400 (#754) * Separate video-channel-import and video-channel-sync-latest (#754) * Bump DB migration version after rebase (#754) * Prettier states in UI table (#754) * Add DefaultScope in VideoChannelSyncModel (#754) * Fix audit logs (#754) * Ensure user can upload when importing channel + minor fixes (#754) * Mark synchronization as failed on exception + typos (#754) * Change REST API for importing videos into channel (#754) * Add option for fully synchronize a chnanel (#754) * Return a whole sync object on creation to avoid tricks in Front (#754) * Various remarks (#754) * Single quotes by default (#754) * Rename synchronization to video_channel_synchronization * Add check.latest_videos_count and max_per_user options (#754) * Better channel rendering in list #754 * Allow sorting with channel name and state (#754) * Add missing tests for channel imports (#754) * Prefer using a parent job for channel sync * Styling * Client styling Co-authored-by: Chocobozzz <me@florianbigard.com>
2022-08-10 03:53:39 -04:00
2019-04-11 05:33:44 -04:00
}
function registerConfigChangedHandler (fun: Function) {
configChangedHandlers.push(fun)
}
2020-02-17 04:27:00 -05:00
function isEmailEnabled () {
2021-01-26 03:28:28 -05:00
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
2020-02-17 04:27:00 -05:00
}
2019-04-11 05:33:44 -04:00
function getLocalConfigFilePath () {
const localConfigDir = getLocalConfigDir()
2019-04-11 05:33:44 -04:00
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(localConfigDir, filename + '.json')
}
function getConfigModule () {
return config
}
2023-07-11 03:52:14 -04:00
// ---------------------------------------------------------------------------
export {
CONFIG,
getConfigModule,
2023-07-11 03:52:14 -04:00
getLocalConfigFilePath,
registerConfigChangedHandler,
isEmailEnabled
}
// ---------------------------------------------------------------------------
function getLocalConfigDir () {
if (process.env.PEERTUBE_LOCAL_CONFIG) return process.env.PEERTUBE_LOCAL_CONFIG
const configSources = config.util.getConfigSources()
if (configSources.length === 0) throw new Error('Invalid config source.')
return dirname(configSources[0].name)
2019-04-11 05:33:44 -04:00
}
2020-01-10 04:11:28 -05:00
function buildVideosRedundancy (objs: any[]): VideosRedundancyStrategy[] {
2019-04-11 05:33:44 -04:00
if (!objs) return []
if (!Array.isArray(objs)) return objs
return objs.map(obj => {
return Object.assign({}, obj, {
minLifetime: parseDurationToMs(obj.min_lifetime),
2019-04-11 05:33:44 -04:00
size: bytes.parse(obj.size),
minViews: obj.min_views
})
})
}
export function reloadConfig () {
function getConfigDirectories () {
2019-04-11 05:33:44 -04:00
if (process.env.NODE_CONFIG_DIR) {
2021-10-14 05:35:43 -04:00
return process.env.NODE_CONFIG_DIR.split(':')
2019-04-11 05:33:44 -04:00
}
return [ join(root(), 'config') ]
2019-04-11 05:33:44 -04:00
}
function purge () {
const directories = getConfigDirectories()
2021-04-09 03:37:46 -04:00
2019-04-11 05:33:44 -04:00
for (const fileName in require.cache) {
if (directories.some((dir) => fileName.includes(dir)) === false) {
2019-04-11 05:33:44 -04:00
continue
}
delete require.cache[fileName]
}
decacheModule(require, 'config')
2019-04-11 05:33:44 -04:00
}
purge()
config = require('config')
for (const configChangedHandler of configChangedHandlers) {
configChangedHandler()
}
return Promise.resolve()
2019-04-11 05:33:44 -04:00
}