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