X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Finitializers%2Fconstants.ts;h=de426c16e0ad35d731d8ac8d7f3c3945d2e17f1c;hb=39ba2e8e3a71961cd0087c57d25905f6a97a6b69;hp=5d93c6b82458f1bec7bac7938b15ee5bd39ce831;hpb=d9eaee3939bf2e93e5d775d32bce77842201faba;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 5d93c6b82..de426c16e 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -1,21 +1,22 @@ import { IConfig } from 'config' import { dirname, join } from 'path' -import { JobType, VideoRateType, VideoState } from '../../shared/models' +import { JobType, VideoRateType, VideoState, VideosRedundancy } from '../../shared/models' import { ActivityPubActorType } from '../../shared/models/activitypub' import { FollowState } from '../../shared/models/actors' import { VideoAbuseState, VideoImportState, VideoPrivacy } from '../../shared/models/videos' // Do not use barrels, remain constants as independent as possible -import { buildPath, isTestInstance, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' +import { buildPath, isTestInstance, parseDuration, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' import { invert } from 'lodash' import { CronRepeatOptions, EveryRepeatOptions } from 'bull' +import * as bytes from 'bytes' // Use a variable to reload the configuration if we need let config: IConfig = require('config') // --------------------------------------------------------------------------- -const LAST_MIGRATION_VERSION = 265 +const LAST_MIGRATION_VERSION = 270 // --------------------------------------------------------------------------- @@ -37,14 +38,15 @@ const SORTABLE_COLUMNS = { JOBS: [ 'createdAt' ], VIDEO_ABUSES: [ 'id', 'createdAt', 'state' ], VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ], - VIDEOS: [ 'name', 'duration', 'createdAt', 'publishedAt', 'views', 'likes' ], VIDEO_IMPORTS: [ 'createdAt' ], VIDEO_COMMENT_THREADS: [ 'createdAt' ], BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ], FOLLOWERS: [ 'createdAt' ], FOLLOWING: [ 'createdAt' ], - VIDEOS_SEARCH: [ 'match', 'name', 'duration', 'createdAt', 'publishedAt', 'views', 'likes' ], + VIDEOS: [ 'name', 'duration', 'createdAt', 'publishedAt', 'views', 'likes', 'trending' ], + + VIDEOS_SEARCH: [ 'name', 'duration', 'createdAt', 'publishedAt', 'views', 'likes', 'match' ], VIDEO_CHANNELS_SEARCH: [ 'match', 'displayName', 'createdAt' ] } @@ -56,11 +58,16 @@ const OAUTH_LIFETIME = { const ROUTE_CACHE_LIFETIME = { FEEDS: '15 minutes', ROBOTS: '2 hours', + SECURITYTXT: '2 hours', NODEINFO: '10 minutes', DNT_POLICY: '1 week', + OVERVIEWS: { + VIDEOS: '1 hour' + }, ACTIVITY_PUB: { VIDEOS: '1 second' // 1 second, cache concurrent requests after a broadcast for example - } + }, + STATS: '4 hours' } // --------------------------------------------------------------------------- @@ -112,7 +119,7 @@ const JOB_TTL: { [ id in JobType ]: number } = { 'activitypub-follow': 60000 * 10, // 10 minutes 'video-file-import': 1000 * 3600, // 1 hour 'video-file': 1000 * 3600 * 48, // 2 days, transcoding could be long - 'video-import': 1000 * 3600 * 5, // 5 hours + 'video-import': 1000 * 3600, // 1 hour 'email': 60000 * 10, // 10 minutes 'videos-views': undefined // Unlimited } @@ -198,6 +205,17 @@ const CONFIG = { ANONYMOUS: config.get('search.remote_uri.anonymous') } }, + TRENDING: { + VIDEOS: { + INTERVAL_DAYS: config.get('trending.videos.interval_days') + } + }, + REDUNDANCY: { + VIDEOS: { + CHECK_INTERVAL: parseDuration(config.get('redundancy.videos.check_interval')), + STRATEGIES: buildVideosRedundancy(config.get('redundancy.videos.strategies')) + } + }, ADMIN: { get EMAIL () { return config.get('admin.email') } }, @@ -256,7 +274,9 @@ const CONFIG = { get JAVASCRIPT () { return config.get('instance.customizations.javascript') }, get CSS () { return config.get('instance.customizations.css') } }, - get ROBOTS () { return config.get('instance.robots') } + get ROBOTS () { return config.get('instance.robots') }, + get SECURITYTXT () { return config.get('instance.securitytxt') }, + get SECURITYTXT_CONTACT () { return config.get('admin.email') } }, SERVICES: { TWITTER: { @@ -309,6 +329,9 @@ const CONSTRAINTS_FIELDS = { } } }, + VIDEOS_REDUNDANCY: { + URL: { min: 3, max: 2000 } // Length + }, VIDEOS: { NAME: { min: 3, max: 120 }, // Length LANGUAGE: { min: 1, max: 10 }, // Length @@ -361,6 +384,10 @@ const RATES_LIMIT = { LOGIN: { WINDOW_MS: 5 * 60 * 1000, // 5 minutes MAX: 15 // 15 attempts + }, + ASK_SEND_EMAIL: { + WINDOW_MS: 5 * 60 * 1000, // 5 minutes + MAX: 3 // 3 attempts } } @@ -464,6 +491,15 @@ const TORRENT_MIMETYPE_EXT = { // --------------------------------------------------------------------------- +const OVERVIEWS = { + VIDEOS: { + SAMPLE_THRESHOLD: 6, + SAMPLES_COUNT: 2 + } +} + +// --------------------------------------------------------------------------- + const SERVER_ACTOR_NAME = 'peertube' const ACTIVITY_PUB = { @@ -559,6 +595,16 @@ const CACHE = { } } +const MEMOIZE_TTL = { + OVERVIEWS_SAMPLE: 1000 * 3600 * 4 // 4 hours +} + +const REDUNDANCY = { + VIDEOS: { + RANDOMIZED_FACTOR: 5 + } +} + const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS) // --------------------------------------------------------------------------- @@ -606,11 +652,15 @@ if (isTestInstance() === true) { SCHEDULER_INTERVALS_MS.updateVideos = 5000 REPEAT_JOBS['videos-views'] = { every: 5000 } + REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1 + VIDEO_VIEW_LIFETIME = 1000 // 1 second JOB_ATTEMPTS['email'] = 1 CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000 + MEMOIZE_TTL.OVERVIEWS_SAMPLE = 1 + ROUTE_CACHE_LIFETIME.OVERVIEWS.VIDEOS = '0ms' } updateWebserverConfig() @@ -628,6 +678,7 @@ export { CONFIG, CONSTRAINTS_FIELDS, EMBED_SIZE, + REDUNDANCY, JOB_CONCURRENCY, JOB_ATTEMPTS, LAST_MIGRATION_VERSION, @@ -664,8 +715,10 @@ export { VIDEO_ABUSE_STATES, JOB_REQUEST_TIMEOUT, USER_PASSWORD_RESET_LIFETIME, + MEMOIZE_TTL, USER_EMAIL_VERIFY_LIFETIME, IMAGE_MIMETYPE_EXT, + OVERVIEWS, SCHEDULER_INTERVALS_MS, REPEAT_JOBS, STATIC_DOWNLOAD_PATHS, @@ -696,6 +749,18 @@ function updateWebserverConfig () { CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP) } +function buildVideosRedundancy (objs: any[]): VideosRedundancy[] { + if (!objs) return [] + + return objs.map(obj => { + return Object.assign(obj, { + minLifetime: parseDuration(obj.min_lifetime), + size: bytes.parse(obj.size), + minViews: obj.min_views + }) + }) +} + function buildLanguages () { const iso639 = require('iso-639-3') @@ -732,6 +797,9 @@ function buildLanguages () { }) .forEach(l => languages[l.iso6391 || l.iso6393] = l.name) + // Override Occitan label + languages['oc'] = 'Occitan' + return languages }