]>
Commit | Line | Data |
---|---|---|
9f10b292 C |
1 | 'use strict' |
2 | ||
e861452f C |
3 | const config = require('config') |
4 | const path = require('path') | |
5 | ||
9f6bae3a C |
6 | // --------------------------------------------------------------------------- |
7 | ||
6e07c3de | 8 | const LAST_MIGRATION_VERSION = 30 |
5804c0db C |
9 | |
10 | // --------------------------------------------------------------------------- | |
11 | ||
9f6bae3a | 12 | // API version |
f0f5567b | 13 | const API_VERSION = 'v1' |
9f10b292 | 14 | |
9f6bae3a C |
15 | // Number of results by default for the pagination |
16 | const PAGINATION_COUNT_DEFAULT = 15 | |
17 | ||
18 | // Sortable columns per schema | |
19 | const SEARCHABLE_COLUMNS = { | |
feb4bdfd | 20 | VIDEOS: [ 'name', 'magnetUri', 'host', 'author', 'tags' ] |
a3ee6fa2 | 21 | } |
9f10b292 | 22 | |
9f6bae3a C |
23 | // Sortable columns per schema |
24 | const SORTABLE_COLUMNS = { | |
9c2c18f3 C |
25 | USERS: [ 'id', 'username', 'createdAt' ], |
26 | VIDEO_ABUSES: [ 'id', 'createdAt' ], | |
86e83939 | 27 | VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ] |
9f6bae3a | 28 | } |
9f10b292 | 29 | |
2f372a86 C |
30 | const OAUTH_LIFETIME = { |
31 | ACCESS_TOKEN: 3600 * 4, // 4 hours | |
32 | REFRESH_TOKEN: 1209600 // 2 weeks | |
33 | } | |
34 | ||
9f6bae3a | 35 | // --------------------------------------------------------------------------- |
26d7d31b | 36 | |
e861452f | 37 | const 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') | |
e22528ac C |
64 | }, |
65 | SIGNUP: { | |
66 | ENABLED: config.get('signup.enabled') | |
e861452f C |
67 | } |
68 | } | |
3737bbaf | 69 | CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT |
49abbbbe | 70 | CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT |
e861452f | 71 | |
9f6bae3a C |
72 | // --------------------------------------------------------------------------- |
73 | ||
e4c55619 C |
74 | const CONSTRAINTS_FIELDS = { |
75 | USERS: { | |
76 | USERNAME: { min: 3, max: 20 }, // Length | |
77 | PASSWORD: { min: 6, max: 255 } // Length | |
78 | }, | |
55fa55a9 C |
79 | VIDEO_ABUSES: { |
80 | REASON: { min: 2, max: 300 } // Length | |
81 | }, | |
e4c55619 C |
82 | VIDEOS: { |
83 | NAME: { min: 3, max: 50 }, // Length | |
84 | DESCRIPTION: { min: 3, max: 250 }, // Length | |
feb4bdfd | 85 | EXTNAME: [ '.mp4', '.ogv', '.webm' ], |
67bf9b96 | 86 | INFO_HASH: { min: 40, max: 40 }, // Length, infohash is 20 bytes length but we represent it in hexa so 20 * 2 |
e4c55619 | 87 | DURATION: { min: 1, max: 7200 }, // Number |
e54163c2 | 88 | TAGS: { min: 0, max: 3 }, // Number of total tags |
e4c55619 C |
89 | TAG: { min: 2, max: 10 }, // Length |
90 | THUMBNAIL: { min: 2, max: 30 }, | |
e4c87ec2 C |
91 | THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes |
92 | VIEWS: { min: 0 }, | |
93 | LIKES: { min: 0 }, | |
94 | DISLIKES: { min: 0 } | |
95 | }, | |
96 | VIDEO_EVENTS: { | |
97 | COUNT: { min: 0 } | |
e4c55619 C |
98 | } |
99 | } | |
100 | ||
d38b8281 C |
101 | const VIDEO_RATE_TYPES = { |
102 | LIKE: 'like', | |
103 | DISLIKE: 'dislike' | |
104 | } | |
105 | ||
6e07c3de C |
106 | const VIDEO_CATEGORIES = { |
107 | 1: 'Music', | |
108 | 2: 'Films', | |
109 | 3: 'Vehicles', | |
110 | 4: 'Art', | |
111 | 5: 'Sports', | |
112 | 6: 'Travels', | |
113 | 7: 'Gaming', | |
114 | 8: 'People', | |
115 | 9: 'Comedy', | |
116 | 10: 'Entertainment', | |
117 | 11: 'News', | |
118 | 12: 'Howto', | |
119 | 13: 'Education', | |
120 | 14: 'Activism', | |
121 | 15: 'Science & Technology', | |
122 | 16: 'Animals', | |
123 | 17: 'Kids', | |
124 | 18: 'Food' | |
125 | } | |
126 | ||
9f6bae3a C |
127 | // --------------------------------------------------------------------------- |
128 | ||
9f10b292 | 129 | // Score a pod has when we create it as a friend |
a3ee6fa2 C |
130 | const FRIEND_SCORE = { |
131 | BASE: 100, | |
132 | MAX: 1000 | |
133 | } | |
9f10b292 | 134 | |
9f6bae3a C |
135 | // --------------------------------------------------------------------------- |
136 | ||
9f10b292 | 137 | // Number of points we add/remove from a friend after a successful/bad request |
f0f5567b | 138 | const PODS_SCORE = { |
9f10b292 C |
139 | MALUS: -10, |
140 | BONUS: 10 | |
141 | } | |
142 | ||
9f6bae3a C |
143 | // Time to wait between requests to the friends (10 min) |
144 | let REQUESTS_INTERVAL = 600000 | |
145 | ||
528a9efa C |
146 | // Number of requests in parallel we can make |
147 | const REQUESTS_IN_PARALLEL = 10 | |
9f10b292 | 148 | |
bd14d16a C |
149 | // To how many pods we send requests |
150 | const REQUESTS_LIMIT_PODS = 10 | |
151 | // How many requests we send to a pod per interval | |
152 | const REQUESTS_LIMIT_PER_POD = 5 | |
b3595463 | 153 | |
9e167724 C |
154 | const REQUESTS_VIDEO_QADU_LIMIT_PODS = 10 |
155 | // The QADU requests are not big | |
156 | const REQUESTS_VIDEO_QADU_LIMIT_PER_POD = 50 | |
157 | ||
e4c87ec2 C |
158 | const REQUESTS_VIDEO_EVENT_LIMIT_PODS = 10 |
159 | // The EVENTS requests are not big | |
160 | const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD = 50 | |
161 | ||
528a9efa C |
162 | // Number of requests to retry for replay requests module |
163 | const RETRY_REQUESTS = 5 | |
8c255eb5 | 164 | |
4b08096b | 165 | const REQUEST_ENDPOINTS = { |
4b466058 | 166 | VIDEOS: 'videos' |
4b08096b | 167 | } |
4b466058 | 168 | |
62f4ef41 C |
169 | const REQUEST_ENDPOINT_ACTIONS = {} |
170 | REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] = { | |
171 | ADD: 'add', | |
172 | UPDATE: 'update', | |
173 | REMOVE: 'remove', | |
174 | REPORT_ABUSE: 'report-abuse' | |
175 | } | |
4b08096b | 176 | |
4b466058 C |
177 | const REQUEST_VIDEO_QADU_ENDPOINT = 'videos/qadu' |
178 | const REQUEST_VIDEO_EVENT_ENDPOINT = 'videos/events' | |
179 | ||
9e167724 C |
180 | const REQUEST_VIDEO_QADU_TYPES = { |
181 | LIKES: 'likes', | |
182 | DISLIKES: 'dislikes', | |
183 | VIEWS: 'views' | |
184 | } | |
185 | ||
e4c87ec2 C |
186 | const REQUEST_VIDEO_EVENT_TYPES = { |
187 | LIKES: 'likes', | |
188 | DISLIKES: 'dislikes', | |
189 | VIEWS: 'views' | |
190 | } | |
191 | ||
f285faa0 C |
192 | const REMOTE_SCHEME = { |
193 | HTTP: 'https', | |
441b66f8 | 194 | WS: 'wss' |
f285faa0 C |
195 | } |
196 | ||
bdfbd4f1 C |
197 | // --------------------------------------------------------------------------- |
198 | ||
15103f11 C |
199 | const PRIVATE_CERT_NAME = 'peertube.key.pem' |
200 | const PUBLIC_CERT_NAME = 'peertube.pub' | |
bdfbd4f1 C |
201 | const SIGNATURE_ALGORITHM = 'RSA-SHA256' |
202 | const SIGNATURE_ENCODING = 'hex' | |
203 | ||
9f6bae3a C |
204 | // Password encryption |
205 | const BCRYPT_SALT_SIZE = 10 | |
a877d5ac | 206 | |
bdfbd4f1 C |
207 | // --------------------------------------------------------------------------- |
208 | ||
052937db C |
209 | // Express static paths (router) |
210 | const STATIC_PATHS = { | |
f285faa0 C |
211 | PREVIEWS: '/static/previews/', |
212 | THUMBNAILS: '/static/thumbnails/', | |
052937db C |
213 | TORRENTS: '/static/torrents/', |
214 | WEBSEED: '/static/webseed/' | |
215 | } | |
216 | ||
dc009132 C |
217 | // Cache control |
218 | let STATIC_MAX_AGE = '30d' | |
219 | ||
cbe2f7c3 C |
220 | // Videos thumbnail size |
221 | const THUMBNAILS_SIZE = '200x110' | |
6a94a109 | 222 | const PREVIEWS_SIZE = '640x480' |
cbe2f7c3 | 223 | |
bdfbd4f1 C |
224 | // --------------------------------------------------------------------------- |
225 | ||
9bd26629 C |
226 | const USER_ROLES = { |
227 | ADMIN: 'admin', | |
228 | USER: 'user' | |
be587647 C |
229 | } |
230 | ||
9f6bae3a C |
231 | // --------------------------------------------------------------------------- |
232 | ||
9f10b292 C |
233 | // Special constants for a test instance |
234 | if (isTestInstance() === true) { | |
9f6bae3a | 235 | CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14 |
a3ee6fa2 | 236 | FRIEND_SCORE.BASE = 20 |
d3cd34be | 237 | REQUESTS_INTERVAL = 10000 |
f285faa0 C |
238 | REMOTE_SCHEME.HTTP = 'http' |
239 | REMOTE_SCHEME.WS = 'ws' | |
dc009132 | 240 | STATIC_MAX_AGE = 0 |
9f10b292 C |
241 | } |
242 | ||
243 | // --------------------------------------------------------------------------- | |
244 | ||
245 | module.exports = { | |
9f6bae3a C |
246 | API_VERSION, |
247 | BCRYPT_SALT_SIZE, | |
248 | CONFIG, | |
249 | CONSTRAINTS_FIELDS, | |
250 | FRIEND_SCORE, | |
b769007f | 251 | LAST_MIGRATION_VERSION, |
9f6bae3a C |
252 | OAUTH_LIFETIME, |
253 | PAGINATION_COUNT_DEFAULT, | |
254 | PODS_SCORE, | |
f285faa0 | 255 | PREVIEWS_SIZE, |
15103f11 C |
256 | PRIVATE_CERT_NAME, |
257 | PUBLIC_CERT_NAME, | |
f285faa0 | 258 | REMOTE_SCHEME, |
62f4ef41 | 259 | REQUEST_ENDPOINT_ACTIONS, |
15103f11 | 260 | REQUEST_ENDPOINTS, |
4b466058 | 261 | REQUEST_VIDEO_EVENT_ENDPOINT, |
e4c87ec2 | 262 | REQUEST_VIDEO_EVENT_TYPES, |
4b466058 | 263 | REQUEST_VIDEO_QADU_ENDPOINT, |
9e167724 | 264 | REQUEST_VIDEO_QADU_TYPES, |
9f6bae3a C |
265 | REQUESTS_IN_PARALLEL, |
266 | REQUESTS_INTERVAL, | |
bd14d16a | 267 | REQUESTS_LIMIT_PER_POD, |
15103f11 | 268 | REQUESTS_LIMIT_PODS, |
e4c87ec2 C |
269 | REQUESTS_VIDEO_EVENT_LIMIT_PER_POD, |
270 | REQUESTS_VIDEO_EVENT_LIMIT_PODS, | |
4b466058 C |
271 | REQUESTS_VIDEO_QADU_LIMIT_PER_POD, |
272 | REQUESTS_VIDEO_QADU_LIMIT_PODS, | |
9f6bae3a C |
273 | RETRY_REQUESTS, |
274 | SEARCHABLE_COLUMNS, | |
bdfbd4f1 C |
275 | SIGNATURE_ALGORITHM, |
276 | SIGNATURE_ENCODING, | |
9f6bae3a | 277 | SORTABLE_COLUMNS, |
dc009132 | 278 | STATIC_MAX_AGE, |
a6375e69 | 279 | STATIC_PATHS, |
9f6bae3a | 280 | THUMBNAILS_SIZE, |
d38b8281 | 281 | USER_ROLES, |
6e07c3de | 282 | VIDEO_CATEGORIES, |
d38b8281 | 283 | VIDEO_RATE_TYPES |
9f10b292 C |
284 | } |
285 | ||
286 | // --------------------------------------------------------------------------- | |
287 | ||
441b66f8 | 288 | // This method exists in utils module but we want to let the constants module independent |
9f10b292 C |
289 | function isTestInstance () { |
290 | return (process.env.NODE_ENV === 'test') | |
291 | } |