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