]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/initializers/constants.js
First version with PostgreSQL
[github/Chocobozzz/PeerTube.git] / server / initializers / constants.js
1 'use strict'
2
3 const config = require('config')
4 const maxBy = require('lodash/maxBy')
5 const path = require('path')
6
7 // ---------------------------------------------------------------------------
8
9 // API version
10 const API_VERSION = 'v1'
11
12 // Number of results by default for the pagination
13 const PAGINATION_COUNT_DEFAULT = 15
14
15 // Sortable columns per schema
16 const SEARCHABLE_COLUMNS = {
17 VIDEOS: [ 'name', 'magnetUri', 'host', 'author', 'tags' ]
18 }
19
20 // Sortable columns per schema
21 const SORTABLE_COLUMNS = {
22 USERS: [ 'username', '-username', 'createdAt', '-createdAt' ],
23 VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdAt', '-createdAt' ]
24 }
25
26 const OAUTH_LIFETIME = {
27 ACCESS_TOKEN: 3600 * 4, // 4 hours
28 REFRESH_TOKEN: 1209600 // 2 weeks
29 }
30
31 // ---------------------------------------------------------------------------
32
33 const CONFIG = {
34 LISTEN: {
35 PORT: config.get('listen.port')
36 },
37 DATABASE: {
38 DBNAME: 'peertube' + config.get('database.suffix'),
39 HOSTNAME: config.get('database.hostname'),
40 PORT: config.get('database.port')
41 },
42 STORAGE: {
43 CERT_DIR: path.join(__dirname, '..', '..', config.get('storage.certs')),
44 LOG_DIR: path.join(__dirname, '..', '..', config.get('storage.logs')),
45 VIDEOS_DIR: path.join(__dirname, '..', '..', config.get('storage.videos')),
46 THUMBNAILS_DIR: path.join(__dirname, '..', '..', config.get('storage.thumbnails')),
47 PREVIEWS_DIR: path.join(__dirname, '..', '..', config.get('storage.previews')),
48 TORRENTS_DIR: path.join(__dirname, '..', '..', config.get('storage.torrents'))
49 },
50 WEBSERVER: {
51 SCHEME: config.get('webserver.https') === true ? 'https' : 'http',
52 WS: config.get('webserver.https') === true ? 'wss' : 'ws',
53 HOSTNAME: config.get('webserver.hostname'),
54 PORT: config.get('webserver.port')
55 }
56 }
57 CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
58 CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
59
60 // ---------------------------------------------------------------------------
61
62 const CONSTRAINTS_FIELDS = {
63 USERS: {
64 USERNAME: { min: 3, max: 20 }, // Length
65 PASSWORD: { min: 6, max: 255 } // Length
66 },
67 VIDEOS: {
68 NAME: { min: 3, max: 50 }, // Length
69 DESCRIPTION: { min: 3, max: 250 }, // Length
70 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
71 INFO_HASH: { min: 10, max: 50 }, // Length
72 DURATION: { min: 1, max: 7200 }, // Number
73 TAGS: { min: 1, max: 3 }, // Number of total tags
74 TAG: { min: 2, max: 10 }, // Length
75 THUMBNAIL: { min: 2, max: 30 },
76 THUMBNAIL64: { min: 0, max: 20000 } // Bytes
77 }
78 }
79
80 // ---------------------------------------------------------------------------
81
82 // Score a pod has when we create it as a friend
83 const FRIEND_SCORE = {
84 BASE: 100,
85 MAX: 1000
86 }
87
88 // ---------------------------------------------------------------------------
89
90 const MIGRATION_SCRIPTS = [
91 {
92 script: '0005-create-application',
93 version: 5
94 },
95 {
96 script: '0010-users-password',
97 version: 10
98 },
99 {
100 script: '0015-admin-role',
101 version: 15
102 },
103 {
104 script: '0020-requests-endpoint',
105 version: 20
106 },
107 {
108 script: '0025-video-filenames',
109 version: 25
110 },
111 {
112 script: '0030-video-magnet',
113 version: 30
114 },
115 {
116 script: '0035-url-to-host',
117 version: 35
118 },
119 {
120 script: '0040-video-remote-id',
121 version: 40
122 }
123 ]
124 const LAST_SQL_SCHEMA_VERSION = (maxBy(MIGRATION_SCRIPTS, 'version'))['version']
125
126 // ---------------------------------------------------------------------------
127
128 // Number of points we add/remove from a friend after a successful/bad request
129 const PODS_SCORE = {
130 MALUS: -10,
131 BONUS: 10
132 }
133
134 // Time to wait between requests to the friends (10 min)
135 let REQUESTS_INTERVAL = 600000
136
137 // Number of requests in parallel we can make
138 const REQUESTS_IN_PARALLEL = 10
139
140 // How many requests we put in request
141 const REQUESTS_LIMIT = 10
142
143 // Number of requests to retry for replay requests module
144 const RETRY_REQUESTS = 5
145
146 const REQUEST_ENDPOINTS = {
147 VIDEOS: 'videos'
148 }
149
150 // ---------------------------------------------------------------------------
151
152 const REMOTE_SCHEME = {
153 HTTP: 'https',
154 WS: 'wss'
155 }
156
157 // Password encryption
158 const BCRYPT_SALT_SIZE = 10
159
160 // Express static paths (router)
161 const STATIC_PATHS = {
162 PREVIEWS: '/static/previews/',
163 THUMBNAILS: '/static/thumbnails/',
164 TORRENTS: '/static/torrents/',
165 WEBSEED: '/static/webseed/'
166 }
167
168 // Cache control
169 let STATIC_MAX_AGE = '30d'
170
171 // Videos thumbnail size
172 const THUMBNAILS_SIZE = '200x110'
173 const PREVIEWS_SIZE = '640x480'
174
175 const USER_ROLES = {
176 ADMIN: 'admin',
177 USER: 'user'
178 }
179
180 // ---------------------------------------------------------------------------
181
182 // Special constants for a test instance
183 if (isTestInstance() === true) {
184 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
185 FRIEND_SCORE.BASE = 20
186 REQUESTS_INTERVAL = 10000
187 REMOTE_SCHEME.HTTP = 'http'
188 REMOTE_SCHEME.WS = 'ws'
189 STATIC_MAX_AGE = 0
190 }
191
192 // ---------------------------------------------------------------------------
193
194 module.exports = {
195 API_VERSION,
196 BCRYPT_SALT_SIZE,
197 CONFIG,
198 CONSTRAINTS_FIELDS,
199 FRIEND_SCORE,
200 LAST_SQL_SCHEMA_VERSION,
201 MIGRATION_SCRIPTS,
202 OAUTH_LIFETIME,
203 PAGINATION_COUNT_DEFAULT,
204 PODS_SCORE,
205 PREVIEWS_SIZE,
206 REMOTE_SCHEME,
207 REQUEST_ENDPOINTS,
208 REQUESTS_IN_PARALLEL,
209 REQUESTS_INTERVAL,
210 REQUESTS_LIMIT,
211 RETRY_REQUESTS,
212 SEARCHABLE_COLUMNS,
213 SORTABLE_COLUMNS,
214 STATIC_MAX_AGE,
215 STATIC_PATHS,
216 THUMBNAILS_SIZE,
217 USER_ROLES
218 }
219
220 // ---------------------------------------------------------------------------
221
222 // This method exists in utils module but we want to let the constants module independent
223 function isTestInstance () {
224 return (process.env.NODE_ENV === 'test')
225 }