]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/initializers/constants.js
Server: add database field validations
[github/Chocobozzz/PeerTube.git] / server / initializers / constants.js
index d345776ff2afb53e74cd371cfce281ce637b5e2f..0af7aca3c39040cb0ed1d61411c0f6a3b0477739 100644 (file)
@@ -1,7 +1,6 @@
 'use strict'
 
 const config = require('config')
-const maxBy = require('lodash/maxBy')
 const path = require('path')
 
 // ---------------------------------------------------------------------------
@@ -14,13 +13,13 @@ const PAGINATION_COUNT_DEFAULT = 15
 
 // Sortable columns per schema
 const SEARCHABLE_COLUMNS = {
-  VIDEOS: [ 'name', 'magnetUri', 'podUrl', 'author', 'tags' ]
+  VIDEOS: [ 'name', 'magnetUri', 'host', 'author', 'tags' ]
 }
 
 // Sortable columns per schema
 const SORTABLE_COLUMNS = {
-  USERS: [ 'username', '-username', 'createdDate', '-createdDate' ],
-  VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdDate', '-createdDate' ]
+  USERS: [ 'username', '-username', 'createdAt', '-createdAt' ],
+  VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdAt', '-createdAt' ]
 }
 
 const OAUTH_LIFETIME = {
@@ -37,13 +36,16 @@ const CONFIG = {
   DATABASE: {
     DBNAME: 'peertube' + config.get('database.suffix'),
     HOSTNAME: config.get('database.hostname'),
-    PORT: config.get('database.port')
+    PORT: config.get('database.port'),
+    USERNAME: config.get('database.username'),
+    PASSWORD: config.get('database.password')
   },
   STORAGE: {
     CERT_DIR: path.join(__dirname, '..', '..', config.get('storage.certs')),
     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: {
@@ -54,6 +56,7 @@ const CONFIG = {
   }
 }
 CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
+CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
 
 // ---------------------------------------------------------------------------
 
@@ -65,7 +68,8 @@ const CONSTRAINTS_FIELDS = {
   VIDEOS: {
     NAME: { min: 3, max: 50 }, // Length
     DESCRIPTION: { min: 3, max: 250 }, // Length
-    MAGNET_URI: { min: 10 }, // Length
+    EXTNAME: [ '.mp4', '.ogv', '.webm' ],
+    INFO_HASH: { min: 40, max: 40 }, // Length, infohash is 20 bytes length but we represent it in hexa so 20 * 2
     DURATION: { min: 1, max: 7200 }, // Number
     TAGS: { min: 1, max: 3 }, // Number of total tags
     TAG: { min: 2, max: 10 }, // Length
@@ -84,25 +88,7 @@ const FRIEND_SCORE = {
 
 // ---------------------------------------------------------------------------
 
-const MONGO_MIGRATION_SCRIPTS = [
-  {
-    script: '0005-create-application',
-    version: 5
-  },
-  {
-    script: '0010-users-password',
-    version: 10
-  },
-  {
-    script: '0015-admin-role',
-    version: 15
-  },
-  {
-    script: '0020-requests-endpoint',
-    version: 20
-  }
-]
-const LAST_MONGO_SCHEMA_VERSION = (maxBy(MONGO_MIGRATION_SCRIPTS, 'version'))['version']
+const LAST_MIGRATION_VERSION = 0
 
 // ---------------------------------------------------------------------------
 
@@ -130,12 +116,18 @@ const REQUEST_ENDPOINTS = {
 
 // ---------------------------------------------------------------------------
 
+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/'
 }
@@ -145,6 +137,7 @@ let STATIC_MAX_AGE = '30d'
 
 // Videos thumbnail size
 const THUMBNAILS_SIZE = '200x110'
+const PREVIEWS_SIZE = '640x480'
 
 const USER_ROLES = {
   ADMIN: 'admin',
@@ -158,6 +151,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
 }
 
@@ -169,11 +164,12 @@ module.exports = {
   CONFIG,
   CONSTRAINTS_FIELDS,
   FRIEND_SCORE,
-  LAST_MONGO_SCHEMA_VERSION,
-  MONGO_MIGRATION_SCRIPTS,
+  LAST_MIGRATION_VERSION,
   OAUTH_LIFETIME,
   PAGINATION_COUNT_DEFAULT,
   PODS_SCORE,
+  PREVIEWS_SIZE,
+  REMOTE_SCHEME,
   REQUEST_ENDPOINTS,
   REQUESTS_IN_PARALLEL,
   REQUESTS_INTERVAL,
@@ -189,6 +185,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')
 }