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