X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Finitializers%2Fconstants.ts;h=03424ffb8f4d2ffc4f9adea006d728c14673c33f;hb=91411dba928678c15a5e99d9795ae061909e397d;hp=16d8dca68598fc4da364d815d39bc2e74258c5e9;hpb=2d3741d6d92e9bd1f41694c7442a6d1da434e1f2;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 16d8dca68..03424ffb8 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,6 +58,7 @@ const OAUTH_LIFETIME = { const ROUTE_CACHE_LIFETIME = { FEEDS: '15 minutes', ROBOTS: '2 hours', + SECURITYTXT: '2 hours', NODEINFO: '10 minutes', DNT_POLICY: '1 week', OVERVIEWS: { @@ -63,7 +66,8 @@ const ROUTE_CACHE_LIFETIME = { }, ACTIVITY_PUB: { VIDEOS: '1 second' // 1 second, cache concurrent requests after a broadcast for example - } + }, + STATS: '4 hours' } // --------------------------------------------------------------------------- @@ -201,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') } }, @@ -259,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: { @@ -312,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 @@ -364,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 } } @@ -469,7 +493,7 @@ const TORRENT_MIMETYPE_EXT = { const OVERVIEWS = { VIDEOS: { - SAMPLE_THRESHOLD: 4, + SAMPLE_THRESHOLD: 6, SAMPLES_COUNT: 2 } } @@ -571,6 +595,17 @@ const CACHE = { } } +const MEMOIZE_TTL = { + OVERVIEWS_SAMPLE: 1000 * 3600 * 4 // 4 hours +} + +const REDUNDANCY = { + VIDEOS: { + EXPIRES_AFTER_MS: 48 * 3600 * 1000, // 2 days + RANDOMIZED_FACTOR: 5 + } +} + const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS) // --------------------------------------------------------------------------- @@ -618,11 +653,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() @@ -640,6 +679,7 @@ export { CONFIG, CONSTRAINTS_FIELDS, EMBED_SIZE, + REDUNDANCY, JOB_CONCURRENCY, JOB_ATTEMPTS, LAST_MIGRATION_VERSION, @@ -676,6 +716,7 @@ export { VIDEO_ABUSE_STATES, JOB_REQUEST_TIMEOUT, USER_PASSWORD_RESET_LIFETIME, + MEMOIZE_TTL, USER_EMAIL_VERIFY_LIFETIME, IMAGE_MIMETYPE_EXT, OVERVIEWS, @@ -709,6 +750,12 @@ function updateWebserverConfig () { CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP) } +function buildVideosRedundancy (objs: VideosRedundancy[]): VideosRedundancy[] { + if (!objs) return [] + + return objs.map(obj => Object.assign(obj, { size: bytes.parse(obj.size) })) +} + function buildLanguages () { const iso639 = require('iso-639-3') @@ -745,6 +792,9 @@ function buildLanguages () { }) .forEach(l => languages[l.iso6391 || l.iso6393] = l.name) + // Override Occitan label + languages['oc'] = 'Occitan' + return languages }