X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Finitializers%2Fconstants.ts;h=50a29dc4328468132df7a00207d4ad1473f1b03a;hb=c5911fd347c76e8bdc05ea9f3ee9efed4a58c236;hp=3e083fd920569df28df4be7abbc849e81e17e7da;hpb=f3aaa9a95cc2b61f1f255472d7014d08faa66561;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 3e083fd92..50a29dc43 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -1,20 +1,15 @@ import * as config from 'config' import { join } from 'path' - +import { JobCategory, JobState, VideoRateType } from '../../shared/models' +import { ActivityPubActorType } from '../../shared/models/activitypub' +import { FollowState } from '../../shared/models/actors' +import { VideoPrivacy } from '../../shared/models/videos' // Do not use barrels, remain constants as independent as possible -import { root, isTestInstance } from '../helpers/core-utils' - -import { - VideoRateType, - JobState, - JobCategory -} from '../../shared/models' -import { VideoPrivacy } from '../../shared/models/videos/video-privacy.enum' -import { FollowState } from '../../shared/models/accounts/follow.model' +import { isTestInstance, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' // --------------------------------------------------------------------------- -const LAST_MIGRATION_VERSION = 115 +const LAST_MIGRATION_VERSION = 150 // --------------------------------------------------------------------------- @@ -31,6 +26,7 @@ const SORTABLE_COLUMNS = { VIDEO_ABUSES: [ 'id', 'createdAt' ], VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ], VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ], + VIDEO_COMMENT_THREADS: [ 'createdAt' ], BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ], FOLLOWERS: [ 'createdAt' ], FOLLOWING: [ 'createdAt' ] @@ -43,6 +39,44 @@ const OAUTH_LIFETIME = { // --------------------------------------------------------------------------- +// Number of points we add/remove from a friend after a successful/bad request +const SERVERS_SCORE = { + PENALTY: -10, + BONUS: 10, + BASE: 100, + MAX: 1000 +} + +const FOLLOW_STATES: { [ id: string ]: FollowState } = { + PENDING: 'pending', + ACCEPTED: 'accepted' +} + +const REMOTE_SCHEME = { + HTTP: 'https', + WS: 'wss' +} + +const JOB_STATES: { [ id: string ]: JobState } = { + PENDING: 'pending', + PROCESSING: 'processing', + ERROR: 'error', + SUCCESS: 'success' +} +const JOB_CATEGORIES: { [ id: string ]: JobCategory } = { + TRANSCODING: 'transcoding', + ACTIVITYPUB_HTTP: 'activitypub-http' +} +// How many maximum jobs we fetch from the database per cycle +const JOBS_FETCH_LIMIT_PER_CYCLE = { + transcoding: 10, + httpRequest: 20 +} +// 1 minutes +let JOBS_FETCHING_INTERVAL = 60000 + +// --------------------------------------------------------------------------- + const CONFIG = { LISTEN: { PORT: config.get('listen.port') @@ -98,8 +132,6 @@ const CONFIG = { } } } -CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT -CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT const AVATARS_DIR = { ACCOUNT: join(CONFIG.STORAGE.AVATARS_DIR, 'account') @@ -137,13 +169,20 @@ const CONSTRAINTS_FIELDS = { FILE_SIZE: { min: 10 }, URL: { min: 3, max: 2000 } // Length }, - ACCOUNTS: { + ACTOR: { PUBLIC_KEY: { min: 10, max: 5000 }, // Length PRIVATE_KEY: { min: 10, max: 5000 }, // Length - URL: { min: 3, max: 2000 } // Length + URL: { min: 3, max: 2000 }, // Length + AVATAR: { + EXTNAME: [ '.png', '.jpeg', '.jpg' ] + } }, VIDEO_EVENTS: { COUNT: { min: 0 } + }, + VIDEO_COMMENTS: { + TEXT: { min: 2, max: 3000 }, // Length + URL: { min: 3, max: 2000 } // Length } } @@ -214,9 +253,15 @@ const VIDEO_MIMETYPE_EXT = { 'video/mp4': '.mp4' } +const AVATAR_MIMETYPE_EXT = { + 'image/png': '.png', + 'image/jpg': '.jpg', + 'image/jpeg': '.jpg' +} + // --------------------------------------------------------------------------- -const SERVER_ACCOUNT_NAME = 'peertube' +const SERVER_ACTOR_NAME = 'peertube' const ACTIVITY_PUB = { POTENTIAL_ACCEPT_HEADERS: [ @@ -235,44 +280,12 @@ const ACTIVITY_PUB = { } } -// --------------------------------------------------------------------------- - -// Number of points we add/remove from a friend after a successful/bad request -const SERVERS_SCORE = { - PENALTY: -10, - BONUS: 10, - BASE: 100, - MAX: 1000 -} - -const FOLLOW_STATES: { [ id: string ]: FollowState } = { - PENDING: 'pending', - ACCEPTED: 'accepted' +const ACTIVITY_PUB_ACTOR_TYPES: { [ id: string ]: ActivityPubActorType } = { + GROUP: 'Group', + PERSON: 'Person', + APPLICATION: 'Application' } -const REMOTE_SCHEME = { - HTTP: 'https', - WS: 'wss' -} - -const JOB_STATES: { [ id: string ]: JobState } = { - PENDING: 'pending', - PROCESSING: 'processing', - ERROR: 'error', - SUCCESS: 'success' -} -const JOB_CATEGORIES: { [ id: string ]: JobCategory } = { - TRANSCODING: 'transcoding', - ACTIVITYPUB_HTTP: 'activitypub-http' -} -// How many maximum jobs we fetch from the database per cycle -const JOBS_FETCH_LIMIT_PER_CYCLE = { - transcoding: 10, - httpRequest: 20 -} -// 1 minutes -let JOBS_FETCHING_INTERVAL = 60000 - // --------------------------------------------------------------------------- const PRIVATE_RSA_KEY_SIZE = 2048 @@ -287,7 +300,8 @@ const STATIC_PATHS = { PREVIEWS: '/static/previews/', THUMBNAILS: '/static/thumbnails/', TORRENTS: '/static/torrents/', - WEBSEED: '/static/webseed/' + WEBSEED: '/static/webseed/', + AVATARS: '/static/avatars/' } // Cache control @@ -315,7 +329,7 @@ const CACHE = { } } -const ACCEPT_HEADERS = ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS.concat('html', 'application/json') +const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS) // --------------------------------------------------------------------------- @@ -333,6 +347,9 @@ if (isTestInstance() === true) { ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2 } +CONFIG.WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT) +CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP) + // --------------------------------------------------------------------------- export { @@ -356,17 +373,19 @@ export { REMOTE_SCHEME, FOLLOW_STATES, AVATARS_DIR, - SERVER_ACCOUNT_NAME, + SERVER_ACTOR_NAME, PRIVATE_RSA_KEY_SIZE, SORTABLE_COLUMNS, STATIC_MAX_AGE, STATIC_PATHS, ACTIVITY_PUB, + ACTIVITY_PUB_ACTOR_TYPES, THUMBNAILS_SIZE, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_PRIVACIES, VIDEO_LICENCES, VIDEO_RATE_TYPES, - VIDEO_MIMETYPE_EXT + VIDEO_MIMETYPE_EXT, + AVATAR_MIMETYPE_EXT }