]>
Commit | Line | Data |
---|---|---|
1 | 'use strict' | |
2 | ||
3 | const config = require('config') | |
4 | const path = require('path') | |
5 | ||
6 | // --------------------------------------------------------------------------- | |
7 | ||
8 | const LAST_MIGRATION_VERSION = 45 | |
9 | ||
10 | // --------------------------------------------------------------------------- | |
11 | ||
12 | // API version | |
13 | const API_VERSION = 'v1' | |
14 | ||
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 = { | |
20 | VIDEOS: [ 'name', 'magnetUri', 'host', 'author', 'tags' ] | |
21 | } | |
22 | ||
23 | // Sortable columns per schema | |
24 | const SORTABLE_COLUMNS = { | |
25 | USERS: [ 'id', 'username', 'createdAt' ], | |
26 | VIDEO_ABUSES: [ 'id', 'createdAt' ], | |
27 | VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ] | |
28 | } | |
29 | ||
30 | const OAUTH_LIFETIME = { | |
31 | ACCESS_TOKEN: 3600 * 4, // 4 hours | |
32 | REFRESH_TOKEN: 1209600 // 2 weeks | |
33 | } | |
34 | ||
35 | // --------------------------------------------------------------------------- | |
36 | ||
37 | const CONFIG = { | |
38 | LISTEN: { | |
39 | PORT: config.get('listen.port') | |
40 | }, | |
41 | DATABASE: { | |
42 | DBNAME: 'peertube' + config.get('database.suffix'), | |
43 | HOSTNAME: config.get('database.hostname'), | |
44 | PORT: config.get('database.port'), | |
45 | USERNAME: config.get('database.username'), | |
46 | PASSWORD: config.get('database.password') | |
47 | }, | |
48 | STORAGE: { | |
49 | CERT_DIR: path.join(__dirname, '..', '..', config.get('storage.certs')), | |
50 | LOG_DIR: path.join(__dirname, '..', '..', config.get('storage.logs')), | |
51 | VIDEOS_DIR: path.join(__dirname, '..', '..', config.get('storage.videos')), | |
52 | THUMBNAILS_DIR: path.join(__dirname, '..', '..', config.get('storage.thumbnails')), | |
53 | PREVIEWS_DIR: path.join(__dirname, '..', '..', config.get('storage.previews')), | |
54 | TORRENTS_DIR: path.join(__dirname, '..', '..', config.get('storage.torrents')) | |
55 | }, | |
56 | WEBSERVER: { | |
57 | SCHEME: config.get('webserver.https') === true ? 'https' : 'http', | |
58 | WS: config.get('webserver.https') === true ? 'wss' : 'ws', | |
59 | HOSTNAME: config.get('webserver.hostname'), | |
60 | PORT: config.get('webserver.port') | |
61 | }, | |
62 | ADMIN: { | |
63 | EMAIL: config.get('admin.email') | |
64 | }, | |
65 | SIGNUP: { | |
66 | ENABLED: config.get('signup.enabled') | |
67 | } | |
68 | } | |
69 | CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT | |
70 | CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT | |
71 | ||
72 | // --------------------------------------------------------------------------- | |
73 | ||
74 | const CONSTRAINTS_FIELDS = { | |
75 | USERS: { | |
76 | USERNAME: { min: 3, max: 20 }, // Length | |
77 | PASSWORD: { min: 6, max: 255 } // Length | |
78 | }, | |
79 | VIDEO_ABUSES: { | |
80 | REASON: { min: 2, max: 300 } // Length | |
81 | }, | |
82 | VIDEOS: { | |
83 | NAME: { min: 3, max: 50 }, // Length | |
84 | DESCRIPTION: { min: 3, max: 250 }, // Length | |
85 | EXTNAME: [ '.mp4', '.ogv', '.webm' ], | |
86 | INFO_HASH: { min: 40, max: 40 }, // Length, infohash is 20 bytes length but we represent it in hexa so 20 * 2 | |
87 | DURATION: { min: 1, max: 7200 }, // Number | |
88 | TAGS: { min: 0, max: 3 }, // Number of total tags | |
89 | TAG: { min: 2, max: 10 }, // Length | |
90 | THUMBNAIL: { min: 2, max: 30 }, | |
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 } | |
98 | } | |
99 | } | |
100 | ||
101 | const VIDEO_RATE_TYPES = { | |
102 | LIKE: 'like', | |
103 | DISLIKE: 'dislike' | |
104 | } | |
105 | ||
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 | ||
127 | // See https://creativecommons.org/licenses/?lang=en | |
128 | const VIDEO_LICENCES = { | |
129 | 1: 'Attribution', | |
130 | 2: 'Attribution - Share Alike', | |
131 | 3: 'Attribution - No Derivatives', | |
132 | 4: 'Attribution - Non Commercial', | |
133 | 5: 'Attribution - Non Commercial - Share Alike', | |
134 | 6: 'Attribution - Non Commercial - No Derivatives', | |
135 | 7: 'Public Domain Dedication' | |
136 | } | |
137 | ||
138 | // --------------------------------------------------------------------------- | |
139 | ||
140 | // Score a pod has when we create it as a friend | |
141 | const FRIEND_SCORE = { | |
142 | BASE: 100, | |
143 | MAX: 1000 | |
144 | } | |
145 | ||
146 | // --------------------------------------------------------------------------- | |
147 | ||
148 | // Number of points we add/remove from a friend after a successful/bad request | |
149 | const PODS_SCORE = { | |
150 | MALUS: -10, | |
151 | BONUS: 10 | |
152 | } | |
153 | ||
154 | // Time to wait between requests to the friends (10 min) | |
155 | let REQUESTS_INTERVAL = 600000 | |
156 | ||
157 | // Number of requests in parallel we can make | |
158 | const REQUESTS_IN_PARALLEL = 10 | |
159 | ||
160 | // To how many pods we send requests | |
161 | const REQUESTS_LIMIT_PODS = 10 | |
162 | // How many requests we send to a pod per interval | |
163 | const REQUESTS_LIMIT_PER_POD = 5 | |
164 | ||
165 | const REQUESTS_VIDEO_QADU_LIMIT_PODS = 10 | |
166 | // The QADU requests are not big | |
167 | const REQUESTS_VIDEO_QADU_LIMIT_PER_POD = 50 | |
168 | ||
169 | const REQUESTS_VIDEO_EVENT_LIMIT_PODS = 10 | |
170 | // The EVENTS requests are not big | |
171 | const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD = 50 | |
172 | ||
173 | // Number of requests to retry for replay requests module | |
174 | const RETRY_REQUESTS = 5 | |
175 | ||
176 | const REQUEST_ENDPOINTS = { | |
177 | VIDEOS: 'videos' | |
178 | } | |
179 | ||
180 | const REQUEST_ENDPOINT_ACTIONS = {} | |
181 | REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] = { | |
182 | ADD: 'add', | |
183 | UPDATE: 'update', | |
184 | REMOVE: 'remove', | |
185 | REPORT_ABUSE: 'report-abuse' | |
186 | } | |
187 | ||
188 | const REQUEST_VIDEO_QADU_ENDPOINT = 'videos/qadu' | |
189 | const REQUEST_VIDEO_EVENT_ENDPOINT = 'videos/events' | |
190 | ||
191 | const REQUEST_VIDEO_QADU_TYPES = { | |
192 | LIKES: 'likes', | |
193 | DISLIKES: 'dislikes', | |
194 | VIEWS: 'views' | |
195 | } | |
196 | ||
197 | const REQUEST_VIDEO_EVENT_TYPES = { | |
198 | LIKES: 'likes', | |
199 | DISLIKES: 'dislikes', | |
200 | VIEWS: 'views' | |
201 | } | |
202 | ||
203 | const REMOTE_SCHEME = { | |
204 | HTTP: 'https', | |
205 | WS: 'wss' | |
206 | } | |
207 | ||
208 | // --------------------------------------------------------------------------- | |
209 | ||
210 | const PRIVATE_CERT_NAME = 'peertube.key.pem' | |
211 | const PUBLIC_CERT_NAME = 'peertube.pub' | |
212 | const SIGNATURE_ALGORITHM = 'RSA-SHA256' | |
213 | const SIGNATURE_ENCODING = 'hex' | |
214 | ||
215 | // Password encryption | |
216 | const BCRYPT_SALT_SIZE = 10 | |
217 | ||
218 | // --------------------------------------------------------------------------- | |
219 | ||
220 | // Express static paths (router) | |
221 | const STATIC_PATHS = { | |
222 | PREVIEWS: '/static/previews/', | |
223 | THUMBNAILS: '/static/thumbnails/', | |
224 | TORRENTS: '/static/torrents/', | |
225 | WEBSEED: '/static/webseed/' | |
226 | } | |
227 | ||
228 | // Cache control | |
229 | let STATIC_MAX_AGE = '30d' | |
230 | ||
231 | // Videos thumbnail size | |
232 | const THUMBNAILS_SIZE = '200x110' | |
233 | const PREVIEWS_SIZE = '640x480' | |
234 | ||
235 | // --------------------------------------------------------------------------- | |
236 | ||
237 | const USER_ROLES = { | |
238 | ADMIN: 'admin', | |
239 | USER: 'user' | |
240 | } | |
241 | ||
242 | // --------------------------------------------------------------------------- | |
243 | ||
244 | // Special constants for a test instance | |
245 | if (isTestInstance() === true) { | |
246 | CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14 | |
247 | FRIEND_SCORE.BASE = 20 | |
248 | REQUESTS_INTERVAL = 10000 | |
249 | REMOTE_SCHEME.HTTP = 'http' | |
250 | REMOTE_SCHEME.WS = 'ws' | |
251 | STATIC_MAX_AGE = 0 | |
252 | } | |
253 | ||
254 | // --------------------------------------------------------------------------- | |
255 | ||
256 | module.exports = { | |
257 | API_VERSION, | |
258 | BCRYPT_SALT_SIZE, | |
259 | CONFIG, | |
260 | CONSTRAINTS_FIELDS, | |
261 | FRIEND_SCORE, | |
262 | LAST_MIGRATION_VERSION, | |
263 | OAUTH_LIFETIME, | |
264 | PAGINATION_COUNT_DEFAULT, | |
265 | PODS_SCORE, | |
266 | PREVIEWS_SIZE, | |
267 | PRIVATE_CERT_NAME, | |
268 | PUBLIC_CERT_NAME, | |
269 | REMOTE_SCHEME, | |
270 | REQUEST_ENDPOINT_ACTIONS, | |
271 | REQUEST_ENDPOINTS, | |
272 | REQUEST_VIDEO_EVENT_ENDPOINT, | |
273 | REQUEST_VIDEO_EVENT_TYPES, | |
274 | REQUEST_VIDEO_QADU_ENDPOINT, | |
275 | REQUEST_VIDEO_QADU_TYPES, | |
276 | REQUESTS_IN_PARALLEL, | |
277 | REQUESTS_INTERVAL, | |
278 | REQUESTS_LIMIT_PER_POD, | |
279 | REQUESTS_LIMIT_PODS, | |
280 | REQUESTS_VIDEO_EVENT_LIMIT_PER_POD, | |
281 | REQUESTS_VIDEO_EVENT_LIMIT_PODS, | |
282 | REQUESTS_VIDEO_QADU_LIMIT_PER_POD, | |
283 | REQUESTS_VIDEO_QADU_LIMIT_PODS, | |
284 | RETRY_REQUESTS, | |
285 | SEARCHABLE_COLUMNS, | |
286 | SIGNATURE_ALGORITHM, | |
287 | SIGNATURE_ENCODING, | |
288 | SORTABLE_COLUMNS, | |
289 | STATIC_MAX_AGE, | |
290 | STATIC_PATHS, | |
291 | THUMBNAILS_SIZE, | |
292 | USER_ROLES, | |
293 | VIDEO_CATEGORIES, | |
294 | VIDEO_LICENCES, | |
295 | VIDEO_RATE_TYPES | |
296 | } | |
297 | ||
298 | // --------------------------------------------------------------------------- | |
299 | ||
300 | // This method exists in utils module but we want to let the constants module independent | |
301 | function isTestInstance () { | |
302 | return (process.env.NODE_ENV === 'test') | |
303 | } |