Allow to sort by likes
[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 = 25
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 }
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     VIEWS: { min: 0 },
90     LIKES: { min: 0 },
91     DISLIKES: { min: 0 }
92   },
93   VIDEO_EVENTS: {
94     COUNT: { min: 0 }
95   }
96 }
97
98 const VIDEO_RATE_TYPES = {
99   LIKE: 'like',
100   DISLIKE: 'dislike'
101 }
102
103 // ---------------------------------------------------------------------------
104
105 // Score a pod has when we create it as a friend
106 const FRIEND_SCORE = {
107   BASE: 100,
108   MAX: 1000
109 }
110
111 // ---------------------------------------------------------------------------
112
113 // Number of points we add/remove from a friend after a successful/bad request
114 const PODS_SCORE = {
115   MALUS: -10,
116   BONUS: 10
117 }
118
119 // Time to wait between requests to the friends (10 min)
120 let REQUESTS_INTERVAL = 600000
121
122 // Number of requests in parallel we can make
123 const REQUESTS_IN_PARALLEL = 10
124
125 // To how many pods we send requests
126 const REQUESTS_LIMIT_PODS = 10
127 // How many requests we send to a pod per interval
128 const REQUESTS_LIMIT_PER_POD = 5
129
130 const REQUESTS_VIDEO_QADU_LIMIT_PODS = 10
131 // The QADU requests are not big
132 const REQUESTS_VIDEO_QADU_LIMIT_PER_POD = 50
133
134 const REQUESTS_VIDEO_EVENT_LIMIT_PODS = 10
135 // The EVENTS requests are not big
136 const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD = 50
137
138 // Number of requests to retry for replay requests module
139 const RETRY_REQUESTS = 5
140
141 const REQUEST_ENDPOINTS = {
142   VIDEOS: 'videos'
143 }
144
145 const REQUEST_ENDPOINT_ACTIONS = {}
146 REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] = {
147   ADD: 'add',
148   UPDATE: 'update',
149   REMOVE: 'remove',
150   REPORT_ABUSE: 'report-abuse'
151 }
152
153 const REQUEST_VIDEO_QADU_ENDPOINT = 'videos/qadu'
154 const REQUEST_VIDEO_EVENT_ENDPOINT = 'videos/events'
155
156 const REQUEST_VIDEO_QADU_TYPES = {
157   LIKES: 'likes',
158   DISLIKES: 'dislikes',
159   VIEWS: 'views'
160 }
161
162 const REQUEST_VIDEO_EVENT_TYPES = {
163   LIKES: 'likes',
164   DISLIKES: 'dislikes',
165   VIEWS: 'views'
166 }
167
168 const REMOTE_SCHEME = {
169   HTTP: 'https',
170   WS: 'wss'
171 }
172
173 // ---------------------------------------------------------------------------
174
175 const PRIVATE_CERT_NAME = 'peertube.key.pem'
176 const PUBLIC_CERT_NAME = 'peertube.pub'
177 const SIGNATURE_ALGORITHM = 'RSA-SHA256'
178 const SIGNATURE_ENCODING = 'hex'
179
180 // Password encryption
181 const BCRYPT_SALT_SIZE = 10
182
183 // ---------------------------------------------------------------------------
184
185 // Express static paths (router)
186 const STATIC_PATHS = {
187   PREVIEWS: '/static/previews/',
188   THUMBNAILS: '/static/thumbnails/',
189   TORRENTS: '/static/torrents/',
190   WEBSEED: '/static/webseed/'
191 }
192
193 // Cache control
194 let STATIC_MAX_AGE = '30d'
195
196 // Videos thumbnail size
197 const THUMBNAILS_SIZE = '200x110'
198 const PREVIEWS_SIZE = '640x480'
199
200 // ---------------------------------------------------------------------------
201
202 const USER_ROLES = {
203   ADMIN: 'admin',
204   USER: 'user'
205 }
206
207 // ---------------------------------------------------------------------------
208
209 // Special constants for a test instance
210 if (isTestInstance() === true) {
211   CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
212   FRIEND_SCORE.BASE = 20
213   REQUESTS_INTERVAL = 10000
214   REMOTE_SCHEME.HTTP = 'http'
215   REMOTE_SCHEME.WS = 'ws'
216   STATIC_MAX_AGE = 0
217 }
218
219 // ---------------------------------------------------------------------------
220
221 module.exports = {
222   API_VERSION,
223   BCRYPT_SALT_SIZE,
224   CONFIG,
225   CONSTRAINTS_FIELDS,
226   FRIEND_SCORE,
227   LAST_MIGRATION_VERSION,
228   OAUTH_LIFETIME,
229   PAGINATION_COUNT_DEFAULT,
230   PODS_SCORE,
231   PREVIEWS_SIZE,
232   PRIVATE_CERT_NAME,
233   PUBLIC_CERT_NAME,
234   REMOTE_SCHEME,
235   REQUEST_ENDPOINT_ACTIONS,
236   REQUEST_ENDPOINTS,
237   REQUEST_VIDEO_EVENT_ENDPOINT,
238   REQUEST_VIDEO_EVENT_TYPES,
239   REQUEST_VIDEO_QADU_ENDPOINT,
240   REQUEST_VIDEO_QADU_TYPES,
241   REQUESTS_IN_PARALLEL,
242   REQUESTS_INTERVAL,
243   REQUESTS_LIMIT_PER_POD,
244   REQUESTS_LIMIT_PODS,
245   REQUESTS_VIDEO_EVENT_LIMIT_PER_POD,
246   REQUESTS_VIDEO_EVENT_LIMIT_PODS,
247   REQUESTS_VIDEO_QADU_LIMIT_PER_POD,
248   REQUESTS_VIDEO_QADU_LIMIT_PODS,
249   RETRY_REQUESTS,
250   SEARCHABLE_COLUMNS,
251   SIGNATURE_ALGORITHM,
252   SIGNATURE_ENCODING,
253   SORTABLE_COLUMNS,
254   STATIC_MAX_AGE,
255   STATIC_PATHS,
256   THUMBNAILS_SIZE,
257   USER_ROLES,
258   VIDEO_RATE_TYPES
259 }
260
261 // ---------------------------------------------------------------------------
262
263 // This method exists in utils module but we want to let the constants module independent
264 function isTestInstance () {
265   return (process.env.NODE_ENV === 'test')
266 }