aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers
diff options
context:
space:
mode:
Diffstat (limited to 'server/initializers')
-rw-r--r--server/initializers/checker-before-init.ts2
-rw-r--r--server/initializers/constants.ts96
-rw-r--r--server/initializers/migrations/0295-video-file-extname.ts49
3 files changed, 115 insertions, 32 deletions
diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts
index b51c7cfba..a7bc7eec8 100644
--- a/server/initializers/checker-before-init.ts
+++ b/server/initializers/checker-before-init.ts
@@ -19,7 +19,7 @@ function checkMissedConfig () {
19 'signup.enabled', 'signup.limit', 'signup.requires_email_verification', 19 'signup.enabled', 'signup.limit', 'signup.requires_email_verification',
20 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist', 20 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist',
21 'redundancy.videos.strategies', 'redundancy.videos.check_interval', 21 'redundancy.videos.strategies', 'redundancy.videos.check_interval',
22 'transcoding.enabled', 'transcoding.threads', 22 'transcoding.enabled', 'transcoding.threads', 'transcoding.allow_additional_extensions',
23 'import.videos.http.enabled', 'import.videos.torrent.enabled', 23 'import.videos.http.enabled', 'import.videos.torrent.enabled',
24 'trending.videos.interval_days', 24 'trending.videos.interval_days',
25 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route', 25 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route',
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}
diff --git a/server/initializers/migrations/0295-video-file-extname.ts b/server/initializers/migrations/0295-video-file-extname.ts
new file mode 100644
index 000000000..dbf249f66
--- /dev/null
+++ b/server/initializers/migrations/0295-video-file-extname.ts
@@ -0,0 +1,49 @@
1import * as Sequelize from 'sequelize'
2
3async function up (utils: {
4 transaction: Sequelize.Transaction,
5 queryInterface: Sequelize.QueryInterface,
6 sequelize: Sequelize.Sequelize,
7 db: any
8}): Promise<void> {
9 {
10 await utils.queryInterface.renameColumn('videoFile', 'extname', 'extname_old')
11 }
12
13 {
14 const data = {
15 type: Sequelize.STRING,
16 defaultValue: null,
17 allowNull: true
18 }
19
20 await utils.queryInterface.addColumn('videoFile', 'extname', data)
21 }
22
23 {
24 const query = 'UPDATE "videoFile" SET "extname" = "extname_old"::text'
25 await utils.sequelize.query(query)
26 }
27
28 {
29 const data = {
30 type: Sequelize.STRING,
31 defaultValue: null,
32 allowNull: false
33 }
34 await utils.queryInterface.changeColumn('videoFile', 'extname', data)
35 }
36
37 {
38 await utils.queryInterface.removeColumn('videoFile', 'extname_old')
39 }
40}
41
42function down (options) {
43 throw new Error('Not implemented.')
44}
45
46export {
47 up,
48 down
49}