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