Server: make a basic "quick and dirty update" for videos
[oweals/peertube.git] / server / initializers / constants.js
1 'use strict'
2
3 const config = require('config')
4 const path = require('path')
5
6 // ---------------------------------------------------------------------------
7
8 const LAST_MIGRATION_VERSION = 15
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', '-id', 'username', '-username', 'createdAt', '-createdAt' ],
26   VIDEO_ABUSES: [ 'id', '-id', 'createdAt', '-createdAt' ],
27   VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdAt', '-createdAt', 'views', '-views' ]
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 }
66 CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
67 CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
68
69 // ---------------------------------------------------------------------------
70
71 const CONSTRAINTS_FIELDS = {
72   USERS: {
73     USERNAME: { min: 3, max: 20 }, // Length
74     PASSWORD: { min: 6, max: 255 } // Length
75   },
76   VIDEO_ABUSES: {
77     REASON: { min: 2, max: 300 } // Length
78   },
79   VIDEOS: {
80     NAME: { min: 3, max: 50 }, // Length
81     DESCRIPTION: { min: 3, max: 250 }, // Length
82     EXTNAME: [ '.mp4', '.ogv', '.webm' ],
83     INFO_HASH: { min: 40, max: 40 }, // Length, infohash is 20 bytes length but we represent it in hexa so 20 * 2
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 },
88     THUMBNAIL_DATA: { min: 0, max: 20000 } // Bytes
89   }
90 }
91
92 // ---------------------------------------------------------------------------
93
94 // Score a pod has when we create it as a friend
95 const FRIEND_SCORE = {
96   BASE: 100,
97   MAX: 1000
98 }
99
100 // ---------------------------------------------------------------------------
101
102 // Number of points we add/remove from a friend after a successful/bad request
103 const PODS_SCORE = {
104   MALUS: -10,
105   BONUS: 10
106 }
107
108 // Time to wait between requests to the friends (10 min)
109 let REQUESTS_INTERVAL = 600000
110
111 // Number of requests in parallel we can make
112 const REQUESTS_IN_PARALLEL = 10
113
114 // To how many pods we send requests
115 const REQUESTS_LIMIT_PODS = 10
116 // How many requests we send to a pod per interval
117 const REQUESTS_LIMIT_PER_POD = 5
118
119 const REQUESTS_VIDEO_QADU_LIMIT_PODS = 10
120 // The QADU requests are not big
121 const REQUESTS_VIDEO_QADU_LIMIT_PER_POD = 50
122
123 // Number of requests to retry for replay requests module
124 const RETRY_REQUESTS = 5
125
126 const REQUEST_ENDPOINTS = {
127   VIDEOS: 'videos',
128   QADU: 'videos/qadu'
129 }
130 const REQUEST_ENDPOINT_ACTIONS = {}
131 REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] = {
132   ADD: 'add',
133   UPDATE: 'update',
134   REMOVE: 'remove',
135   REPORT_ABUSE: 'report-abuse'
136 }
137
138 const REQUEST_VIDEO_QADU_TYPES = {
139   LIKES: 'likes',
140   DISLIKES: 'dislikes',
141   VIEWS: 'views'
142 }
143
144 const REMOTE_SCHEME = {
145   HTTP: 'https',
146   WS: 'wss'
147 }
148
149 // ---------------------------------------------------------------------------
150
151 const PRIVATE_CERT_NAME = 'peertube.key.pem'
152 const PUBLIC_CERT_NAME = 'peertube.pub'
153 const SIGNATURE_ALGORITHM = 'RSA-SHA256'
154 const SIGNATURE_ENCODING = 'hex'
155
156 // Password encryption
157 const BCRYPT_SALT_SIZE = 10
158
159 // ---------------------------------------------------------------------------
160
161 // Express static paths (router)
162 const STATIC_PATHS = {
163   PREVIEWS: '/static/previews/',
164   THUMBNAILS: '/static/thumbnails/',
165   TORRENTS: '/static/torrents/',
166   WEBSEED: '/static/webseed/'
167 }
168
169 // Cache control
170 let STATIC_MAX_AGE = '30d'
171
172 // Videos thumbnail size
173 const THUMBNAILS_SIZE = '200x110'
174 const PREVIEWS_SIZE = '640x480'
175
176 // ---------------------------------------------------------------------------
177
178 const USER_ROLES = {
179   ADMIN: 'admin',
180   USER: 'user'
181 }
182
183 // ---------------------------------------------------------------------------
184
185 // Special constants for a test instance
186 if (isTestInstance() === true) {
187   CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
188   FRIEND_SCORE.BASE = 20
189   REQUESTS_INTERVAL = 10000
190   REMOTE_SCHEME.HTTP = 'http'
191   REMOTE_SCHEME.WS = 'ws'
192   STATIC_MAX_AGE = 0
193 }
194
195 // ---------------------------------------------------------------------------
196
197 module.exports = {
198   API_VERSION,
199   BCRYPT_SALT_SIZE,
200   CONFIG,
201   CONSTRAINTS_FIELDS,
202   FRIEND_SCORE,
203   LAST_MIGRATION_VERSION,
204   OAUTH_LIFETIME,
205   PAGINATION_COUNT_DEFAULT,
206   PODS_SCORE,
207   PREVIEWS_SIZE,
208   PRIVATE_CERT_NAME,
209   PUBLIC_CERT_NAME,
210   REMOTE_SCHEME,
211   REQUEST_ENDPOINT_ACTIONS,
212   REQUEST_ENDPOINTS,
213   REQUEST_VIDEO_QADU_TYPES,
214   REQUESTS_IN_PARALLEL,
215   REQUESTS_INTERVAL,
216   REQUESTS_LIMIT_PER_POD,
217   REQUESTS_LIMIT_PODS,
218   REQUESTS_VIDEO_QADU_LIMIT_PER_POD,
219   REQUESTS_VIDEO_QADU_LIMIT_PODS,
220   RETRY_REQUESTS,
221   SEARCHABLE_COLUMNS,
222   SIGNATURE_ALGORITHM,
223   SIGNATURE_ENCODING,
224   SORTABLE_COLUMNS,
225   STATIC_MAX_AGE,
226   STATIC_PATHS,
227   THUMBNAILS_SIZE,
228   USER_ROLES
229 }
230
231 // ---------------------------------------------------------------------------
232
233 // This method exists in utils module but we want to let the constants module independent
234 function isTestInstance () {
235   return (process.env.NODE_ENV === 'test')
236 }