From e4c556196d7b31111f17596840d2e1d60caa7dcb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 31 Jul 2016 20:58:43 +0200 Subject: Server: reorganize express validators --- server/initializers/constants.js | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'server/initializers/constants.js') diff --git a/server/initializers/constants.js b/server/initializers/constants.js index 467816f2c..5f4aeccc6 100644 --- a/server/initializers/constants.js +++ b/server/initializers/constants.js @@ -3,6 +3,23 @@ // API version of our pod const API_VERSION = 'v1' +const CONSTRAINTS_FIELDS = { + USERS: { + USERNAME: { min: 3, max: 20 }, // Length + PASSWORD: { min: 6, max: 255 } // Length + }, + VIDEOS: { + NAME: { min: 3, max: 50 }, // Length + DESCRIPTION: { min: 3, max: 250 }, // Length + MAGNET_URI: { min: 10 }, // Length + DURATION: { min: 1, max: 7200 }, // Number + TAGS: { min: 1, max: 3 }, // Number of total tags + TAG: { min: 2, max: 10 }, // Length + THUMBNAIL: { min: 2, max: 30 }, + THUMBNAIL64: { min: 0, max: 20000 } // Bytes + } +} + // Score a pod has when we create it as a friend const FRIEND_SCORE = { BASE: 100, @@ -55,29 +72,18 @@ const THUMBNAILS_SIZE = '200x110' // Path for access to thumbnails with express router const THUMBNAILS_STATIC_PATH = '/static/thumbnails' -const VIDEOS_CONSTRAINTS_FIELDS = { - NAME: { min: 3, max: 50 }, // Length - DESCRIPTION: { min: 3, max: 250 }, // Length - MAGNET_URI: { min: 10 }, // Length - DURATION: { min: 1, max: 7200 }, // Number - AUTHOR: { min: 3, max: 20 }, // Length - TAGS: { min: 1, max: 3 }, // Number of total tags - TAG: { min: 2, max: 10 }, // Length - THUMBNAIL: { min: 2, max: 30 }, - THUMBNAIL64: { min: 0, max: 20000 } // Bytes -} - // Special constants for a test instance if (isTestInstance() === true) { FRIEND_SCORE.BASE = 20 INTERVAL = 10000 - VIDEOS_CONSTRAINTS_FIELDS.DURATION.max = 14 + CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14 } // --------------------------------------------------------------------------- module.exports = { API_VERSION: API_VERSION, + CONSTRAINTS_FIELDS: CONSTRAINTS_FIELDS, FRIEND_SCORE: FRIEND_SCORE, INTERVAL: INTERVAL, OAUTH_LIFETIME: OAUTH_LIFETIME, @@ -90,8 +96,7 @@ module.exports = { SEEDS_IN_PARALLEL: SEEDS_IN_PARALLEL, SORTABLE_COLUMNS: SORTABLE_COLUMNS, THUMBNAILS_SIZE: THUMBNAILS_SIZE, - THUMBNAILS_STATIC_PATH: THUMBNAILS_STATIC_PATH, - VIDEOS_CONSTRAINTS_FIELDS: VIDEOS_CONSTRAINTS_FIELDS + THUMBNAILS_STATIC_PATH: THUMBNAILS_STATIC_PATH } // --------------------------------------------------------------------------- -- cgit v1.2.3 From 9bd2662976a75d3b03364cdbe6419e57c80f99a6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 4 Aug 2016 22:32:36 +0200 Subject: Implement user API (create, update, remove, list) --- server/initializers/constants.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'server/initializers/constants.js') diff --git a/server/initializers/constants.js b/server/initializers/constants.js index 5f4aeccc6..416356400 100644 --- a/server/initializers/constants.js +++ b/server/initializers/constants.js @@ -72,6 +72,11 @@ const THUMBNAILS_SIZE = '200x110' // Path for access to thumbnails with express router const THUMBNAILS_STATIC_PATH = '/static/thumbnails' +const USER_ROLES = { + ADMIN: 'admin', + USER: 'user' +} + // Special constants for a test instance if (isTestInstance() === true) { FRIEND_SCORE.BASE = 20 @@ -96,7 +101,8 @@ module.exports = { SEEDS_IN_PARALLEL: SEEDS_IN_PARALLEL, SORTABLE_COLUMNS: SORTABLE_COLUMNS, THUMBNAILS_SIZE: THUMBNAILS_SIZE, - THUMBNAILS_STATIC_PATH: THUMBNAILS_STATIC_PATH + THUMBNAILS_STATIC_PATH: THUMBNAILS_STATIC_PATH, + USER_ROLES: USER_ROLES } // --------------------------------------------------------------------------- -- cgit v1.2.3 From 5c39adb7313e0696aabb4b71196ab7b0b378c359 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 16 Aug 2016 22:31:45 +0200 Subject: Server: add user list sort/pagination --- server/initializers/constants.js | 1 + 1 file changed, 1 insertion(+) (limited to 'server/initializers/constants.js') diff --git a/server/initializers/constants.js b/server/initializers/constants.js index 416356400..cd2e0cfb9 100644 --- a/server/initializers/constants.js +++ b/server/initializers/constants.js @@ -63,6 +63,7 @@ const SEEDS_IN_PARALLEL = 3 // Sortable columns per schema const SORTABLE_COLUMNS = { + USERS: [ 'username', '-username', 'createdDate', '-createdDate' ], VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdDate', '-createdDate' ] } -- cgit v1.2.3 From e861452fb26553177ad4e32bfb18b4fd8a5b1816 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 19 Aug 2016 21:34:51 +0200 Subject: Server: put config in constants --- server/initializers/constants.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'server/initializers/constants.js') diff --git a/server/initializers/constants.js b/server/initializers/constants.js index cd2e0cfb9..ce9f8ad6c 100644 --- a/server/initializers/constants.js +++ b/server/initializers/constants.js @@ -1,8 +1,34 @@ 'use strict' +const config = require('config') +const path = require('path') + // API version of our pod const API_VERSION = 'v1' +const CONFIG = { + DATABASE: { + DBNAME: 'peertube' + config.get('database.suffix'), + HOST: config.get('database.host'), + PORT: config.get('database.port') + }, + ELECTRON: { + DEBUG: config.get('electron.debug') + }, + STORAGE: { + CERT_DIR: path.join(__dirname, '..', '..', config.get('storage.certs')), + LOG_DIR: path.join(__dirname, '..', '..', config.get('storage.logs')), + UPLOAD_DIR: path.join(__dirname, '..', '..', config.get('storage.uploads')), + THUMBNAILS_DIR: path.join(__dirname, '..', '..', config.get('storage.thumbnails')) + }, + WEBSERVER: { + SCHEME: config.get('webserver.https') === true ? 'https' : 'http', + HOST: config.get('webserver.host'), + PORT: config.get('webserver.port') + } +} +CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOST + ':' + CONFIG.WEBSERVER.PORT + const CONSTRAINTS_FIELDS = { USERS: { USERNAME: { min: 3, max: 20 }, // Length @@ -89,6 +115,7 @@ if (isTestInstance() === true) { module.exports = { API_VERSION: API_VERSION, + CONFIG: CONFIG, CONSTRAINTS_FIELDS: CONSTRAINTS_FIELDS, FRIEND_SCORE: FRIEND_SCORE, INTERVAL: INTERVAL, -- cgit v1.2.3 From 26d7d31ba3b1d26ea9a51e8626e4a4537867db94 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 25 Aug 2016 17:57:37 +0200 Subject: Server: encrypt password in database --- server/initializers/constants.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'server/initializers/constants.js') diff --git a/server/initializers/constants.js b/server/initializers/constants.js index ce9f8ad6c..dd4eff493 100644 --- a/server/initializers/constants.js +++ b/server/initializers/constants.js @@ -6,6 +6,8 @@ const path = require('path') // API version of our pod const API_VERSION = 'v1' +const BCRYPT_SALT_SIZE = 10 + const CONFIG = { DATABASE: { DBNAME: 'peertube' + config.get('database.suffix'), @@ -115,6 +117,7 @@ if (isTestInstance() === true) { module.exports = { API_VERSION: API_VERSION, + BCRYPT_SALT_SIZE: BCRYPT_SALT_SIZE, CONFIG: CONFIG, CONSTRAINTS_FIELDS: CONSTRAINTS_FIELDS, FRIEND_SCORE: FRIEND_SCORE, -- cgit v1.2.3 From d3cd34be2fd03ea79145dfa8eb16e82d2e23191b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 19 Sep 2016 21:33:46 +0200 Subject: Server: add requests stats endpoint --- server/initializers/constants.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'server/initializers/constants.js') diff --git a/server/initializers/constants.js b/server/initializers/constants.js index dd4eff493..76ebb8681 100644 --- a/server/initializers/constants.js +++ b/server/initializers/constants.js @@ -55,7 +55,7 @@ const FRIEND_SCORE = { } // Time to wait between requests to the friends (10 min) -let INTERVAL = 600000 +let REQUESTS_INTERVAL = 600000 const OAUTH_LIFETIME = { ACCESS_TOKEN: 3600 * 4, // 4 hours @@ -109,7 +109,7 @@ const USER_ROLES = { // Special constants for a test instance if (isTestInstance() === true) { FRIEND_SCORE.BASE = 20 - INTERVAL = 10000 + REQUESTS_INTERVAL = 10000 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14 } @@ -121,7 +121,7 @@ module.exports = { CONFIG: CONFIG, CONSTRAINTS_FIELDS: CONSTRAINTS_FIELDS, FRIEND_SCORE: FRIEND_SCORE, - INTERVAL: INTERVAL, + REQUESTS_INTERVAL: REQUESTS_INTERVAL, OAUTH_LIFETIME: OAUTH_LIFETIME, PAGINATION_COUNT_DEFAULT: PAGINATION_COUNT_DEFAULT, PODS_SCORE: PODS_SCORE, -- cgit v1.2.3 From 00d6b0dda4b1964ab11127851c0fc7106cc0f912 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 26 Sep 2016 22:36:36 +0200 Subject: Add migration (for db, folders...) mechanism --- server/initializers/constants.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'server/initializers/constants.js') diff --git a/server/initializers/constants.js b/server/initializers/constants.js index 76ebb8681..10ae48e95 100644 --- a/server/initializers/constants.js +++ b/server/initializers/constants.js @@ -54,6 +54,18 @@ const FRIEND_SCORE = { MAX: 1000 } +const MONGO_MIGRATION_SCRIPTS = [ + { + script: '0005-create-application', + version: 5 + }, + { + script: '0010-users-password', + version: 10 + } +] +const LAST_MONGO_SCHEMA_VERSION = 10 + // Time to wait between requests to the friends (10 min) let REQUESTS_INTERVAL = 600000 @@ -121,11 +133,13 @@ module.exports = { CONFIG: CONFIG, CONSTRAINTS_FIELDS: CONSTRAINTS_FIELDS, FRIEND_SCORE: FRIEND_SCORE, - REQUESTS_INTERVAL: REQUESTS_INTERVAL, + LAST_MONGO_SCHEMA_VERSION: LAST_MONGO_SCHEMA_VERSION, + MONGO_MIGRATION_SCRIPTS: MONGO_MIGRATION_SCRIPTS, OAUTH_LIFETIME: OAUTH_LIFETIME, PAGINATION_COUNT_DEFAULT: PAGINATION_COUNT_DEFAULT, PODS_SCORE: PODS_SCORE, REQUESTS_IN_PARALLEL: REQUESTS_IN_PARALLEL, + REQUESTS_INTERVAL: REQUESTS_INTERVAL, REQUESTS_LIMIT: REQUESTS_LIMIT, RETRY_REQUESTS: RETRY_REQUESTS, SEARCHABLE_COLUMNS: SEARCHABLE_COLUMNS, -- cgit v1.2.3 From c60f2212fd326c323dc2d145ba64080612b655d3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 27 Sep 2016 22:41:38 +0200 Subject: Server: migration script that add admin role to root user --- server/initializers/constants.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'server/initializers/constants.js') diff --git a/server/initializers/constants.js b/server/initializers/constants.js index 10ae48e95..02043bd45 100644 --- a/server/initializers/constants.js +++ b/server/initializers/constants.js @@ -62,9 +62,13 @@ const MONGO_MIGRATION_SCRIPTS = [ { script: '0010-users-password', version: 10 + }, + { + script: '0015-admin-role', + version: 15 } ] -const LAST_MONGO_SCHEMA_VERSION = 10 +const LAST_MONGO_SCHEMA_VERSION = 15 // Time to wait between requests to the friends (10 min) let REQUESTS_INTERVAL = 600000 -- cgit v1.2.3 From 9f6bae3a9db13bf827f8aaff903aac06ec430903 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 2 Oct 2016 11:14:08 +0200 Subject: Server: reorganize constant file --- server/initializers/constants.js | 111 ++++++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 47 deletions(-) (limited to 'server/initializers/constants.js') diff --git a/server/initializers/constants.js b/server/initializers/constants.js index 02043bd45..b1d033377 100644 --- a/server/initializers/constants.js +++ b/server/initializers/constants.js @@ -3,10 +3,31 @@ const config = require('config') const path = require('path') -// API version of our pod +// --------------------------------------------------------------------------- + +// API version const API_VERSION = 'v1' -const BCRYPT_SALT_SIZE = 10 +// Number of results by default for the pagination +const PAGINATION_COUNT_DEFAULT = 15 + +// Sortable columns per schema +const SEARCHABLE_COLUMNS = { + VIDEOS: [ 'name', 'magnetUri', 'podUrl', 'author', 'tags' ] +} + +// Sortable columns per schema +const SORTABLE_COLUMNS = { + USERS: [ 'username', '-username', 'createdDate', '-createdDate' ], + VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdDate', '-createdDate' ] +} + +const OAUTH_LIFETIME = { + ACCESS_TOKEN: 3600 * 4, // 4 hours + REFRESH_TOKEN: 1209600 // 2 weeks +} + +// --------------------------------------------------------------------------- const CONFIG = { DATABASE: { @@ -31,6 +52,8 @@ const CONFIG = { } CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOST + ':' + CONFIG.WEBSERVER.PORT +// --------------------------------------------------------------------------- + const CONSTRAINTS_FIELDS = { USERS: { USERNAME: { min: 3, max: 20 }, // Length @@ -48,12 +71,16 @@ const CONSTRAINTS_FIELDS = { } } +// --------------------------------------------------------------------------- + // Score a pod has when we create it as a friend const FRIEND_SCORE = { BASE: 100, MAX: 1000 } +// --------------------------------------------------------------------------- + const MONGO_MIGRATION_SCRIPTS = [ { script: '0005-create-application', @@ -70,16 +97,7 @@ const MONGO_MIGRATION_SCRIPTS = [ ] const LAST_MONGO_SCHEMA_VERSION = 15 -// Time to wait between requests to the friends (10 min) -let REQUESTS_INTERVAL = 600000 - -const OAUTH_LIFETIME = { - ACCESS_TOKEN: 3600 * 4, // 4 hours - REFRESH_TOKEN: 1209600 // 2 weeks -} - -// Number of results by default for the pagination -const PAGINATION_COUNT_DEFAULT = 15 +// --------------------------------------------------------------------------- // Number of points we add/remove from a friend after a successful/bad request const PODS_SCORE = { @@ -87,29 +105,22 @@ const PODS_SCORE = { BONUS: 10 } +// Time to wait between requests to the friends (10 min) +let REQUESTS_INTERVAL = 600000 + // Number of requests in parallel we can make const REQUESTS_IN_PARALLEL = 10 -// How many requests we put in request (request scheduler) +// How many requests we put in request const REQUESTS_LIMIT = 10 // Number of requests to retry for replay requests module const RETRY_REQUESTS = 5 -// Sortable columns per schema -const SEARCHABLE_COLUMNS = { - VIDEOS: [ 'name', 'magnetUri', 'podUrl', 'author', 'tags' ] -} - -// Seeds in parallel we send to electron when "seed all" -// Once a video is in seeding state we seed another video etc -const SEEDS_IN_PARALLEL = 3 +// --------------------------------------------------------------------------- -// Sortable columns per schema -const SORTABLE_COLUMNS = { - USERS: [ 'username', '-username', 'createdDate', '-createdDate' ], - VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdDate', '-createdDate' ] -} +// Password encryption +const BCRYPT_SALT_SIZE = 10 // Videos thumbnail size const THUMBNAILS_SIZE = '200x110' @@ -122,36 +133,42 @@ const USER_ROLES = { USER: 'user' } +// Seeds in parallel we send to electron when "seed all" +// Once a video is in seeding state we seed another video etc +const SEEDS_IN_PARALLEL = 3 + +// --------------------------------------------------------------------------- + // Special constants for a test instance if (isTestInstance() === true) { + CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14 FRIEND_SCORE.BASE = 20 REQUESTS_INTERVAL = 10000 - CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14 } // --------------------------------------------------------------------------- module.exports = { - API_VERSION: API_VERSION, - BCRYPT_SALT_SIZE: BCRYPT_SALT_SIZE, - CONFIG: CONFIG, - CONSTRAINTS_FIELDS: CONSTRAINTS_FIELDS, - FRIEND_SCORE: FRIEND_SCORE, - LAST_MONGO_SCHEMA_VERSION: LAST_MONGO_SCHEMA_VERSION, - MONGO_MIGRATION_SCRIPTS: MONGO_MIGRATION_SCRIPTS, - OAUTH_LIFETIME: OAUTH_LIFETIME, - PAGINATION_COUNT_DEFAULT: PAGINATION_COUNT_DEFAULT, - PODS_SCORE: PODS_SCORE, - REQUESTS_IN_PARALLEL: REQUESTS_IN_PARALLEL, - REQUESTS_INTERVAL: REQUESTS_INTERVAL, - REQUESTS_LIMIT: REQUESTS_LIMIT, - RETRY_REQUESTS: RETRY_REQUESTS, - SEARCHABLE_COLUMNS: SEARCHABLE_COLUMNS, - SEEDS_IN_PARALLEL: SEEDS_IN_PARALLEL, - SORTABLE_COLUMNS: SORTABLE_COLUMNS, - THUMBNAILS_SIZE: THUMBNAILS_SIZE, - THUMBNAILS_STATIC_PATH: THUMBNAILS_STATIC_PATH, - USER_ROLES: USER_ROLES + API_VERSION, + BCRYPT_SALT_SIZE, + CONFIG, + CONSTRAINTS_FIELDS, + FRIEND_SCORE, + LAST_MONGO_SCHEMA_VERSION, + MONGO_MIGRATION_SCRIPTS, + OAUTH_LIFETIME, + PAGINATION_COUNT_DEFAULT, + PODS_SCORE, + REQUESTS_IN_PARALLEL, + REQUESTS_INTERVAL, + REQUESTS_LIMIT, + RETRY_REQUESTS, + SEARCHABLE_COLUMNS, + SEEDS_IN_PARALLEL, + SORTABLE_COLUMNS, + THUMBNAILS_SIZE, + THUMBNAILS_STATIC_PATH, + USER_ROLES } // --------------------------------------------------------------------------- -- cgit v1.2.3