]>
Commit | Line | Data |
---|---|---|
1 | 'use strict' | |
2 | ||
3 | const config = require('config') | |
4 | const path = require('path') | |
5 | ||
6 | // API version of our pod | |
7 | const API_VERSION = 'v1' | |
8 | ||
9 | const BCRYPT_SALT_SIZE = 10 | |
10 | ||
11 | const CONFIG = { | |
12 | DATABASE: { | |
13 | DBNAME: 'peertube' + config.get('database.suffix'), | |
14 | HOST: config.get('database.host'), | |
15 | PORT: config.get('database.port') | |
16 | }, | |
17 | ELECTRON: { | |
18 | DEBUG: config.get('electron.debug') | |
19 | }, | |
20 | STORAGE: { | |
21 | CERT_DIR: path.join(__dirname, '..', '..', config.get('storage.certs')), | |
22 | LOG_DIR: path.join(__dirname, '..', '..', config.get('storage.logs')), | |
23 | UPLOAD_DIR: path.join(__dirname, '..', '..', config.get('storage.uploads')), | |
24 | THUMBNAILS_DIR: path.join(__dirname, '..', '..', config.get('storage.thumbnails')) | |
25 | }, | |
26 | WEBSERVER: { | |
27 | SCHEME: config.get('webserver.https') === true ? 'https' : 'http', | |
28 | HOST: config.get('webserver.host'), | |
29 | PORT: config.get('webserver.port') | |
30 | } | |
31 | } | |
32 | CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOST + ':' + CONFIG.WEBSERVER.PORT | |
33 | ||
34 | const CONSTRAINTS_FIELDS = { | |
35 | USERS: { | |
36 | USERNAME: { min: 3, max: 20 }, // Length | |
37 | PASSWORD: { min: 6, max: 255 } // Length | |
38 | }, | |
39 | VIDEOS: { | |
40 | NAME: { min: 3, max: 50 }, // Length | |
41 | DESCRIPTION: { min: 3, max: 250 }, // Length | |
42 | MAGNET_URI: { min: 10 }, // Length | |
43 | DURATION: { min: 1, max: 7200 }, // Number | |
44 | TAGS: { min: 1, max: 3 }, // Number of total tags | |
45 | TAG: { min: 2, max: 10 }, // Length | |
46 | THUMBNAIL: { min: 2, max: 30 }, | |
47 | THUMBNAIL64: { min: 0, max: 20000 } // Bytes | |
48 | } | |
49 | } | |
50 | ||
51 | // Score a pod has when we create it as a friend | |
52 | const FRIEND_SCORE = { | |
53 | BASE: 100, | |
54 | MAX: 1000 | |
55 | } | |
56 | ||
57 | // Time to wait between requests to the friends (10 min) | |
58 | let REQUESTS_INTERVAL = 600000 | |
59 | ||
60 | const OAUTH_LIFETIME = { | |
61 | ACCESS_TOKEN: 3600 * 4, // 4 hours | |
62 | REFRESH_TOKEN: 1209600 // 2 weeks | |
63 | } | |
64 | ||
65 | // Number of results by default for the pagination | |
66 | const PAGINATION_COUNT_DEFAULT = 15 | |
67 | ||
68 | // Number of points we add/remove from a friend after a successful/bad request | |
69 | const PODS_SCORE = { | |
70 | MALUS: -10, | |
71 | BONUS: 10 | |
72 | } | |
73 | ||
74 | // Number of requests in parallel we can make | |
75 | const REQUESTS_IN_PARALLEL = 10 | |
76 | ||
77 | // How many requests we put in request (request scheduler) | |
78 | const REQUESTS_LIMIT = 10 | |
79 | ||
80 | // Number of requests to retry for replay requests module | |
81 | const RETRY_REQUESTS = 5 | |
82 | ||
83 | // Sortable columns per schema | |
84 | const SEARCHABLE_COLUMNS = { | |
85 | VIDEOS: [ 'name', 'magnetUri', 'podUrl', 'author', 'tags' ] | |
86 | } | |
87 | ||
88 | // Seeds in parallel we send to electron when "seed all" | |
89 | // Once a video is in seeding state we seed another video etc | |
90 | const SEEDS_IN_PARALLEL = 3 | |
91 | ||
92 | // Sortable columns per schema | |
93 | const SORTABLE_COLUMNS = { | |
94 | USERS: [ 'username', '-username', 'createdDate', '-createdDate' ], | |
95 | VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdDate', '-createdDate' ] | |
96 | } | |
97 | ||
98 | // Videos thumbnail size | |
99 | const THUMBNAILS_SIZE = '200x110' | |
100 | ||
101 | // Path for access to thumbnails with express router | |
102 | const THUMBNAILS_STATIC_PATH = '/static/thumbnails' | |
103 | ||
104 | const USER_ROLES = { | |
105 | ADMIN: 'admin', | |
106 | USER: 'user' | |
107 | } | |
108 | ||
109 | // Special constants for a test instance | |
110 | if (isTestInstance() === true) { | |
111 | FRIEND_SCORE.BASE = 20 | |
112 | REQUESTS_INTERVAL = 10000 | |
113 | CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14 | |
114 | } | |
115 | ||
116 | // --------------------------------------------------------------------------- | |
117 | ||
118 | module.exports = { | |
119 | API_VERSION: API_VERSION, | |
120 | BCRYPT_SALT_SIZE: BCRYPT_SALT_SIZE, | |
121 | CONFIG: CONFIG, | |
122 | CONSTRAINTS_FIELDS: CONSTRAINTS_FIELDS, | |
123 | FRIEND_SCORE: FRIEND_SCORE, | |
124 | REQUESTS_INTERVAL: REQUESTS_INTERVAL, | |
125 | OAUTH_LIFETIME: OAUTH_LIFETIME, | |
126 | PAGINATION_COUNT_DEFAULT: PAGINATION_COUNT_DEFAULT, | |
127 | PODS_SCORE: PODS_SCORE, | |
128 | REQUESTS_IN_PARALLEL: REQUESTS_IN_PARALLEL, | |
129 | REQUESTS_LIMIT: REQUESTS_LIMIT, | |
130 | RETRY_REQUESTS: RETRY_REQUESTS, | |
131 | SEARCHABLE_COLUMNS: SEARCHABLE_COLUMNS, | |
132 | SEEDS_IN_PARALLEL: SEEDS_IN_PARALLEL, | |
133 | SORTABLE_COLUMNS: SORTABLE_COLUMNS, | |
134 | THUMBNAILS_SIZE: THUMBNAILS_SIZE, | |
135 | THUMBNAILS_STATIC_PATH: THUMBNAILS_STATIC_PATH, | |
136 | USER_ROLES: USER_ROLES | |
137 | } | |
138 | ||
139 | // --------------------------------------------------------------------------- | |
140 | ||
141 | function isTestInstance () { | |
142 | return (process.env.NODE_ENV === 'test') | |
143 | } |