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