]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/initializers/constants.js
Server: forbid to make friends with a non https server
[github/Chocobozzz/PeerTube.git] / server / initializers / constants.js
index 8a8d5c1ce562ad7986dedd7042d37aecc3f07c44..3ddf87454e0e234ffaf3215cfd6c2fa0f088c9c1 100644 (file)
@@ -1,6 +1,7 @@
 'use strict'
 
 const config = require('config')
+const maxBy = require('lodash/maxBy')
 const path = require('path')
 
 // ---------------------------------------------------------------------------
@@ -13,7 +14,7 @@ const PAGINATION_COUNT_DEFAULT = 15
 
 // Sortable columns per schema
 const SEARCHABLE_COLUMNS = {
-  VIDEOS: [ 'name', 'magnetUri', 'podUrl', 'author', 'tags' ]
+  VIDEOS: [ 'name', 'magnetUri', 'podHost', 'author', 'tags' ]
 }
 
 // Sortable columns per schema
@@ -30,9 +31,12 @@ const OAUTH_LIFETIME = {
 // ---------------------------------------------------------------------------
 
 const CONFIG = {
+  LISTEN: {
+    PORT: config.get('listen.port')
+  },
   DATABASE: {
     DBNAME: 'peertube' + config.get('database.suffix'),
-    HOST: config.get('database.host'),
+    HOSTNAME: config.get('database.hostname'),
     PORT: config.get('database.port')
   },
   STORAGE: {
@@ -40,16 +44,18 @@ const CONFIG = {
     LOG_DIR: path.join(__dirname, '..', '..', config.get('storage.logs')),
     VIDEOS_DIR: path.join(__dirname, '..', '..', config.get('storage.videos')),
     THUMBNAILS_DIR: path.join(__dirname, '..', '..', config.get('storage.thumbnails')),
+    PREVIEWS_DIR: path.join(__dirname, '..', '..', config.get('storage.previews')),
     TORRENTS_DIR: path.join(__dirname, '..', '..', config.get('storage.torrents'))
   },
   WEBSERVER: {
     SCHEME: config.get('webserver.https') === true ? 'https' : 'http',
     WS: config.get('webserver.https') === true ? 'wss' : 'ws',
-    HOST: config.get('webserver.host'),
+    HOSTNAME: config.get('webserver.hostname'),
     PORT: config.get('webserver.port')
   }
 }
-CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOST + ':' + CONFIG.WEBSERVER.PORT
+CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
+CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
 
 // ---------------------------------------------------------------------------
 
@@ -61,7 +67,9 @@ const CONSTRAINTS_FIELDS = {
   VIDEOS: {
     NAME: { min: 3, max: 50 }, // Length
     DESCRIPTION: { min: 3, max: 250 }, // Length
-    MAGNET_URI: { min: 10 }, // Length
+    MAGNET: {
+      INFO_HASH: { min: 10, max: 50 } // Length
+    },
     DURATION: { min: 1, max: 7200 }, // Number
     TAGS: { min: 1, max: 3 }, // Number of total tags
     TAG: { min: 2, max: 10 }, // Length
@@ -92,9 +100,29 @@ const MONGO_MIGRATION_SCRIPTS = [
   {
     script: '0015-admin-role',
     version: 15
+  },
+  {
+    script: '0020-requests-endpoint',
+    version: 20
+  },
+  {
+    script: '0025-video-filenames',
+    version: 25
+  },
+  {
+    script: '0030-video-magnet',
+    version: 30
+  },
+  {
+    script: '0035-url-to-host',
+    version: 35
+  },
+  {
+    script: '0040-video-remote-id',
+    version: 40
   }
 ]
-const LAST_MONGO_SCHEMA_VERSION = 15
+const LAST_MONGO_SCHEMA_VERSION = (maxBy(MONGO_MIGRATION_SCRIPTS, 'version'))['version']
 
 // ---------------------------------------------------------------------------
 
@@ -116,14 +144,24 @@ const REQUESTS_LIMIT = 10
 // Number of requests to retry for replay requests module
 const RETRY_REQUESTS = 5
 
+const REQUEST_ENDPOINTS = {
+  VIDEOS: 'videos'
+}
+
 // ---------------------------------------------------------------------------
 
+const REMOTE_SCHEME = {
+  HTTP: 'https',
+  WS: 'wss'
+}
+
 // Password encryption
 const BCRYPT_SALT_SIZE = 10
 
 // Express static paths (router)
 const STATIC_PATHS = {
-  THUMBNAILS: '/static/thumbnails',
+  PREVIEWS: '/static/previews/',
+  THUMBNAILS: '/static/thumbnails/',
   TORRENTS: '/static/torrents/',
   WEBSEED: '/static/webseed/'
 }
@@ -133,6 +171,7 @@ let STATIC_MAX_AGE = '30d'
 
 // Videos thumbnail size
 const THUMBNAILS_SIZE = '200x110'
+const PREVIEWS_SIZE = '640x480'
 
 const USER_ROLES = {
   ADMIN: 'admin',
@@ -146,6 +185,8 @@ if (isTestInstance() === true) {
   CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
   FRIEND_SCORE.BASE = 20
   REQUESTS_INTERVAL = 10000
+  REMOTE_SCHEME.HTTP = 'http'
+  REMOTE_SCHEME.WS = 'ws'
   STATIC_MAX_AGE = 0
 }
 
@@ -162,6 +203,9 @@ module.exports = {
   OAUTH_LIFETIME,
   PAGINATION_COUNT_DEFAULT,
   PODS_SCORE,
+  PREVIEWS_SIZE,
+  REMOTE_SCHEME,
+  REQUEST_ENDPOINTS,
   REQUESTS_IN_PARALLEL,
   REQUESTS_INTERVAL,
   REQUESTS_LIMIT,
@@ -176,6 +220,7 @@ module.exports = {
 
 // ---------------------------------------------------------------------------
 
+// This method exists in utils module but we want to let the constants module independent
 function isTestInstance () {
   return (process.env.NODE_ENV === 'test')
 }