aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/constants.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/initializers/constants.ts')
-rw-r--r--server/initializers/constants.ts96
1 files changed, 65 insertions, 31 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index d4496bc34..ad61bee73 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -16,7 +16,7 @@ let config: IConfig = require('config')
16 16
17// --------------------------------------------------------------------------- 17// ---------------------------------------------------------------------------
18 18
19const LAST_MIGRATION_VERSION = 290 19const LAST_MIGRATION_VERSION = 295
20 20
21// --------------------------------------------------------------------------- 21// ---------------------------------------------------------------------------
22 22
@@ -246,6 +246,7 @@ const CONFIG = {
246 }, 246 },
247 TRANSCODING: { 247 TRANSCODING: {
248 get ENABLED () { return config.get<boolean>('transcoding.enabled') }, 248 get ENABLED () { return config.get<boolean>('transcoding.enabled') },
249 get ALLOW_ADDITIONAL_EXTENSIONS () { return config.get<boolean>('transcoding.allow_additional_extensions') },
249 get THREADS () { return config.get<number>('transcoding.threads') }, 250 get THREADS () { return config.get<number>('transcoding.threads') },
250 RESOLUTIONS: { 251 RESOLUTIONS: {
251 get '240p' () { return config.get<boolean>('transcoding.resolutions.240p') }, 252 get '240p' () { return config.get<boolean>('transcoding.resolutions.240p') },
@@ -298,7 +299,7 @@ const CONFIG = {
298 299
299// --------------------------------------------------------------------------- 300// ---------------------------------------------------------------------------
300 301
301const CONSTRAINTS_FIELDS = { 302let CONSTRAINTS_FIELDS = {
302 USERS: { 303 USERS: {
303 NAME: { min: 1, max: 50 }, // Length 304 NAME: { min: 1, max: 50 }, // Length
304 DESCRIPTION: { min: 3, max: 1000 }, // Length 305 DESCRIPTION: { min: 3, max: 1000 }, // Length
@@ -357,7 +358,7 @@ const CONSTRAINTS_FIELDS = {
357 max: 2 * 1024 * 1024 // 2MB 358 max: 2 * 1024 * 1024 // 2MB
358 } 359 }
359 }, 360 },
360 EXTNAME: [ '.mp4', '.ogv', '.webm' ], 361 EXTNAME: buildVideosExtname(),
361 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2 362 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
362 DURATION: { min: 0 }, // Number 363 DURATION: { min: 0 }, // Number
363 TAGS: { min: 0, max: 5 }, // Number of total tags 364 TAGS: { min: 0, max: 5 }, // Number of total tags
@@ -480,27 +481,31 @@ const VIDEO_ABUSE_STATES = {
480 [VideoAbuseState.ACCEPTED]: 'Accepted' 481 [VideoAbuseState.ACCEPTED]: 'Accepted'
481} 482}
482 483
483const VIDEO_MIMETYPE_EXT = { 484const MIMETYPES = {
484 'video/webm': '.webm', 485 VIDEO: {
485 'video/ogg': '.ogv', 486 MIMETYPE_EXT: buildVideoMimetypeExt(),
486 'video/mp4': '.mp4' 487 EXT_MIMETYPE: null as { [ id: string ]: string }
487} 488 },
488const VIDEO_EXT_MIMETYPE = invert(VIDEO_MIMETYPE_EXT) 489 IMAGE: {
489 490 MIMETYPE_EXT: {
490const IMAGE_MIMETYPE_EXT = { 491 'image/png': '.png',
491 'image/png': '.png', 492 'image/jpg': '.jpg',
492 'image/jpg': '.jpg', 493 'image/jpeg': '.jpg'
493 'image/jpeg': '.jpg' 494 }
494} 495 },
495 496 VIDEO_CAPTIONS: {
496const VIDEO_CAPTIONS_MIMETYPE_EXT = { 497 MIMETYPE_EXT: {
497 'text/vtt': '.vtt', 498 'text/vtt': '.vtt',
498 'application/x-subrip': '.srt' 499 'application/x-subrip': '.srt'
499} 500 }
500 501 },
501const TORRENT_MIMETYPE_EXT = { 502 TORRENT: {
502 'application/x-bittorrent': '.torrent' 503 MIMETYPE_EXT: {
504 'application/x-bittorrent': '.torrent'
505 }
506 }
503} 507}
508MIMETYPES.VIDEO.EXT_MIMETYPE = invert(MIMETYPES.VIDEO.MIMETYPE_EXT)
504 509
505// --------------------------------------------------------------------------- 510// ---------------------------------------------------------------------------
506 511
@@ -526,7 +531,7 @@ const ACTIVITY_PUB = {
526 COLLECTION_ITEMS_PER_PAGE: 10, 531 COLLECTION_ITEMS_PER_PAGE: 10,
527 FETCH_PAGE_LIMIT: 100, 532 FETCH_PAGE_LIMIT: 100,
528 URL_MIME_TYPES: { 533 URL_MIME_TYPES: {
529 VIDEO: Object.keys(VIDEO_MIMETYPE_EXT), 534 VIDEO: Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT),
530 TORRENT: [ 'application/x-bittorrent' ], 535 TORRENT: [ 'application/x-bittorrent' ],
531 MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ] 536 MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ]
532 }, 537 },
@@ -685,13 +690,12 @@ if (isTestInstance() === true) {
685 ROUTE_CACHE_LIFETIME.OVERVIEWS.VIDEOS = '0ms' 690 ROUTE_CACHE_LIFETIME.OVERVIEWS.VIDEOS = '0ms'
686} 691}
687 692
688updateWebserverConfig() 693updateWebserverUrls()
689 694
690// --------------------------------------------------------------------------- 695// ---------------------------------------------------------------------------
691 696
692export { 697export {
693 API_VERSION, 698 API_VERSION,
694 VIDEO_CAPTIONS_MIMETYPE_EXT,
695 AVATARS_SIZE, 699 AVATARS_SIZE,
696 ACCEPT_HEADERS, 700 ACCEPT_HEADERS,
697 BCRYPT_SALT_SIZE, 701 BCRYPT_SALT_SIZE,
@@ -719,7 +723,6 @@ export {
719 FEEDS, 723 FEEDS,
720 JOB_TTL, 724 JOB_TTL,
721 NSFW_POLICY_TYPES, 725 NSFW_POLICY_TYPES,
722 TORRENT_MIMETYPE_EXT,
723 STATIC_MAX_AGE, 726 STATIC_MAX_AGE,
724 STATIC_PATHS, 727 STATIC_PATHS,
725 VIDEO_IMPORT_TIMEOUT, 728 VIDEO_IMPORT_TIMEOUT,
@@ -732,7 +735,6 @@ export {
732 VIDEO_LICENCES, 735 VIDEO_LICENCES,
733 VIDEO_STATES, 736 VIDEO_STATES,
734 VIDEO_RATE_TYPES, 737 VIDEO_RATE_TYPES,
735 VIDEO_MIMETYPE_EXT,
736 VIDEO_TRANSCODING_FPS, 738 VIDEO_TRANSCODING_FPS,
737 FFMPEG_NICE, 739 FFMPEG_NICE,
738 VIDEO_ABUSE_STATES, 740 VIDEO_ABUSE_STATES,
@@ -740,13 +742,12 @@ export {
740 USER_PASSWORD_RESET_LIFETIME, 742 USER_PASSWORD_RESET_LIFETIME,
741 MEMOIZE_TTL, 743 MEMOIZE_TTL,
742 USER_EMAIL_VERIFY_LIFETIME, 744 USER_EMAIL_VERIFY_LIFETIME,
743 IMAGE_MIMETYPE_EXT,
744 OVERVIEWS, 745 OVERVIEWS,
745 SCHEDULER_INTERVALS_MS, 746 SCHEDULER_INTERVALS_MS,
746 REPEAT_JOBS, 747 REPEAT_JOBS,
747 STATIC_DOWNLOAD_PATHS, 748 STATIC_DOWNLOAD_PATHS,
748 RATES_LIMIT, 749 RATES_LIMIT,
749 VIDEO_EXT_MIMETYPE, 750 MIMETYPES,
750 CRAWL_REQUEST_CONCURRENCY, 751 CRAWL_REQUEST_CONCURRENCY,
751 JOB_COMPLETED_LIFETIME, 752 JOB_COMPLETED_LIFETIME,
752 HTTP_SIGNATURE, 753 HTTP_SIGNATURE,
@@ -768,11 +769,43 @@ function getLocalConfigFilePath () {
768 return join(dirname(configSources[ 0 ].name), filename + '.json') 769 return join(dirname(configSources[ 0 ].name), filename + '.json')
769} 770}
770 771
771function updateWebserverConfig () { 772function buildVideoMimetypeExt () {
773 const data = {
774 'video/webm': '.webm',
775 'video/ogg': '.ogv',
776 'video/mp4': '.mp4'
777 }
778
779 if (CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS) {
780 Object.assign(data, {
781 'video/quicktime': '.mov',
782 'video/x-msvideo': '.avi',
783 'video/x-flv': '.flv',
784 'video/x-matroska': '.mkv'
785 })
786 }
787
788 return data
789}
790
791function updateWebserverUrls () {
772 CONFIG.WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT) 792 CONFIG.WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT)
773 CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP) 793 CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP)
774} 794}
775 795
796function updateWebserverConfig () {
797 CONSTRAINTS_FIELDS.VIDEOS.EXTNAME = buildVideosExtname()
798
799 MIMETYPES.VIDEO.MIMETYPE_EXT = buildVideoMimetypeExt()
800 MIMETYPES.VIDEO.EXT_MIMETYPE = invert(MIMETYPES.VIDEO.MIMETYPE_EXT)
801}
802
803function buildVideosExtname () {
804 return CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS
805 ? [ '.mp4', '.ogv', '.webm', '.mkv', '.mov', '.avi', '.flv' ]
806 : [ '.mp4', '.ogv', '.webm' ]
807}
808
776function buildVideosRedundancy (objs: any[]): VideosRedundancy[] { 809function buildVideosRedundancy (objs: any[]): VideosRedundancy[] {
777 if (!objs) return [] 810 if (!objs) return []
778 811
@@ -854,4 +887,5 @@ export function reloadConfig () {
854 config = require('config') 887 config = require('config')
855 888
856 updateWebserverConfig() 889 updateWebserverConfig()
890 updateWebserverUrls()
857} 891}