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