Server: Use ES6 promise for mongoose/node-oatuh2-server
[oweals/peertube.git] / server / initializers / constants.js
1 'use strict'
2
3 // API version of our pod
4 const API_VERSION = 'v1'
5
6 // Score a pod has when we create it as a friend
7 const FRIEND_SCORE = {
8   BASE: 100,
9   MAX: 1000
10 }
11
12 // Time to wait between requests to the friends (10 min)
13 let INTERVAL = 600000
14
15 const OAUTH_LIFETIME = {
16   ACCESS_TOKEN: 3600 * 4, // 4 hours
17   REFRESH_TOKEN: 1209600 // 2 weeks
18 }
19
20 // Number of results by default for the pagination
21 const PAGINATION_COUNT_DEFAULT = 15
22
23 // Number of points we add/remove from a friend after a successful/bad request
24 const PODS_SCORE = {
25   MALUS: -10,
26   BONUS: 10
27 }
28
29 // Number of requests in parallel we can make
30 const REQUESTS_IN_PARALLEL = 10
31
32 // How many requests we put in request (request scheduler)
33 const REQUESTS_LIMIT = 10
34
35 // Number of requests to retry for replay requests module
36 const RETRY_REQUESTS = 5
37
38 // Sortable columns per schema
39 const SEARCHABLE_COLUMNS = {
40   VIDEOS: [ 'name', 'magnetUri', 'podUrl', 'author', 'tags' ]
41 }
42
43 // Seeds in parallel we send to electron when "seed all"
44 // Once a video is in seeding state we seed another video etc
45 const SEEDS_IN_PARALLEL = 3
46
47 // Sortable columns per schema
48 const SORTABLE_COLUMNS = {
49   VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdDate', '-createdDate' ]
50 }
51
52 // Videos thumbnail size
53 const THUMBNAILS_SIZE = '200x110'
54
55 // Path for access to thumbnails with express router
56 const THUMBNAILS_STATIC_PATH = '/static/thumbnails'
57
58 const VIDEOS_CONSTRAINTS_FIELDS = {
59   NAME: { min: 3, max: 50 }, // Length
60   DESCRIPTION: { min: 3, max: 250 }, // Length
61   MAGNET_URI: { min: 10 }, // Length
62   DURATION: { min: 1, max: 7200 }, // Number
63   AUTHOR: { min: 3, max: 20 }, // Length
64   TAGS: { min: 1, max: 3 }, // Number of total tags
65   TAG: { min: 2, max: 10 }, // Length
66   THUMBNAIL: { min: 2, max: 30 },
67   THUMBNAIL64: { min: 0, max: 20000 } // Bytes
68 }
69
70 // Special constants for a test instance
71 if (isTestInstance() === true) {
72   FRIEND_SCORE.BASE = 20
73   INTERVAL = 10000
74   VIDEOS_CONSTRAINTS_FIELDS.DURATION.max = 14
75 }
76
77 // ---------------------------------------------------------------------------
78
79 module.exports = {
80   API_VERSION: API_VERSION,
81   FRIEND_SCORE: FRIEND_SCORE,
82   INTERVAL: INTERVAL,
83   OAUTH_LIFETIME: OAUTH_LIFETIME,
84   PAGINATION_COUNT_DEFAULT: PAGINATION_COUNT_DEFAULT,
85   PODS_SCORE: PODS_SCORE,
86   REQUESTS_IN_PARALLEL: REQUESTS_IN_PARALLEL,
87   REQUESTS_LIMIT: REQUESTS_LIMIT,
88   RETRY_REQUESTS: RETRY_REQUESTS,
89   SEARCHABLE_COLUMNS: SEARCHABLE_COLUMNS,
90   SEEDS_IN_PARALLEL: SEEDS_IN_PARALLEL,
91   SORTABLE_COLUMNS: SORTABLE_COLUMNS,
92   THUMBNAILS_SIZE: THUMBNAILS_SIZE,
93   THUMBNAILS_STATIC_PATH: THUMBNAILS_STATIC_PATH,
94   VIDEOS_CONSTRAINTS_FIELDS: VIDEOS_CONSTRAINTS_FIELDS
95 }
96
97 // ---------------------------------------------------------------------------
98
99 function isTestInstance () {
100   return (process.env.NODE_ENV === 'test')
101 }