]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/constants.js
Update migrations code
[github/Chocobozzz/PeerTube.git] / server / initializers / constants.js
CommitLineData
9f10b292
C
1'use strict'
2
e861452f 3const config = require('config')
4b08096b 4const maxBy = require('lodash/maxBy')
e861452f
C
5const path = require('path')
6
9f6bae3a
C
7// ---------------------------------------------------------------------------
8
9// API version
f0f5567b 10const API_VERSION = 'v1'
9f10b292 11
9f6bae3a
C
12// Number of results by default for the pagination
13const PAGINATION_COUNT_DEFAULT = 15
14
15// Sortable columns per schema
16const SEARCHABLE_COLUMNS = {
feb4bdfd 17 VIDEOS: [ 'name', 'magnetUri', 'host', 'author', 'tags' ]
a3ee6fa2 18}
9f10b292 19
9f6bae3a
C
20// Sortable columns per schema
21const SORTABLE_COLUMNS = {
feb4bdfd
C
22 USERS: [ 'username', '-username', 'createdAt', '-createdAt' ],
23 VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdAt', '-createdAt' ]
9f6bae3a 24}
9f10b292 25
2f372a86
C
26const OAUTH_LIFETIME = {
27 ACCESS_TOKEN: 3600 * 4, // 4 hours
28 REFRESH_TOKEN: 1209600 // 2 weeks
29}
30
9f6bae3a 31// ---------------------------------------------------------------------------
26d7d31b 32
e861452f 33const CONFIG = {
d16b5172
C
34 LISTEN: {
35 PORT: config.get('listen.port')
36 },
e861452f
C
37 DATABASE: {
38 DBNAME: 'peertube' + config.get('database.suffix'),
3737bbaf 39 HOSTNAME: config.get('database.hostname'),
b769007f
C
40 PORT: config.get('database.port'),
41 USERNAME: config.get('database.username'),
42 PASSWORD: config.get('database.password')
e861452f 43 },
e861452f
C
44 STORAGE: {
45 CERT_DIR: path.join(__dirname, '..', '..', config.get('storage.certs')),
46 LOG_DIR: path.join(__dirname, '..', '..', config.get('storage.logs')),
b3d92510 47 VIDEOS_DIR: path.join(__dirname, '..', '..', config.get('storage.videos')),
bf94b6f0 48 THUMBNAILS_DIR: path.join(__dirname, '..', '..', config.get('storage.thumbnails')),
6a94a109 49 PREVIEWS_DIR: path.join(__dirname, '..', '..', config.get('storage.previews')),
bf94b6f0 50 TORRENTS_DIR: path.join(__dirname, '..', '..', config.get('storage.torrents'))
e861452f
C
51 },
52 WEBSERVER: {
53 SCHEME: config.get('webserver.https') === true ? 'https' : 'http',
25cad919 54 WS: config.get('webserver.https') === true ? 'wss' : 'ws',
3737bbaf 55 HOSTNAME: config.get('webserver.hostname'),
e861452f
C
56 PORT: config.get('webserver.port')
57 }
58}
3737bbaf 59CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
49abbbbe 60CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
e861452f 61
9f6bae3a
C
62// ---------------------------------------------------------------------------
63
e4c55619
C
64const CONSTRAINTS_FIELDS = {
65 USERS: {
66 USERNAME: { min: 3, max: 20 }, // Length
67 PASSWORD: { min: 6, max: 255 } // Length
68 },
69 VIDEOS: {
70 NAME: { min: 3, max: 50 }, // Length
71 DESCRIPTION: { min: 3, max: 250 }, // Length
feb4bdfd
C
72 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
73 INFO_HASH: { min: 10, max: 50 }, // Length
e4c55619
C
74 DURATION: { min: 1, max: 7200 }, // Number
75 TAGS: { min: 1, max: 3 }, // Number of total tags
76 TAG: { min: 2, max: 10 }, // Length
77 THUMBNAIL: { min: 2, max: 30 },
78 THUMBNAIL64: { min: 0, max: 20000 } // Bytes
79 }
80}
81
9f6bae3a
C
82// ---------------------------------------------------------------------------
83
9f10b292 84// Score a pod has when we create it as a friend
a3ee6fa2
C
85const FRIEND_SCORE = {
86 BASE: 100,
87 MAX: 1000
88}
9f10b292 89
9f6bae3a
C
90// ---------------------------------------------------------------------------
91
b769007f 92const LAST_MIGRATION_VERSION = 0
00d6b0dd 93
9f6bae3a 94// ---------------------------------------------------------------------------
3fe81fa7 95
9f10b292 96// Number of points we add/remove from a friend after a successful/bad request
f0f5567b 97const PODS_SCORE = {
9f10b292
C
98 MALUS: -10,
99 BONUS: 10
100}
101
9f6bae3a
C
102// Time to wait between requests to the friends (10 min)
103let REQUESTS_INTERVAL = 600000
104
528a9efa
C
105// Number of requests in parallel we can make
106const REQUESTS_IN_PARALLEL = 10
9f10b292 107
9f6bae3a 108// How many requests we put in request
b3595463
C
109const REQUESTS_LIMIT = 10
110
528a9efa
C
111// Number of requests to retry for replay requests module
112const RETRY_REQUESTS = 5
8c255eb5 113
4b08096b
C
114const REQUEST_ENDPOINTS = {
115 VIDEOS: 'videos'
116}
117
9f6bae3a 118// ---------------------------------------------------------------------------
419633ce 119
f285faa0
C
120const REMOTE_SCHEME = {
121 HTTP: 'https',
441b66f8 122 WS: 'wss'
f285faa0
C
123}
124
9f6bae3a
C
125// Password encryption
126const BCRYPT_SALT_SIZE = 10
a877d5ac 127
052937db
C
128// Express static paths (router)
129const STATIC_PATHS = {
f285faa0
C
130 PREVIEWS: '/static/previews/',
131 THUMBNAILS: '/static/thumbnails/',
052937db
C
132 TORRENTS: '/static/torrents/',
133 WEBSEED: '/static/webseed/'
134}
135
dc009132
C
136// Cache control
137let STATIC_MAX_AGE = '30d'
138
cbe2f7c3
C
139// Videos thumbnail size
140const THUMBNAILS_SIZE = '200x110'
6a94a109 141const PREVIEWS_SIZE = '640x480'
cbe2f7c3 142
9bd26629
C
143const USER_ROLES = {
144 ADMIN: 'admin',
145 USER: 'user'
be587647
C
146}
147
9f6bae3a
C
148// ---------------------------------------------------------------------------
149
9f10b292
C
150// Special constants for a test instance
151if (isTestInstance() === true) {
9f6bae3a 152 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
a3ee6fa2 153 FRIEND_SCORE.BASE = 20
d3cd34be 154 REQUESTS_INTERVAL = 10000
f285faa0
C
155 REMOTE_SCHEME.HTTP = 'http'
156 REMOTE_SCHEME.WS = 'ws'
dc009132 157 STATIC_MAX_AGE = 0
9f10b292
C
158}
159
160// ---------------------------------------------------------------------------
161
162module.exports = {
9f6bae3a
C
163 API_VERSION,
164 BCRYPT_SALT_SIZE,
165 CONFIG,
166 CONSTRAINTS_FIELDS,
167 FRIEND_SCORE,
b769007f 168 LAST_MIGRATION_VERSION,
9f6bae3a
C
169 OAUTH_LIFETIME,
170 PAGINATION_COUNT_DEFAULT,
171 PODS_SCORE,
f285faa0
C
172 PREVIEWS_SIZE,
173 REMOTE_SCHEME,
4b08096b 174 REQUEST_ENDPOINTS,
9f6bae3a
C
175 REQUESTS_IN_PARALLEL,
176 REQUESTS_INTERVAL,
177 REQUESTS_LIMIT,
178 RETRY_REQUESTS,
179 SEARCHABLE_COLUMNS,
9f6bae3a 180 SORTABLE_COLUMNS,
dc009132 181 STATIC_MAX_AGE,
a6375e69 182 STATIC_PATHS,
9f6bae3a 183 THUMBNAILS_SIZE,
9f6bae3a 184 USER_ROLES
9f10b292
C
185}
186
187// ---------------------------------------------------------------------------
188
441b66f8 189// This method exists in utils module but we want to let the constants module independent
9f10b292
C
190function isTestInstance () {
191 return (process.env.NODE_ENV === 'test')
192}