]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/initializers/constants.js
a50eb2f662fed5930ac6c089b488d48caa92d1c2
[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', 'podUrl', 'author', 'tags' ]
18 }
19
20 // Sortable columns per schema
21 const SORTABLE_COLUMNS = {
22 USERS: [ 'username', '-username', 'createdDate', '-createdDate' ],
23 VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdDate', '-createdDate' ]
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
59 // ---------------------------------------------------------------------------
60
61 const CONSTRAINTS_FIELDS = {
62 USERS: {
63 USERNAME: { min: 3, max: 20 }, // Length
64 PASSWORD: { min: 6, max: 255 } // Length
65 },
66 VIDEOS: {
67 NAME: { min: 3, max: 50 }, // Length
68 DESCRIPTION: { min: 3, max: 250 }, // Length
69 MAGNET_URI: { min: 10 }, // Length
70 DURATION: { min: 1, max: 7200 }, // Number
71 TAGS: { min: 1, max: 3 }, // Number of total tags
72 TAG: { min: 2, max: 10 }, // Length
73 THUMBNAIL: { min: 2, max: 30 },
74 THUMBNAIL64: { min: 0, max: 20000 } // Bytes
75 }
76 }
77
78 // ---------------------------------------------------------------------------
79
80 // Score a pod has when we create it as a friend
81 const FRIEND_SCORE = {
82 BASE: 100,
83 MAX: 1000
84 }
85
86 // ---------------------------------------------------------------------------
87
88 const MONGO_MIGRATION_SCRIPTS = [
89 {
90 script: '0005-create-application',
91 version: 5
92 },
93 {
94 script: '0010-users-password',
95 version: 10
96 },
97 {
98 script: '0015-admin-role',
99 version: 15
100 },
101 {
102 script: '0020-requests-endpoint',
103 version: 20
104 }
105 ]
106 const LAST_MONGO_SCHEMA_VERSION = (maxBy(MONGO_MIGRATION_SCRIPTS, 'version'))['version']
107
108 // ---------------------------------------------------------------------------
109
110 // Number of points we add/remove from a friend after a successful/bad request
111 const PODS_SCORE = {
112 MALUS: -10,
113 BONUS: 10
114 }
115
116 // Time to wait between requests to the friends (10 min)
117 let REQUESTS_INTERVAL = 600000
118
119 // Number of requests in parallel we can make
120 const REQUESTS_IN_PARALLEL = 10
121
122 // How many requests we put in request
123 const REQUESTS_LIMIT = 10
124
125 // Number of requests to retry for replay requests module
126 const RETRY_REQUESTS = 5
127
128 const REQUEST_ENDPOINTS = {
129 VIDEOS: 'videos'
130 }
131
132 // ---------------------------------------------------------------------------
133
134 // Password encryption
135 const BCRYPT_SALT_SIZE = 10
136
137 // Express static paths (router)
138 const STATIC_PATHS = {
139 PREVIEWS: '/static/previews',
140 THUMBNAILS: '/static/thumbnails',
141 TORRENTS: '/static/torrents/',
142 WEBSEED: '/static/webseed/'
143 }
144
145 // Cache control
146 let STATIC_MAX_AGE = '30d'
147
148 // Videos thumbnail size
149 const THUMBNAILS_SIZE = '200x110'
150 const PREVIEWS_SIZE = '640x480'
151
152 const USER_ROLES = {
153 ADMIN: 'admin',
154 USER: 'user'
155 }
156
157 // ---------------------------------------------------------------------------
158
159 // Special constants for a test instance
160 if (isTestInstance() === true) {
161 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
162 FRIEND_SCORE.BASE = 20
163 REQUESTS_INTERVAL = 10000
164 STATIC_MAX_AGE = 0
165 }
166
167 // ---------------------------------------------------------------------------
168
169 module.exports = {
170 API_VERSION,
171 BCRYPT_SALT_SIZE,
172 CONFIG,
173 CONSTRAINTS_FIELDS,
174 FRIEND_SCORE,
175 LAST_MONGO_SCHEMA_VERSION,
176 MONGO_MIGRATION_SCRIPTS,
177 OAUTH_LIFETIME,
178 PAGINATION_COUNT_DEFAULT,
179 PODS_SCORE,
180 REQUEST_ENDPOINTS,
181 REQUESTS_IN_PARALLEL,
182 REQUESTS_INTERVAL,
183 REQUESTS_LIMIT,
184 RETRY_REQUESTS,
185 PREVIEWS_SIZE,
186 SEARCHABLE_COLUMNS,
187 SORTABLE_COLUMNS,
188 STATIC_MAX_AGE,
189 STATIC_PATHS,
190 THUMBNAILS_SIZE,
191 USER_ROLES
192 }
193
194 // ---------------------------------------------------------------------------
195
196 function isTestInstance () {
197 return (process.env.NODE_ENV === 'test')
198 }