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.ts36
1 files changed, 33 insertions, 3 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 5b7ea5d6c..6b4afbfd8 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -1,6 +1,6 @@
1import { IConfig } from 'config' 1import { IConfig } from 'config'
2import { dirname, join } from 'path' 2import { dirname, join } from 'path'
3import { JobType, VideoRateType, VideoState } from '../../shared/models' 3import { JobType, VideoRateType, VideoRedundancyStrategy, VideoState, VideosRedundancy } from '../../shared/models'
4import { ActivityPubActorType } from '../../shared/models/activitypub' 4import { ActivityPubActorType } from '../../shared/models/activitypub'
5import { FollowState } from '../../shared/models/actors' 5import { FollowState } from '../../shared/models/actors'
6import { VideoAbuseState, VideoImportState, VideoPrivacy } from '../../shared/models/videos' 6import { VideoAbuseState, VideoImportState, VideoPrivacy } from '../../shared/models/videos'
@@ -9,13 +9,14 @@ import { buildPath, isTestInstance, root, sanitizeHost, sanitizeUrl } from '../h
9import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' 9import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type'
10import { invert } from 'lodash' 10import { invert } from 'lodash'
11import { CronRepeatOptions, EveryRepeatOptions } from 'bull' 11import { CronRepeatOptions, EveryRepeatOptions } from 'bull'
12import * as bytes from 'bytes'
12 13
13// Use a variable to reload the configuration if we need 14// Use a variable to reload the configuration if we need
14let config: IConfig = require('config') 15let config: IConfig = require('config')
15 16
16// --------------------------------------------------------------------------- 17// ---------------------------------------------------------------------------
17 18
18const LAST_MIGRATION_VERSION = 265 19const LAST_MIGRATION_VERSION = 270
19 20
20// --------------------------------------------------------------------------- 21// ---------------------------------------------------------------------------
21 22
@@ -137,7 +138,8 @@ let SCHEDULER_INTERVALS_MS = {
137 badActorFollow: 60000 * 60, // 1 hour 138 badActorFollow: 60000 * 60, // 1 hour
138 removeOldJobs: 60000 * 60, // 1 hour 139 removeOldJobs: 60000 * 60, // 1 hour
139 updateVideos: 60000, // 1 minute 140 updateVideos: 60000, // 1 minute
140 youtubeDLUpdate: 60000 * 60 * 24 // 1 day 141 youtubeDLUpdate: 60000 * 60 * 24, // 1 day
142 videosRedundancy: 60000 * 2 // 2 hours
141} 143}
142 144
143// --------------------------------------------------------------------------- 145// ---------------------------------------------------------------------------
@@ -208,6 +210,9 @@ const CONFIG = {
208 INTERVAL_DAYS: config.get<number>('trending.videos.interval_days') 210 INTERVAL_DAYS: config.get<number>('trending.videos.interval_days')
209 } 211 }
210 }, 212 },
213 REDUNDANCY: {
214 VIDEOS: buildVideosRedundancy(config.get<any[]>('redundancy.videos'))
215 },
211 ADMIN: { 216 ADMIN: {
212 get EMAIL () { return config.get<string>('admin.email') } 217 get EMAIL () { return config.get<string>('admin.email') }
213 }, 218 },
@@ -321,6 +326,9 @@ const CONSTRAINTS_FIELDS = {
321 } 326 }
322 } 327 }
323 }, 328 },
329 VIDEOS_REDUNDANCY: {
330 URL: { min: 3, max: 2000 } // Length
331 },
324 VIDEOS: { 332 VIDEOS: {
325 NAME: { min: 3, max: 120 }, // Length 333 NAME: { min: 3, max: 120 }, // Length
326 LANGUAGE: { min: 1, max: 10 }, // Length 334 LANGUAGE: { min: 1, max: 10 }, // Length
@@ -584,6 +592,13 @@ const CACHE = {
584 } 592 }
585} 593}
586 594
595const REDUNDANCY = {
596 VIDEOS: {
597 EXPIRES_AFTER_MS: 48 * 3600 * 1000, // 2 days
598 RANDOMIZED_FACTOR: 5
599 }
600}
601
587const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS) 602const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS)
588 603
589// --------------------------------------------------------------------------- 604// ---------------------------------------------------------------------------
@@ -629,8 +644,11 @@ if (isTestInstance() === true) {
629 SCHEDULER_INTERVALS_MS.badActorFollow = 10000 644 SCHEDULER_INTERVALS_MS.badActorFollow = 10000
630 SCHEDULER_INTERVALS_MS.removeOldJobs = 10000 645 SCHEDULER_INTERVALS_MS.removeOldJobs = 10000
631 SCHEDULER_INTERVALS_MS.updateVideos = 5000 646 SCHEDULER_INTERVALS_MS.updateVideos = 5000
647 SCHEDULER_INTERVALS_MS.videosRedundancy = 5000
632 REPEAT_JOBS['videos-views'] = { every: 5000 } 648 REPEAT_JOBS['videos-views'] = { every: 5000 }
633 649
650 REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1
651
634 VIDEO_VIEW_LIFETIME = 1000 // 1 second 652 VIDEO_VIEW_LIFETIME = 1000 // 1 second
635 653
636 JOB_ATTEMPTS['email'] = 1 654 JOB_ATTEMPTS['email'] = 1
@@ -653,6 +671,7 @@ export {
653 CONFIG, 671 CONFIG,
654 CONSTRAINTS_FIELDS, 672 CONSTRAINTS_FIELDS,
655 EMBED_SIZE, 673 EMBED_SIZE,
674 REDUNDANCY,
656 JOB_CONCURRENCY, 675 JOB_CONCURRENCY,
657 JOB_ATTEMPTS, 676 JOB_ATTEMPTS,
658 LAST_MIGRATION_VERSION, 677 LAST_MIGRATION_VERSION,
@@ -722,6 +741,17 @@ function updateWebserverConfig () {
722 CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP) 741 CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP)
723} 742}
724 743
744function buildVideosRedundancy (objs: { strategy: VideoRedundancyStrategy, size: string }[]): VideosRedundancy[] {
745 if (!objs) return []
746
747 return objs.map(obj => {
748 return {
749 strategy: obj.strategy,
750 size: bytes.parse(obj.size)
751 }
752 })
753}
754
725function buildLanguages () { 755function buildLanguages () {
726 const iso639 = require('iso-639-3') 756 const iso639 = require('iso-639-3')
727 757