]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/initializers/constants.js
Server: fix real world tools
[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 HOST: config.get('database.host'),
36 PORT: config.get('database.port')
37 },
38 ELECTRON: {
39 DEBUG: config.get('electron.debug')
40 },
41 STORAGE: {
42 CERT_DIR: path.join(__dirname, '..', '..', config.get('storage.certs')),
43 LOG_DIR: path.join(__dirname, '..', '..', config.get('storage.logs')),
44 UPLOAD_DIR: path.join(__dirname, '..', '..', config.get('storage.uploads')),
45 THUMBNAILS_DIR: path.join(__dirname, '..', '..', config.get('storage.thumbnails')),
46 TORRENTS_DIR: path.join(__dirname, '..', '..', config.get('storage.torrents'))
47 },
48 WEBSERVER: {
49 SCHEME: config.get('webserver.https') === true ? 'https' : 'http',
50 HOST: config.get('webserver.host'),
51 PORT: config.get('webserver.port')
52 }
53 }
54 CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOST + ':' + CONFIG.WEBSERVER.PORT
55
56 // ---------------------------------------------------------------------------
57
58 const CONSTRAINTS_FIELDS = {
59 USERS: {
60 USERNAME: { min: 3, max: 20 }, // Length
61 PASSWORD: { min: 6, max: 255 } // Length
62 },
63 VIDEOS: {
64 NAME: { min: 3, max: 50 }, // Length
65 DESCRIPTION: { min: 3, max: 250 }, // Length
66 MAGNET_URI: { min: 10 }, // Length
67 DURATION: { min: 1, max: 7200 }, // Number
68 TAGS: { min: 1, max: 3 }, // Number of total tags
69 TAG: { min: 2, max: 10 }, // Length
70 THUMBNAIL: { min: 2, max: 30 },
71 THUMBNAIL64: { min: 0, max: 20000 } // Bytes
72 }
73 }
74
75 // ---------------------------------------------------------------------------
76
77 // Score a pod has when we create it as a friend
78 const FRIEND_SCORE = {
79 BASE: 100,
80 MAX: 1000
81 }
82
83 // ---------------------------------------------------------------------------
84
85 const MONGO_MIGRATION_SCRIPTS = [
86 {
87 script: '0005-create-application',
88 version: 5
89 },
90 {
91 script: '0010-users-password',
92 version: 10
93 },
94 {
95 script: '0015-admin-role',
96 version: 15
97 }
98 ]
99 const LAST_MONGO_SCHEMA_VERSION = 15
100
101 // ---------------------------------------------------------------------------
102
103 // Number of points we add/remove from a friend after a successful/bad request
104 const PODS_SCORE = {
105 MALUS: -10,
106 BONUS: 10
107 }
108
109 // Time to wait between requests to the friends (10 min)
110 let REQUESTS_INTERVAL = 600000
111
112 // Number of requests in parallel we can make
113 const REQUESTS_IN_PARALLEL = 10
114
115 // How many requests we put in request
116 const REQUESTS_LIMIT = 10
117
118 // Number of requests to retry for replay requests module
119 const RETRY_REQUESTS = 5
120
121 // ---------------------------------------------------------------------------
122
123 // Password encryption
124 const BCRYPT_SALT_SIZE = 10
125
126 // Express static paths (router)
127 const STATIC_PATHS = {
128 THUMBNAILS: '/static/thumbnails',
129 TORRENTS: '/static/torrents/',
130 WEBSEED: '/static/webseed/'
131 }
132
133 // Videos thumbnail size
134 const THUMBNAILS_SIZE = '200x110'
135
136 const USER_ROLES = {
137 ADMIN: 'admin',
138 USER: 'user'
139 }
140
141 // Seeds in parallel we send to electron when "seed all"
142 // Once a video is in seeding state we seed another video etc
143 const SEEDS_IN_PARALLEL = 3
144
145 // ---------------------------------------------------------------------------
146
147 // Special constants for a test instance
148 if (isTestInstance() === true) {
149 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
150 FRIEND_SCORE.BASE = 20
151 REQUESTS_INTERVAL = 10000
152 }
153
154 // ---------------------------------------------------------------------------
155
156 module.exports = {
157 API_VERSION,
158 BCRYPT_SALT_SIZE,
159 CONFIG,
160 CONSTRAINTS_FIELDS,
161 FRIEND_SCORE,
162 LAST_MONGO_SCHEMA_VERSION,
163 MONGO_MIGRATION_SCRIPTS,
164 OAUTH_LIFETIME,
165 PAGINATION_COUNT_DEFAULT,
166 PODS_SCORE,
167 REQUESTS_IN_PARALLEL,
168 REQUESTS_INTERVAL,
169 REQUESTS_LIMIT,
170 RETRY_REQUESTS,
171 SEARCHABLE_COLUMNS,
172 SEEDS_IN_PARALLEL,
173 SORTABLE_COLUMNS,
174 STATIC_PATHS,
175 THUMBNAILS_SIZE,
176 USER_ROLES
177 }
178
179 // ---------------------------------------------------------------------------
180
181 function isTestInstance () {
182 return (process.env.NODE_ENV === 'test')
183 }