]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/initializers/constants.js
Server: transaction serializable for videos
[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: [ 'username', '-username', 'createdAt', '-createdAt' ],
22 VIDEO_ABUSES: [ '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}
59CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
60CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
61
62// ---------------------------------------------------------------------------
63
64const CONSTRAINTS_FIELDS = {
65 USERS: {
66 USERNAME: { min: 3, max: 20 }, // Length
67 PASSWORD: { min: 6, max: 255 } // Length
68 },
69 VIDEO_ABUSES: {
70 REASON: { min: 2, max: 300 } // Length
71 },
72 VIDEOS: {
73 NAME: { min: 3, max: 50 }, // Length
74 DESCRIPTION: { min: 3, max: 250 }, // Length
75 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
76 INFO_HASH: { min: 40, max: 40 }, // Length, infohash is 20 bytes length but we represent it in hexa so 20 * 2
77 DURATION: { min: 1, max: 7200 }, // Number
78 TAGS: { min: 1, max: 3 }, // Number of total tags
79 TAG: { min: 2, max: 10 }, // Length
80 THUMBNAIL: { min: 2, max: 30 },
81 THUMBNAIL_DATA: { min: 0, max: 20000 } // Bytes
82 }
83}
84
85// ---------------------------------------------------------------------------
86
87// Score a pod has when we create it as a friend
88const FRIEND_SCORE = {
89 BASE: 100,
90 MAX: 1000
91}
92
93// ---------------------------------------------------------------------------
94
95const LAST_MIGRATION_VERSION = 0
96
97// ---------------------------------------------------------------------------
98
99// Number of points we add/remove from a friend after a successful/bad request
100const PODS_SCORE = {
101 MALUS: -10,
102 BONUS: 10
103}
104
105// Time to wait between requests to the friends (10 min)
106let REQUESTS_INTERVAL = 600000
107
108// Number of requests in parallel we can make
109const REQUESTS_IN_PARALLEL = 10
110
111// To how many pods we send requests
112const REQUESTS_LIMIT_PODS = 10
113// How many requests we send to a pod per interval
114const REQUESTS_LIMIT_PER_POD = 5
115
116// Number of requests to retry for replay requests module
117const RETRY_REQUESTS = 5
118
119const REQUEST_ENDPOINTS = {
120 VIDEOS: 'videos'
121}
122
123const REMOTE_SCHEME = {
124 HTTP: 'https',
125 WS: 'wss'
126}
127
128// ---------------------------------------------------------------------------
129
130const SIGNATURE_ALGORITHM = 'RSA-SHA256'
131const SIGNATURE_ENCODING = 'hex'
132
133// Password encryption
134const BCRYPT_SALT_SIZE = 10
135
136// ---------------------------------------------------------------------------
137
138// Express static paths (router)
139const STATIC_PATHS = {
140 PREVIEWS: '/static/previews/',
141 THUMBNAILS: '/static/thumbnails/',
142 TORRENTS: '/static/torrents/',
143 WEBSEED: '/static/webseed/'
144}
145
146// Cache control
147let STATIC_MAX_AGE = '30d'
148
149// Videos thumbnail size
150const THUMBNAILS_SIZE = '200x110'
151const PREVIEWS_SIZE = '640x480'
152
153// ---------------------------------------------------------------------------
154
155const USER_ROLES = {
156 ADMIN: 'admin',
157 USER: 'user'
158}
159
160// ---------------------------------------------------------------------------
161
162// Special constants for a test instance
163if (isTestInstance() === true) {
164 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
165 FRIEND_SCORE.BASE = 20
166 REQUESTS_INTERVAL = 10000
167 REMOTE_SCHEME.HTTP = 'http'
168 REMOTE_SCHEME.WS = 'ws'
169 STATIC_MAX_AGE = 0
170}
171
172// ---------------------------------------------------------------------------
173
174module.exports = {
175 API_VERSION,
176 BCRYPT_SALT_SIZE,
177 CONFIG,
178 CONSTRAINTS_FIELDS,
179 FRIEND_SCORE,
180 LAST_MIGRATION_VERSION,
181 OAUTH_LIFETIME,
182 PAGINATION_COUNT_DEFAULT,
183 PODS_SCORE,
184 PREVIEWS_SIZE,
185 REMOTE_SCHEME,
186 REQUEST_ENDPOINTS,
187 REQUESTS_IN_PARALLEL,
188 REQUESTS_INTERVAL,
189 REQUESTS_LIMIT_PODS,
190 REQUESTS_LIMIT_PER_POD,
191 RETRY_REQUESTS,
192 SEARCHABLE_COLUMNS,
193 SIGNATURE_ALGORITHM,
194 SIGNATURE_ENCODING,
195 SORTABLE_COLUMNS,
196 STATIC_MAX_AGE,
197 STATIC_PATHS,
198 THUMBNAILS_SIZE,
199 USER_ROLES
200}
201
202// ---------------------------------------------------------------------------
203
204// This method exists in utils module but we want to let the constants module independent
205function isTestInstance () {
206 return (process.env.NODE_ENV === 'test')
207}