Little refractoring of requests scheduler module
[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 let FRIEND_BASE_SCORE = 100
8
9 // Time to wait between requests to the friends (10 min)
10 let INTERVAL = 600000
11
12 // Number of results by default for the pagination
13 const PAGINATION_COUNT_DEFAULT = 15
14
15 // Number of points we add/remove from a friend after a successful/bad request
16 const PODS_SCORE = {
17   MALUS: -10,
18   BONUS: 10
19 }
20
21 // Number of retries we make for the make retry requests (to friends...)
22 let REQUEST_RETRIES = 10
23
24 // Different types or requests for the request scheduler module
25 const REQUEST_SCHEDULER_TYPE = [ 'add', 'remove' ]
26
27 // Sortable columns per schema
28 const SEARCHABLE_COLUMNS = {
29   VIDEOS: [ 'name', 'magnetUri', 'podUrl', 'author', 'tags' ]
30 }
31
32 // Sortable columns per schema
33 const SORTABLE_COLUMNS = {
34   VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdDate', '-createdDate' ]
35 }
36
37 // Videos thumbnail size
38 const THUMBNAILS_SIZE = '200x110'
39
40 // Path for access to thumbnails with express router
41 const THUMBNAILS_STATIC_PATH = '/static/thumbnails'
42
43 const VIDEOS_CONSTRAINTS_FIELDS = {
44   NAME: { min: 1, max: 50 }, // Length
45   DESCRIPTION: { min: 1, max: 250 }, // Length
46   MAGNET_URI: { min: 10 }, // Length
47   DURATION: { min: 1, max: 7200 }, // Number
48   AUTHOR: { min: 3, max: 20 }, // Length
49   TAGS: { min: 1, max: 3 }, // Number of total tags
50   TAG: { min: 2, max: 10 }, // Length
51   THUMBNAIL: { min: 0, max: 20000 } // Bytes
52 }
53
54 // Special constants for a test instance
55 if (isTestInstance() === true) {
56   FRIEND_BASE_SCORE = 20
57   INTERVAL = 10000
58   VIDEOS_CONSTRAINTS_FIELDS.DURATION.max = 14
59   REQUEST_RETRIES = 2
60 }
61
62 // ---------------------------------------------------------------------------
63
64 module.exports = {
65   API_VERSION: API_VERSION,
66   FRIEND_BASE_SCORE: FRIEND_BASE_SCORE,
67   INTERVAL: INTERVAL,
68   PAGINATION_COUNT_DEFAULT: PAGINATION_COUNT_DEFAULT,
69   PODS_SCORE: PODS_SCORE,
70   REQUEST_RETRIES: REQUEST_RETRIES,
71   REQUEST_SCHEDULER_TYPE: REQUEST_SCHEDULER_TYPE,
72   SEARCHABLE_COLUMNS: SEARCHABLE_COLUMNS,
73   SORTABLE_COLUMNS: SORTABLE_COLUMNS,
74   THUMBNAILS_SIZE: THUMBNAILS_SIZE,
75   THUMBNAILS_STATIC_PATH: THUMBNAILS_STATIC_PATH,
76   VIDEOS_CONSTRAINTS_FIELDS: VIDEOS_CONSTRAINTS_FIELDS
77 }
78
79 // ---------------------------------------------------------------------------
80
81 function isTestInstance () {
82   return (process.env.NODE_ENV === 'test')
83 }