aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-03-16 22:29:27 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-03-16 22:29:27 +0100
commitf0f5567b6918fc60c8cab15e13aec03a89a91dfb (patch)
tree99dfdb9fa8273c9cda1360fd3b6bfccc515bf8be /server
parent5101105ef91bfe478f97546b78b321882da2079c (diff)
downloadPeerTube-f0f5567b6918fc60c8cab15e13aec03a89a91dfb.tar.gz
PeerTube-f0f5567b6918fc60c8cab15e13aec03a89a91dfb.tar.zst
PeerTube-f0f5567b6918fc60c8cab15e13aec03a89a91dfb.zip
Use const/let now we use node 4.2
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/v1/index.js10
-rw-r--r--server/controllers/api/v1/pods.js34
-rw-r--r--server/controllers/api/v1/remoteVideos.js20
-rw-r--r--server/controllers/api/v1/videos.js50
-rw-r--r--server/controllers/index.js4
-rw-r--r--server/helpers/customValidators.js4
-rw-r--r--server/helpers/logger.js10
-rw-r--r--server/helpers/peertubeCrypto.js50
-rw-r--r--server/helpers/requests.js51
-rw-r--r--server/helpers/utils.js4
-rw-r--r--server/initializers/checker.js20
-rw-r--r--server/initializers/constants.js10
-rw-r--r--server/initializers/database.js14
-rw-r--r--server/lib/friends.js62
-rw-r--r--server/lib/poolRequests.js36
-rw-r--r--server/lib/videos.js21
-rw-r--r--server/lib/webtorrent.js46
-rw-r--r--server/lib/webtorrentProcess.js38
-rw-r--r--server/middlewares/cache.js2
-rw-r--r--server/middlewares/index.js8
-rw-r--r--server/middlewares/reqValidators/index.js8
-rw-r--r--server/middlewares/reqValidators/pods.js8
-rw-r--r--server/middlewares/reqValidators/remote.js6
-rw-r--r--server/middlewares/reqValidators/utils.js8
-rw-r--r--server/middlewares/reqValidators/videos.js10
-rw-r--r--server/middlewares/secure.js12
-rw-r--r--server/models/pods.js14
-rw-r--r--server/models/poolRequests.js10
-rw-r--r--server/models/videos.js36
-rw-r--r--server/tests/api/checkParams.js70
-rw-r--r--server/tests/api/friendsAdvanced.js22
-rw-r--r--server/tests/api/friendsBasic.js36
-rw-r--r--server/tests/api/multiplePods.js46
-rw-r--r--server/tests/api/singlePod.js24
-rw-r--r--server/tests/api/utils.js62
-rw-r--r--server/tests/index.js8
36 files changed, 433 insertions, 441 deletions
diff --git a/server/controllers/api/v1/index.js b/server/controllers/api/v1/index.js
index b562bc2af..45f07ae1f 100644
--- a/server/controllers/api/v1/index.js
+++ b/server/controllers/api/v1/index.js
@@ -1,12 +1,12 @@
1'use strict' 1'use strict'
2 2
3var express = require('express') 3const express = require('express')
4 4
5var router = express.Router() 5const router = express.Router()
6 6
7var podsController = require('./pods') 7const podsController = require('./pods')
8var remoteVideosController = require('./remoteVideos') 8const remoteVideosController = require('./remoteVideos')
9var videosController = require('./videos') 9const videosController = require('./videos')
10 10
11router.use('/pods', podsController) 11router.use('/pods', podsController)
12router.use('/remotevideos', remoteVideosController) 12router.use('/remotevideos', remoteVideosController)
diff --git a/server/controllers/api/v1/pods.js b/server/controllers/api/v1/pods.js
index fa9832914..dbe1a7372 100644
--- a/server/controllers/api/v1/pods.js
+++ b/server/controllers/api/v1/pods.js
@@ -1,20 +1,20 @@
1'use strict' 1'use strict'
2 2
3var express = require('express') 3const express = require('express')
4var fs = require('fs') 4const fs = require('fs')
5 5
6var logger = require('../../../helpers/logger') 6const logger = require('../../../helpers/logger')
7var friends = require('../../../lib/friends') 7const friends = require('../../../lib/friends')
8var middleware = require('../../../middlewares') 8const middleware = require('../../../middlewares')
9var cacheMiddleware = middleware.cache 9const cacheMiddleware = middleware.cache
10var peertubeCrypto = require('../../../helpers/peertubeCrypto') 10const peertubeCrypto = require('../../../helpers/peertubeCrypto')
11var Pods = require('../../../models/pods') 11const Pods = require('../../../models/pods')
12var reqValidator = middleware.reqValidators.pods 12const reqValidator = middleware.reqValidators.pods
13var secureMiddleware = middleware.secure 13const secureMiddleware = middleware.secure
14var secureRequest = middleware.reqValidators.remote.secureRequest 14const secureRequest = middleware.reqValidators.remote.secureRequest
15var Videos = require('../../../models/videos') 15const Videos = require('../../../models/videos')
16 16
17var router = express.Router() 17const router = express.Router()
18 18
19router.get('/', cacheMiddleware.cache(false), listPods) 19router.get('/', cacheMiddleware.cache(false), listPods)
20router.post('/', reqValidator.podsAdd, cacheMiddleware.cache(false), addPods) 20router.post('/', reqValidator.podsAdd, cacheMiddleware.cache(false), addPods)
@@ -30,7 +30,7 @@ module.exports = router
30// --------------------------------------------------------------------------- 30// ---------------------------------------------------------------------------
31 31
32function addPods (req, res, next) { 32function addPods (req, res, next) {
33 var informations = req.body.data 33 const informations = req.body.data
34 Pods.add(informations, function (err) { 34 Pods.add(informations, function (err) {
35 if (err) return next(err) 35 if (err) return next(err)
36 36
@@ -71,7 +71,7 @@ function makeFriends (req, res, next) {
71} 71}
72 72
73function removePods (req, res, next) { 73function removePods (req, res, next) {
74 var url = req.body.signature.url 74 const url = req.body.signature.url
75 Pods.remove(url, function (err) { 75 Pods.remove(url, function (err) {
76 if (err) return next(err) 76 if (err) return next(err)
77 77
diff --git a/server/controllers/api/v1/remoteVideos.js b/server/controllers/api/v1/remoteVideos.js
index 7622e39f5..58222de52 100644
--- a/server/controllers/api/v1/remoteVideos.js
+++ b/server/controllers/api/v1/remoteVideos.js
@@ -1,15 +1,15 @@
1'use strict' 1'use strict'
2 2
3var express = require('express') 3const express = require('express')
4var pluck = require('lodash-node/compat/collection/pluck') 4const pluck = require('lodash-node/compat/collection/pluck')
5 5
6var middleware = require('../../../middlewares') 6const middleware = require('../../../middlewares')
7var secureMiddleware = middleware.secure 7const secureMiddleware = middleware.secure
8var cacheMiddleware = middleware.cache 8const cacheMiddleware = middleware.cache
9var reqValidator = middleware.reqValidators.remote 9const reqValidator = middleware.reqValidators.remote
10var videos = require('../../../models/videos') 10const videos = require('../../../models/videos')
11 11
12var router = express.Router() 12const router = express.Router()
13 13
14router.post('/add', 14router.post('/add',
15 reqValidator.secureRequest, 15 reqValidator.secureRequest,
@@ -42,8 +42,8 @@ function addRemoteVideos (req, res, next) {
42} 42}
43 43
44function removeRemoteVideo (req, res, next) { 44function removeRemoteVideo (req, res, next) {
45 var url = req.body.signature.url 45 const url = req.body.signature.url
46 var magnetUris = pluck(req.body.data, 'magnetUri') 46 const magnetUris = pluck(req.body.data, 'magnetUri')
47 47
48 videos.removeRemotesOfByMagnetUris(url, magnetUris, function (err) { 48 videos.removeRemotesOfByMagnetUris(url, magnetUris, function (err) {
49 if (err) return next(err) 49 if (err) return next(err)
diff --git a/server/controllers/api/v1/videos.js b/server/controllers/api/v1/videos.js
index 76cad62d1..1eea417d4 100644
--- a/server/controllers/api/v1/videos.js
+++ b/server/controllers/api/v1/videos.js
@@ -1,41 +1,41 @@
1'use strict' 1'use strict'
2 2
3var config = require('config') 3const config = require('config')
4var crypto = require('crypto') 4const crypto = require('crypto')
5var express = require('express') 5const express = require('express')
6var multer = require('multer') 6const multer = require('multer')
7 7
8var logger = require('../../../helpers/logger') 8const logger = require('../../../helpers/logger')
9var friends = require('../../../lib/friends') 9const friends = require('../../../lib/friends')
10var middleware = require('../../../middlewares') 10const middleware = require('../../../middlewares')
11var cacheMiddleware = middleware.cache 11const cacheMiddleware = middleware.cache
12var reqValidator = middleware.reqValidators.videos 12const reqValidator = middleware.reqValidators.videos
13var Videos = require('../../../models/videos') // model 13const Videos = require('../../../models/videos') // model
14var videos = require('../../../lib/videos') 14const videos = require('../../../lib/videos')
15var webtorrent = require('../../../lib/webtorrent') 15const webtorrent = require('../../../lib/webtorrent')
16 16
17var router = express.Router() 17const router = express.Router()
18var uploads = config.get('storage.uploads') 18const uploads = config.get('storage.uploads')
19 19
20// multer configuration 20// multer configuration
21var storage = multer.diskStorage({ 21const storage = multer.diskStorage({
22 destination: function (req, file, cb) { 22 destination: function (req, file, cb) {
23 cb(null, uploads) 23 cb(null, uploads)
24 }, 24 },
25 25
26 filename: function (req, file, cb) { 26 filename: function (req, file, cb) {
27 var extension = '' 27 let extension = ''
28 if (file.mimetype === 'video/webm') extension = 'webm' 28 if (file.mimetype === 'video/webm') extension = 'webm'
29 else if (file.mimetype === 'video/mp4') extension = 'mp4' 29 else if (file.mimetype === 'video/mp4') extension = 'mp4'
30 else if (file.mimetype === 'video/ogg') extension = 'ogv' 30 else if (file.mimetype === 'video/ogg') extension = 'ogv'
31 crypto.pseudoRandomBytes(16, function (err, raw) { 31 crypto.pseudoRandomBytes(16, function (err, raw) {
32 var fieldname = err ? undefined : raw.toString('hex') 32 const fieldname = err ? undefined : raw.toString('hex')
33 cb(null, fieldname + '.' + extension) 33 cb(null, fieldname + '.' + extension)
34 }) 34 })
35 } 35 }
36}) 36})
37 37
38var reqFiles = multer({ storage: storage }).fields([{ name: 'input_video', maxCount: 1 }]) 38const reqFiles = multer({ storage: storage }).fields([{ name: 'input_video', maxCount: 1 }])
39 39
40router.get('/', cacheMiddleware.cache(false), listVideos) 40router.get('/', cacheMiddleware.cache(false), listVideos)
41router.post('/', reqFiles, reqValidator.videosAdd, cacheMiddleware.cache(false), addVideo) 41router.post('/', reqFiles, reqValidator.videosAdd, cacheMiddleware.cache(false), addVideo)
@@ -50,8 +50,8 @@ module.exports = router
50// --------------------------------------------------------------------------- 50// ---------------------------------------------------------------------------
51 51
52function addVideo (req, res, next) { 52function addVideo (req, res, next) {
53 var video_file = req.files.input_video[0] 53 const video_file = req.files.input_video[0]
54 var video_infos = req.body 54 const video_infos = req.body
55 55
56 videos.seed(video_file.path, function (err, torrent) { 56 videos.seed(video_file.path, function (err, torrent) {
57 if (err) { 57 if (err) {
@@ -59,7 +59,7 @@ function addVideo (req, res, next) {
59 return next(err) 59 return next(err)
60 } 60 }
61 61
62 var video_data = { 62 const video_data = {
63 name: video_infos.name, 63 name: video_infos.name,
64 namePath: video_file.filename, 64 namePath: video_file.filename,
65 description: video_infos.description, 65 description: video_infos.description,
@@ -103,7 +103,7 @@ function listVideos (req, res, next) {
103} 103}
104 104
105function removeVideo (req, res, next) { 105function removeVideo (req, res, next) {
106 var video_id = req.params.id 106 const video_id = req.params.id
107 Videos.get(video_id, function (err, video) { 107 Videos.get(video_id, function (err, video) {
108 if (err) return next(err) 108 if (err) return next(err)
109 109
@@ -111,7 +111,7 @@ function removeVideo (req, res, next) {
111 Videos.removeOwned(req.params.id, function (err) { 111 Videos.removeOwned(req.params.id, function (err) {
112 if (err) return next(err) 112 if (err) return next(err)
113 113
114 var params = { 114 const params = {
115 name: video.name, 115 name: video.name,
116 magnetUri: video.magnetUri 116 magnetUri: video.magnetUri
117 } 117 }
diff --git a/server/controllers/index.js b/server/controllers/index.js
index 7b0288dbb..4c1d3dafe 100644
--- a/server/controllers/index.js
+++ b/server/controllers/index.js
@@ -1,8 +1,8 @@
1'use strict' 1'use strict'
2 2
3var constants = require('../initializers/constants') 3const constants = require('../initializers/constants')
4 4
5var apiController = require('./api/' + constants.API_VERSION) 5const apiController = require('./api/' + constants.API_VERSION)
6 6
7module.exports = { 7module.exports = {
8 api: apiController 8 api: apiController
diff --git a/server/helpers/customValidators.js b/server/helpers/customValidators.js
index 20c41f5da..a5ae32780 100644
--- a/server/helpers/customValidators.js
+++ b/server/helpers/customValidators.js
@@ -1,8 +1,8 @@
1'use strict' 1'use strict'
2 2
3var validator = require('validator') 3const validator = require('validator')
4 4
5var customValidators = { 5const customValidators = {
6 eachIsRemoteVideosAddValid: eachIsRemoteVideosAddValid, 6 eachIsRemoteVideosAddValid: eachIsRemoteVideosAddValid,
7 eachIsRemoteVideosRemoveValid: eachIsRemoteVideosRemoveValid, 7 eachIsRemoteVideosRemoveValid: eachIsRemoteVideosRemoveValid,
8 isArray: isArray 8 isArray: isArray
diff --git a/server/helpers/logger.js b/server/helpers/logger.js
index 1c15a0edd..d3fce4cc9 100644
--- a/server/helpers/logger.js
+++ b/server/helpers/logger.js
@@ -1,13 +1,13 @@
1// Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/ 1// Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/
2'use strict' 2'use strict'
3 3
4var config = require('config') 4const config = require('config')
5var path = require('path') 5const path = require('path')
6var winston = require('winston') 6const winston = require('winston')
7winston.emitErrs = true 7winston.emitErrs = true
8 8
9var logDir = path.join(__dirname, '..', '..', config.get('storage.logs')) 9const logDir = path.join(__dirname, '..', '..', config.get('storage.logs'))
10var logger = new winston.Logger({ 10const logger = new winston.Logger({
11 transports: [ 11 transports: [
12 new winston.transports.File({ 12 new winston.transports.File({
13 level: 'debug', 13 level: 'debug',
diff --git a/server/helpers/peertubeCrypto.js b/server/helpers/peertubeCrypto.js
index 7e65c43e1..3826ebaf6 100644
--- a/server/helpers/peertubeCrypto.js
+++ b/server/helpers/peertubeCrypto.js
@@ -1,18 +1,18 @@
1'use strict' 1'use strict'
2 2
3var config = require('config') 3const config = require('config')
4var crypto = require('crypto') 4const crypto = require('crypto')
5var fs = require('fs') 5const fs = require('fs')
6var openssl = require('openssl-wrapper') 6const openssl = require('openssl-wrapper')
7var path = require('path') 7const path = require('path')
8var ursa = require('ursa') 8const ursa = require('ursa')
9 9
10var logger = require('./logger') 10const logger = require('./logger')
11 11
12var certDir = path.join(__dirname, '..', '..', config.get('storage.certs')) 12const certDir = path.join(__dirname, '..', '..', config.get('storage.certs'))
13var algorithm = 'aes-256-ctr' 13const algorithm = 'aes-256-ctr'
14 14
15var peertubeCrypto = { 15const peertubeCrypto = {
16 checkSignature: checkSignature, 16 checkSignature: checkSignature,
17 createCertsIfNotExist: createCertsIfNotExist, 17 createCertsIfNotExist: createCertsIfNotExist,
18 decrypt: decrypt, 18 decrypt: decrypt,
@@ -22,8 +22,8 @@ var peertubeCrypto = {
22} 22}
23 23
24function checkSignature (public_key, raw_data, hex_signature) { 24function checkSignature (public_key, raw_data, hex_signature) {
25 var crt = ursa.createPublicKey(public_key) 25 const crt = ursa.createPublicKey(public_key)
26 var is_valid = crt.hashAndVerify('sha256', new Buffer(raw_data).toString('hex'), hex_signature, 'hex') 26 const is_valid = crt.hashAndVerify('sha256', new Buffer(raw_data).toString('hex'), hex_signature, 'hex')
27 return is_valid 27 return is_valid
28} 28}
29 29
@@ -43,22 +43,22 @@ function decrypt (key, data, callback) {
43 fs.readFile(getCertDir() + 'peertube.key.pem', function (err, file) { 43 fs.readFile(getCertDir() + 'peertube.key.pem', function (err, file) {
44 if (err) return callback(err) 44 if (err) return callback(err)
45 45
46 var my_private_key = ursa.createPrivateKey(file) 46 const my_private_key = ursa.createPrivateKey(file)
47 var decrypted_key = my_private_key.decrypt(key, 'hex', 'utf8') 47 const decrypted_key = my_private_key.decrypt(key, 'hex', 'utf8')
48 var decrypted_data = symetricDecrypt(data, decrypted_key) 48 const decrypted_data = symetricDecrypt(data, decrypted_key)
49 49
50 return callback(null, decrypted_data) 50 return callback(null, decrypted_data)
51 }) 51 })
52} 52}
53 53
54function encrypt (public_key, data, callback) { 54function encrypt (public_key, data, callback) {
55 var crt = ursa.createPublicKey(public_key) 55 const crt = ursa.createPublicKey(public_key)
56 56
57 symetricEncrypt(data, function (err, dataEncrypted) { 57 symetricEncrypt(data, function (err, dataEncrypted) {
58 if (err) return callback(err) 58 if (err) return callback(err)
59 59
60 var key = crt.encrypt(dataEncrypted.password, 'utf8', 'hex') 60 const key = crt.encrypt(dataEncrypted.password, 'utf8', 'hex')
61 var encrypted = { 61 const encrypted = {
62 data: dataEncrypted.crypted, 62 data: dataEncrypted.crypted,
63 key: key 63 key: key
64 } 64 }
@@ -72,8 +72,8 @@ function getCertDir () {
72} 72}
73 73
74function sign (data) { 74function sign (data) {
75 var myKey = ursa.createPrivateKey(fs.readFileSync(certDir + 'peertube.key.pem')) 75 const myKey = ursa.createPrivateKey(fs.readFileSync(certDir + 'peertube.key.pem'))
76 var signature = myKey.hashAndSign('sha256', data, 'utf8', 'hex') 76 const signature = myKey.hashAndSign('sha256', data, 'utf8', 'hex')
77 77
78 return signature 78 return signature
79} 79}
@@ -93,7 +93,7 @@ function certsExist (callback) {
93function createCerts (callback) { 93function createCerts (callback) {
94 certsExist(function (exist) { 94 certsExist(function (exist) {
95 if (exist === true) { 95 if (exist === true) {
96 var string = 'Certs already exist.' 96 const string = 'Certs already exist.'
97 logger.warning(string) 97 logger.warning(string)
98 return callback(new Error(string)) 98 return callback(new Error(string))
99 } 99 }
@@ -129,8 +129,8 @@ function generatePassword (callback) {
129} 129}
130 130
131function symetricDecrypt (text, password) { 131function symetricDecrypt (text, password) {
132 var decipher = crypto.createDecipher(algorithm, password) 132 const decipher = crypto.createDecipher(algorithm, password)
133 var dec = decipher.update(text, 'hex', 'utf8') 133 let dec = decipher.update(text, 'hex', 'utf8')
134 dec += decipher.final('utf8') 134 dec += decipher.final('utf8')
135 return dec 135 return dec
136} 136}
@@ -139,8 +139,8 @@ function symetricEncrypt (text, callback) {
139 generatePassword(function (err, password) { 139 generatePassword(function (err, password) {
140 if (err) return callback(err) 140 if (err) return callback(err)
141 141
142 var cipher = crypto.createCipher(algorithm, password) 142 const cipher = crypto.createCipher(algorithm, password)
143 var crypted = cipher.update(text, 'utf8', 'hex') 143 let crypted = cipher.update(text, 'utf8', 'hex')
144 crypted += cipher.final('hex') 144 crypted += cipher.final('hex')
145 callback(null, { crypted: crypted, password: password }) 145 callback(null, { crypted: crypted, password: password })
146 }) 146 })
diff --git a/server/helpers/requests.js b/server/helpers/requests.js
index e19afa5ca..17b1127c0 100644
--- a/server/helpers/requests.js
+++ b/server/helpers/requests.js
@@ -1,19 +1,19 @@
1'use strict' 1'use strict'
2 2
3var async = require('async') 3const async = require('async')
4var config = require('config') 4const config = require('config')
5var request = require('request') 5const request = require('request')
6var replay = require('request-replay') 6const replay = require('request-replay')
7 7
8var constants = require('../initializers/constants') 8const constants = require('../initializers/constants')
9var logger = require('./logger') 9const logger = require('./logger')
10var peertubeCrypto = require('./peertubeCrypto') 10const peertubeCrypto = require('./peertubeCrypto')
11 11
12var http = config.get('webserver.https') ? 'https' : 'http' 12const http = config.get('webserver.https') ? 'https' : 'http'
13var host = config.get('webserver.host') 13const host = config.get('webserver.host')
14var port = config.get('webserver.port') 14const port = config.get('webserver.port')
15 15
16var requests = { 16const requests = {
17 makeMultipleRetryRequest: makeMultipleRetryRequest 17 makeMultipleRetryRequest: makeMultipleRetryRequest
18} 18}
19 19
@@ -23,8 +23,8 @@ function makeMultipleRetryRequest (all_data, pods, callbackEach, callback) {
23 callbackEach = null 23 callbackEach = null
24 } 24 }
25 25
26 var url = http + '://' + host + ':' + port 26 const url = http + '://' + host + ':' + port
27 var signature 27 let signature
28 28
29 // Add signature if it is specified in the params 29 // Add signature if it is specified in the params
30 if (all_data.method === 'POST' && all_data.data && all_data.sign === true) { 30 if (all_data.method === 'POST' && all_data.data && all_data.sign === true) {
@@ -43,7 +43,7 @@ function makeMultipleRetryRequest (all_data, pods, callbackEach, callback) {
43 } 43 }
44 } 44 }
45 45
46 var params = { 46 const params = {
47 url: pod.url + all_data.path, 47 url: pod.url + all_data.path,
48 method: all_data.method 48 method: all_data.method
49 } 49 }
@@ -52,19 +52,16 @@ function makeMultipleRetryRequest (all_data, pods, callbackEach, callback) {
52 if (all_data.method === 'POST' && all_data.data) { 52 if (all_data.method === 'POST' && all_data.data) {
53 // Encrypt data ? 53 // Encrypt data ?
54 if (all_data.encrypt === true) { 54 if (all_data.encrypt === true) {
55 // TODO: ES6 with let 55 peertubeCrypto.encrypt(pod.publicKey, JSON.stringify(all_data.data), function (err, encrypted) {
56 ;(function (copy_params, copy_url, copy_pod, copy_signature) { 56 if (err) return callback(err)
57 peertubeCrypto.encrypt(pod.publicKey, JSON.stringify(all_data.data), function (err, encrypted) { 57
58 if (err) return callback(err) 58 params.json = {
59 59 data: encrypted.data,
60 copy_params.json = { 60 key: encrypted.key
61 data: encrypted.data, 61 }
62 key: encrypted.key 62
63 } 63 makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest)
64 64 })
65 makeRetryRequest(copy_params, copy_url, copy_pod, copy_signature, callbackEachRetryRequest)
66 })
67 })(params, url, pod, signature)
68 } else { 65 } else {
69 params.json = { data: all_data.data } 66 params.json = { data: all_data.data }
70 makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest) 67 makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest)
diff --git a/server/helpers/utils.js b/server/helpers/utils.js
index d2c9ad8b2..1f7839673 100644
--- a/server/helpers/utils.js
+++ b/server/helpers/utils.js
@@ -1,8 +1,8 @@
1'use strict' 1'use strict'
2 2
3var logger = require('./logger') 3const logger = require('./logger')
4 4
5var utils = { 5const utils = {
6 cleanForExit: cleanForExit 6 cleanForExit: cleanForExit
7} 7}
8 8
diff --git a/server/initializers/checker.js b/server/initializers/checker.js
index 44d9ea85b..a21e54982 100644
--- a/server/initializers/checker.js
+++ b/server/initializers/checker.js
@@ -1,24 +1,24 @@
1'use strict' 1'use strict'
2 2
3var config = require('config') 3const config = require('config')
4var mkdirp = require('mkdirp') 4const mkdirp = require('mkdirp')
5var path = require('path') 5const path = require('path')
6 6
7var checker = { 7const checker = {
8 checkConfig: checkConfig, 8 checkConfig: checkConfig,
9 createDirectoriesIfNotExist: createDirectoriesIfNotExist 9 createDirectoriesIfNotExist: createDirectoriesIfNotExist
10} 10}
11 11
12// Check the config files 12// Check the config files
13function checkConfig () { 13function checkConfig () {
14 var required = [ 'listen.port', 14 const required = [ 'listen.port',
15 'webserver.https', 'webserver.host', 'webserver.port', 15 'webserver.https', 'webserver.host', 'webserver.port',
16 'database.host', 'database.port', 'database.suffix', 16 'database.host', 'database.port', 'database.suffix',
17 'storage.certs', 'storage.uploads', 'storage.logs', 17 'storage.certs', 'storage.uploads', 'storage.logs',
18 'network.friends' ] 18 'network.friends' ]
19 var miss = [] 19 const miss = []
20 20
21 for (var key of required) { 21 for (const key of required) {
22 if (!config.has(key)) { 22 if (!config.has(key)) {
23 miss.push(key) 23 miss.push(key)
24 } 24 }
@@ -29,10 +29,10 @@ function checkConfig () {
29 29
30// Create directories for the storage if it doesn't exist 30// Create directories for the storage if it doesn't exist
31function createDirectoriesIfNotExist () { 31function createDirectoriesIfNotExist () {
32 var storages = config.get('storage') 32 const storages = config.get('storage')
33 33
34 for (var key of Object.keys(storages)) { 34 for (const key of Object.keys(storages)) {
35 var dir = storages[key] 35 const dir = storages[key]
36 try { 36 try {
37 mkdirp.sync(path.join(__dirname, '..', '..', dir)) 37 mkdirp.sync(path.join(__dirname, '..', '..', dir))
38 } catch (error) { 38 } catch (error) {
diff --git a/server/initializers/constants.js b/server/initializers/constants.js
index 16e50443b..dc08805b9 100644
--- a/server/initializers/constants.js
+++ b/server/initializers/constants.js
@@ -1,22 +1,22 @@
1'use strict' 1'use strict'
2 2
3// API version of our pod 3// API version of our pod
4var API_VERSION = 'v1' 4const API_VERSION = 'v1'
5 5
6// Score a pod has when we create it as a friend 6// Score a pod has when we create it as a friend
7var FRIEND_BASE_SCORE = 100 7let FRIEND_BASE_SCORE = 100
8 8
9// Time to wait between requests to the friends 9// Time to wait between requests to the friends
10var INTERVAL = 60000 10let INTERVAL = 60000
11 11
12// Number of points we add/remove from a friend after a successful/bad request 12// Number of points we add/remove from a friend after a successful/bad request
13var PODS_SCORE = { 13const PODS_SCORE = {
14 MALUS: -10, 14 MALUS: -10,
15 BONUS: 10 15 BONUS: 10
16} 16}
17 17
18// Number of retries we make for the make retry requests (to friends...) 18// Number of retries we make for the make retry requests (to friends...)
19var REQUEST_RETRIES = 10 19let REQUEST_RETRIES = 10
20 20
21// Special constants for a test instance 21// Special constants for a test instance
22if (isTestInstance() === true) { 22if (isTestInstance() === true) {
diff --git a/server/initializers/database.js b/server/initializers/database.js
index a917442ec..830cc7dd8 100644
--- a/server/initializers/database.js
+++ b/server/initializers/database.js
@@ -1,15 +1,15 @@
1'use strict' 1'use strict'
2 2
3var config = require('config') 3const config = require('config')
4var mongoose = require('mongoose') 4const mongoose = require('mongoose')
5 5
6var logger = require('../helpers/logger') 6const logger = require('../helpers/logger')
7 7
8var dbname = 'peertube' + config.get('database.suffix') 8const dbname = 'peertube' + config.get('database.suffix')
9var host = config.get('database.host') 9const host = config.get('database.host')
10var port = config.get('database.port') 10const port = config.get('database.port')
11 11
12var database = { 12const database = {
13 connect: connect 13 connect: connect
14} 14}
15 15
diff --git a/server/lib/friends.js b/server/lib/friends.js
index 006a64404..c3c231604 100644
--- a/server/lib/friends.js
+++ b/server/lib/friends.js
@@ -1,23 +1,23 @@
1'use strict' 1'use strict'
2 2
3var async = require('async') 3const async = require('async')
4var config = require('config') 4const config = require('config')
5var fs = require('fs') 5const fs = require('fs')
6var request = require('request') 6const request = require('request')
7 7
8var constants = require('../initializers/constants') 8const constants = require('../initializers/constants')
9var logger = require('../helpers/logger') 9const logger = require('../helpers/logger')
10var peertubeCrypto = require('../helpers/peertubeCrypto') 10const peertubeCrypto = require('../helpers/peertubeCrypto')
11var Pods = require('../models/pods') 11const Pods = require('../models/pods')
12var poolRequests = require('../lib/poolRequests') 12const poolRequests = require('../lib/poolRequests')
13var requests = require('../helpers/requests') 13const requests = require('../helpers/requests')
14var Videos = require('../models/videos') 14const Videos = require('../models/videos')
15 15
16var http = config.get('webserver.https') ? 'https' : 'http' 16const http = config.get('webserver.https') ? 'https' : 'http'
17var host = config.get('webserver.host') 17const host = config.get('webserver.host')
18var port = config.get('webserver.port') 18const port = config.get('webserver.port')
19 19
20var pods = { 20const pods = {
21 addVideoToFriends: addVideoToFriends, 21 addVideoToFriends: addVideoToFriends,
22 hasFriends: hasFriends, 22 hasFriends: hasFriends,
23 makeFriends: makeFriends, 23 makeFriends: makeFriends,
@@ -27,7 +27,7 @@ var pods = {
27 27
28function addVideoToFriends (video) { 28function addVideoToFriends (video) {
29 // To avoid duplicates 29 // To avoid duplicates
30 var id = video.name + video.magnetUri 30 const id = video.name + video.magnetUri
31 // ensure namePath is null 31 // ensure namePath is null
32 video.namePath = null 32 video.namePath = null
33 poolRequests.addRequest(id, 'add', video) 33 poolRequests.addRequest(id, 'add', video)
@@ -37,13 +37,13 @@ function hasFriends (callback) {
37 Pods.count(function (err, count) { 37 Pods.count(function (err, count) {
38 if (err) return callback(err) 38 if (err) return callback(err)
39 39
40 var has_friends = (count !== 0) 40 const has_friends = (count !== 0)
41 callback(null, has_friends) 41 callback(null, has_friends)
42 }) 42 })
43} 43}
44 44
45function makeFriends (callback) { 45function makeFriends (callback) {
46 var pods_score = {} 46 const pods_score = {}
47 47
48 logger.info('Make friends!') 48 logger.info('Make friends!')
49 fs.readFile(peertubeCrypto.getCertDir() + 'peertube.pub', 'utf8', function (err, cert) { 49 fs.readFile(peertubeCrypto.getCertDir() + 'peertube.pub', 'utf8', function (err, cert) {
@@ -52,7 +52,7 @@ function makeFriends (callback) {
52 return callback(err) 52 return callback(err)
53 } 53 }
54 54
55 var urls = config.get('network.friends') 55 const urls = config.get('network.friends')
56 56
57 async.each(urls, function (url, callback) { 57 async.each(urls, function (url, callback) {
58 computeForeignPodsList(url, pods_score, callback) 58 computeForeignPodsList(url, pods_score, callback)
@@ -60,8 +60,8 @@ function makeFriends (callback) {
60 if (err) return callback(err) 60 if (err) return callback(err)
61 61
62 logger.debug('Pods scores computed.', { pods_score: pods_score }) 62 logger.debug('Pods scores computed.', { pods_score: pods_score })
63 var pods_list = computeWinningPods(urls, pods_score) 63 const pods_list = computeWinningPods(urls, pods_score)
64 logger.debug('Pods that we keep computed.', { pods_to_keep: pods_list }) 64 logger.debug('Pods that we keep.', { pods_to_keep: pods_list })
65 65
66 makeRequestsToWinningPods(cert, pods_list, callback) 66 makeRequestsToWinningPods(cert, pods_list, callback)
67 }) 67 })
@@ -77,7 +77,7 @@ function quitFriends (callback) {
77 Pods.list(function (err, pods) { 77 Pods.list(function (err, pods) {
78 if (err) return callback(err) 78 if (err) return callback(err)
79 79
80 var request = { 80 const request = {
81 method: 'POST', 81 method: 'POST',
82 path: '/api/' + constants.API_VERSION + '/pods/remove', 82 path: '/api/' + constants.API_VERSION + '/pods/remove',
83 sign: true, 83 sign: true,
@@ -109,7 +109,7 @@ function quitFriends (callback) {
109 109
110function removeVideoToFriends (video) { 110function removeVideoToFriends (video) {
111 // To avoid duplicates 111 // To avoid duplicates
112 var id = video.name + video.magnetUri 112 const id = video.name + video.magnetUri
113 poolRequests.addRequest(id, 'remove', video) 113 poolRequests.addRequest(id, 'remove', video)
114} 114}
115 115
@@ -128,7 +128,7 @@ function computeForeignPodsList (url, pods_score, callback) {
128 if (foreign_pods_list.length === 0) return callback() 128 if (foreign_pods_list.length === 0) return callback()
129 129
130 async.each(foreign_pods_list, function (foreign_pod, callback_each) { 130 async.each(foreign_pods_list, function (foreign_pod, callback_each) {
131 var foreign_url = foreign_pod.url 131 const foreign_url = foreign_pod.url
132 132
133 if (pods_score[foreign_url]) pods_score[foreign_url]++ 133 if (pods_score[foreign_url]) pods_score[foreign_url]++
134 else pods_score[foreign_url] = 1 134 else pods_score[foreign_url] = 1
@@ -143,8 +143,8 @@ function computeForeignPodsList (url, pods_score, callback) {
143function computeWinningPods (urls, pods_score) { 143function computeWinningPods (urls, pods_score) {
144 // Build the list of pods to add 144 // Build the list of pods to add
145 // Only add a pod if it exists in more than a half base pods 145 // Only add a pod if it exists in more than a half base pods
146 var pods_list = [] 146 const pods_list = []
147 var base_score = urls.length / 2 147 const base_score = urls.length / 2
148 Object.keys(pods_score).forEach(function (pod) { 148 Object.keys(pods_score).forEach(function (pod) {
149 if (pods_score[pod] > base_score) pods_list.push({ url: pod }) 149 if (pods_score[pod] > base_score) pods_list.push({ url: pod })
150 }) 150 })
@@ -153,7 +153,7 @@ function computeWinningPods (urls, pods_score) {
153} 153}
154 154
155function getForeignPodsList (url, callback) { 155function getForeignPodsList (url, callback) {
156 var path = '/api/' + constants.API_VERSION + '/pods' 156 const path = '/api/' + constants.API_VERSION + '/pods'
157 157
158 request.get(url + path, function (err, response, body) { 158 request.get(url + path, function (err, response, body) {
159 if (err) return callback(err) 159 if (err) return callback(err)
@@ -175,7 +175,7 @@ function makeRequestsToWinningPods (cert, pods_list, callback) {
175 return callback(err) 175 return callback(err)
176 } 176 }
177 177
178 var data = { 178 const data = {
179 url: http + '://' + host + ':' + port, 179 url: http + '://' + host + ':' + port,
180 publicKey: cert, 180 publicKey: cert,
181 videos: videos_list 181 videos: videos_list
diff --git a/server/lib/poolRequests.js b/server/lib/poolRequests.js
index f786c3c7a..2eb501311 100644
--- a/server/lib/poolRequests.js
+++ b/server/lib/poolRequests.js
@@ -1,18 +1,18 @@
1'use strict' 1'use strict'
2 2
3var async = require('async') 3const async = require('async')
4var pluck = require('lodash-node/compat/collection/pluck') 4const pluck = require('lodash-node/compat/collection/pluck')
5 5
6var constants = require('../initializers/constants') 6const constants = require('../initializers/constants')
7var logger = require('../helpers/logger') 7const logger = require('../helpers/logger')
8var Pods = require('../models/pods') 8const Pods = require('../models/pods')
9var PoolRequests = require('../models/poolRequests') 9const PoolRequests = require('../models/poolRequests')
10var requests = require('../helpers/requests') 10const requests = require('../helpers/requests')
11var Videos = require('../models/videos') 11const Videos = require('../models/videos')
12 12
13var timer = null 13let timer = null
14 14
15var poolRequests = { 15const poolRequests = {
16 activate: activate, 16 activate: activate,
17 addRequest: addRequest, 17 addRequest: addRequest,
18 deactivate: deactivate, 18 deactivate: deactivate,
@@ -77,7 +77,7 @@ function makePoolRequest (type, requests_to_make, callback) {
77 Pods.list(function (err, pods) { 77 Pods.list(function (err, pods) {
78 if (err) return callback(err) 78 if (err) return callback(err)
79 79
80 var params = { 80 const params = {
81 encrypt: true, 81 encrypt: true,
82 sign: true, 82 sign: true,
83 method: 'POST', 83 method: 'POST',
@@ -93,8 +93,8 @@ function makePoolRequest (type, requests_to_make, callback) {
93 return callback(new Error('Unkown pool request type.')) 93 return callback(new Error('Unkown pool request type.'))
94 } 94 }
95 95
96 var bad_pods = [] 96 const bad_pods = []
97 var good_pods = [] 97 const good_pods = []
98 98
99 requests.makeMultipleRetryRequest(params, pods, callbackEachPodFinished, callbackAllPodsFinished) 99 requests.makeMultipleRetryRequest(params, pods, callbackEachPodFinished, callbackAllPodsFinished)
100 100
@@ -129,7 +129,7 @@ function makePoolRequests () {
129 129
130 if (pool_requests.length === 0) return 130 if (pool_requests.length === 0) return
131 131
132 var requests_to_make = { 132 const requests_to_make = {
133 add: { 133 add: {
134 ids: [], 134 ids: [],
135 requests: [] 135 requests: []
@@ -184,14 +184,14 @@ function removeBadPods () {
184 184
185 if (pods.length === 0) return 185 if (pods.length === 0) return
186 186
187 var urls = pluck(pods, 'url') 187 const urls = pluck(pods, 'url')
188 var ids = pluck(pods, '_id') 188 const ids = pluck(pods, '_id')
189 189
190 Videos.removeAllRemotesOf(urls, function (err, r) { 190 Videos.removeAllRemotesOf(urls, function (err, r) {
191 if (err) { 191 if (err) {
192 logger.error('Cannot remove videos from a pod that we removing.', { error: err }) 192 logger.error('Cannot remove videos from a pod that we removing.', { error: err })
193 } else { 193 } else {
194 var videos_removed = r.result.n 194 const videos_removed = r.result.n
195 logger.info('Removed %d videos.', videos_removed) 195 logger.info('Removed %d videos.', videos_removed)
196 } 196 }
197 197
@@ -199,7 +199,7 @@ function removeBadPods () {
199 if (err) { 199 if (err) {
200 logger.error('Cannot remove bad pods.', { error: err }) 200 logger.error('Cannot remove bad pods.', { error: err })
201 } else { 201 } else {
202 var pods_removed = r.result.n 202 const pods_removed = r.result.n
203 logger.info('Removed %d pods.', pods_removed) 203 logger.info('Removed %d pods.', pods_removed)
204 } 204 }
205 }) 205 })
diff --git a/server/lib/videos.js b/server/lib/videos.js
index a5fe7b0c4..eb3a0125a 100644
--- a/server/lib/videos.js
+++ b/server/lib/videos.js
@@ -1,25 +1,24 @@
1'use strict' 1'use strict'
2 2
3var async = require('async') 3const async = require('async')
4var config = require('config') 4const config = require('config')
5// TODO 5const pathUtils = require('path')
6var path = require('path') 6const webtorrent = require('../lib/webtorrent')
7var webtorrent = require('../lib/webtorrent')
8 7
9var logger = require('../helpers/logger') 8const logger = require('../helpers/logger')
10var Videos = require('../models/videos') 9const Videos = require('../models/videos')
11 10
12var uploadDir = path.join(__dirname, '..', '..', config.get('storage.uploads')) 11const uploadDir = pathUtils.join(__dirname, '..', '..', config.get('storage.uploads'))
13 12
14var videos = { 13const videos = {
15 getVideoState: getVideoState, 14 getVideoState: getVideoState,
16 seed: seed, 15 seed: seed,
17 seedAllExisting: seedAllExisting 16 seedAllExisting: seedAllExisting
18} 17}
19 18
20function getVideoState (video, callback) { 19function getVideoState (video, callback) {
21 var exist = (video !== null) 20 const exist = (video !== null)
22 var owned = false 21 let owned = false
23 if (exist === true) { 22 if (exist === true) {
24 owned = (video.namePath !== null) 23 owned = (video.namePath !== null)
25 } 24 }
diff --git a/server/lib/webtorrent.js b/server/lib/webtorrent.js
index cb641fead..455b086a3 100644
--- a/server/lib/webtorrent.js
+++ b/server/lib/webtorrent.js
@@ -1,20 +1,20 @@
1'use strict' 1'use strict'
2 2
3var config = require('config') 3const config = require('config')
4var ipc = require('node-ipc') 4const ipc = require('node-ipc')
5var pathUtils = require('path') 5const pathUtils = require('path')
6var spawn = require('electron-spawn') 6const spawn = require('electron-spawn')
7 7
8var logger = require('../helpers/logger') 8const logger = require('../helpers/logger')
9 9
10var host = config.get('webserver.host') 10let host = config.get('webserver.host')
11var port = config.get('webserver.port') 11let port = config.get('webserver.port')
12var nodeKey = 'webtorrentnode' + port 12let nodeKey = 'webtorrentnode' + port
13var processKey = 'webtorrentprocess' + port 13let processKey = 'webtorrentprocess' + port
14ipc.config.silent = true 14ipc.config.silent = true
15ipc.config.id = nodeKey 15ipc.config.id = nodeKey
16 16
17var webtorrent = { 17const webtorrent = {
18 add: add, 18 add: add,
19 app: null, // Pid of the app 19 app: null, // Pid of the app
20 create: create, 20 create: create,
@@ -42,7 +42,7 @@ function create (options, callback) {
42 if (!webtorrent.silent) logger.info('IPC server ready.') 42 if (!webtorrent.silent) logger.info('IPC server ready.')
43 43
44 // Run a timeout of 30s after which we exit the process 44 // Run a timeout of 30s after which we exit the process
45 var timeout_webtorrent_process = setTimeout(function () { 45 const timeout_webtorrent_process = setTimeout(function () {
46 throw new Error('Timeout : cannot run the webtorrent process. Please ensure you have electron-prebuilt npm package installed with xvfb-run.') 46 throw new Error('Timeout : cannot run the webtorrent process. Please ensure you have electron-prebuilt npm package installed with xvfb-run.')
47 }, 30000) 47 }, 30000)
48 48
@@ -56,7 +56,7 @@ function create (options, callback) {
56 throw new Error('Received exception error from webtorrent process.' + data.exception) 56 throw new Error('Received exception error from webtorrent process.' + data.exception)
57 }) 57 })
58 58
59 var webtorrent_process = spawn(pathUtils.join(__dirname, 'webtorrentProcess.js'), host, port, { detached: true }) 59 const webtorrent_process = spawn(pathUtils.join(__dirname, 'webtorrentProcess.js'), host, port, { detached: true })
60 webtorrent_process.stderr.on('data', function (data) { 60 webtorrent_process.stderr.on('data', function (data) {
61 // logger.debug('Webtorrent process stderr: ', data.toString()) 61 // logger.debug('Webtorrent process stderr: ', data.toString())
62 }) 62 })
@@ -72,9 +72,9 @@ function create (options, callback) {
72} 72}
73 73
74function seed (path, callback) { 74function seed (path, callback) {
75 var extension = pathUtils.extname(path) 75 const extension = pathUtils.extname(path)
76 var basename = pathUtils.basename(path, extension) 76 const basename = pathUtils.basename(path, extension)
77 var data = { 77 const data = {
78 _id: basename, 78 _id: basename,
79 args: { 79 args: {
80 path: path 80 path: path
@@ -84,12 +84,12 @@ function seed (path, callback) {
84 if (!webtorrent.silent) logger.debug('Node wants to seed %s.', data._id) 84 if (!webtorrent.silent) logger.debug('Node wants to seed %s.', data._id)
85 85
86 // Finish signal 86 // Finish signal
87 var event_key = nodeKey + '.seedDone.' + data._id 87 const event_key = nodeKey + '.seedDone.' + data._id
88 ipc.server.on(event_key, function listener (received) { 88 ipc.server.on(event_key, function listener (received) {
89 if (!webtorrent.silent) logger.debug('Process seeded torrent %s.', received.magnetUri) 89 if (!webtorrent.silent) logger.debug('Process seeded torrent %s.', received.magnetUri)
90 90
91 // This is a fake object, we just use the magnetUri in this project 91 // This is a fake object, we just use the magnetUri in this project
92 var torrent = { 92 const torrent = {
93 magnetURI: received.magnetUri 93 magnetURI: received.magnetUri
94 } 94 }
95 95
@@ -101,7 +101,7 @@ function seed (path, callback) {
101} 101}
102 102
103function add (magnetUri, callback) { 103function add (magnetUri, callback) {
104 var data = { 104 const data = {
105 _id: magnetUri, 105 _id: magnetUri,
106 args: { 106 args: {
107 magnetUri: magnetUri 107 magnetUri: magnetUri
@@ -111,12 +111,12 @@ function add (magnetUri, callback) {
111 if (!webtorrent.silent) logger.debug('Node wants to add ' + data._id) 111 if (!webtorrent.silent) logger.debug('Node wants to add ' + data._id)
112 112
113 // Finish signal 113 // Finish signal
114 var event_key = nodeKey + '.addDone.' + data._id 114 const event_key = nodeKey + '.addDone.' + data._id
115 ipc.server.on(event_key, function (received) { 115 ipc.server.on(event_key, function (received) {
116 if (!webtorrent.silent) logger.debug('Process added torrent.') 116 if (!webtorrent.silent) logger.debug('Process added torrent.')
117 117
118 // This is a fake object, we just use the magnetUri in this project 118 // This is a fake object, we just use the magnetUri in this project
119 var torrent = { 119 const torrent = {
120 files: received.files 120 files: received.files
121 } 121 }
122 122
@@ -128,7 +128,7 @@ function add (magnetUri, callback) {
128} 128}
129 129
130function remove (magnetUri, callback) { 130function remove (magnetUri, callback) {
131 var data = { 131 const data = {
132 _id: magnetUri, 132 _id: magnetUri,
133 args: { 133 args: {
134 magnetUri: magnetUri 134 magnetUri: magnetUri
@@ -138,11 +138,11 @@ function remove (magnetUri, callback) {
138 if (!webtorrent.silent) logger.debug('Node wants to stop seeding %s.', data._id) 138 if (!webtorrent.silent) logger.debug('Node wants to stop seeding %s.', data._id)
139 139
140 // Finish signal 140 // Finish signal
141 var event_key = nodeKey + '.removeDone.' + data._id 141 const event_key = nodeKey + '.removeDone.' + data._id
142 ipc.server.on(event_key, function (received) { 142 ipc.server.on(event_key, function (received) {
143 if (!webtorrent.silent) logger.debug('Process removed torrent %s.', data._id) 143 if (!webtorrent.silent) logger.debug('Process removed torrent %s.', data._id)
144 144
145 var err = null 145 let err = null
146 if (received.err) err = received.err 146 if (received.err) err = received.err
147 147
148 ipc.server.off(event_key) 148 ipc.server.off(event_key)
diff --git a/server/lib/webtorrentProcess.js b/server/lib/webtorrentProcess.js
index 7da52523a..c68e97ee4 100644
--- a/server/lib/webtorrentProcess.js
+++ b/server/lib/webtorrentProcess.js
@@ -1,32 +1,32 @@
1'use strict' 1'use strict'
2 2
3var WebTorrent = require('webtorrent') 3const WebTorrent = require('webtorrent')
4var ipc = require('node-ipc') 4const ipc = require('node-ipc')
5 5
6function webtorrent (args) { 6function webtorrent (args) {
7 if (args.length !== 3) { 7 if (args.length !== 3) {
8 throw new Error('Wrong arguments number: ' + args.length + '/3') 8 throw new Error('Wrong arguments number: ' + args.length + '/3')
9 } 9 }
10 10
11 var host = args[1] 11 const host = args[1]
12 var port = args[2] 12 const port = args[2]
13 var nodeKey = 'webtorrentnode' + port 13 const nodeKey = 'webtorrentnode' + port
14 var processKey = 'webtorrentprocess' + port 14 const processKey = 'webtorrentprocess' + port
15 15
16 ipc.config.silent = true 16 ipc.config.silent = true
17 ipc.config.id = processKey 17 ipc.config.id = processKey
18 18
19 if (host === 'client' && port === '1') global.WEBTORRENT_ANNOUNCE = [] 19 if (host === 'client' && port === '1') global.WEBTORRENT_ANNOUNCE = []
20 else global.WEBTORRENT_ANNOUNCE = 'ws://' + host + ':' + port + '/tracker/socket' 20 else global.WEBTORRENT_ANNOUNCE = 'ws://' + host + ':' + port + '/tracker/socket'
21 var wt = new WebTorrent({ dht: false }) 21 const wt = new WebTorrent({ dht: false })
22 22
23 function seed (data) { 23 function seed (data) {
24 var args = data.args 24 const args = data.args
25 var path = args.path 25 const path = args.path
26 var _id = data._id 26 const _id = data._id
27 27
28 wt.seed(path, { announceList: '' }, function (torrent) { 28 wt.seed(path, { announceList: '' }, function (torrent) {
29 var to_send = { 29 const to_send = {
30 magnetUri: torrent.magnetURI 30 magnetUri: torrent.magnetURI
31 } 31 }
32 32
@@ -35,12 +35,12 @@ function webtorrent (args) {
35 } 35 }
36 36
37 function add (data) { 37 function add (data) {
38 var args = data.args 38 const args = data.args
39 var magnetUri = args.magnetUri 39 const magnetUri = args.magnetUri
40 var _id = data._id 40 const _id = data._id
41 41
42 wt.add(magnetUri, function (torrent) { 42 wt.add(magnetUri, function (torrent) {
43 var to_send = { 43 const to_send = {
44 files: [] 44 files: []
45 } 45 }
46 46
@@ -53,9 +53,9 @@ function webtorrent (args) {
53 } 53 }
54 54
55 function remove (data) { 55 function remove (data) {
56 var args = data.args 56 const args = data.args
57 var magnetUri = args.magnetUri 57 const magnetUri = args.magnetUri
58 var _id = data._id 58 const _id = data._id
59 59
60 try { 60 try {
61 wt.remove(magnetUri, callback) 61 wt.remove(magnetUri, callback)
@@ -65,7 +65,7 @@ function webtorrent (args) {
65 } 65 }
66 66
67 function callback () { 67 function callback () {
68 var to_send = {} 68 const to_send = {}
69 ipc.of[nodeKey].emit(nodeKey + '.removeDone.' + _id, to_send) 69 ipc.of[nodeKey].emit(nodeKey + '.removeDone.' + _id, to_send)
70 } 70 }
71 } 71 }
diff --git a/server/middlewares/cache.js b/server/middlewares/cache.js
index 0d3da0075..1b621f6dc 100644
--- a/server/middlewares/cache.js
+++ b/server/middlewares/cache.js
@@ -1,6 +1,6 @@
1'use strict' 1'use strict'
2 2
3var cacheMiddleware = { 3const cacheMiddleware = {
4 cache: cache 4 cache: cache
5} 5}
6 6
diff --git a/server/middlewares/index.js b/server/middlewares/index.js
index c85899b0c..d85f6261c 100644
--- a/server/middlewares/index.js
+++ b/server/middlewares/index.js
@@ -1,10 +1,10 @@
1'use strict' 1'use strict'
2 2
3var cacheMiddleware = require('./cache') 3const cacheMiddleware = require('./cache')
4var reqValidatorsMiddleware = require('./reqValidators') 4const reqValidatorsMiddleware = require('./reqValidators')
5var secureMiddleware = require('./secure') 5const secureMiddleware = require('./secure')
6 6
7var middlewares = { 7const middlewares = {
8 cache: cacheMiddleware, 8 cache: cacheMiddleware,
9 reqValidators: reqValidatorsMiddleware, 9 reqValidators: reqValidatorsMiddleware,
10 secure: secureMiddleware 10 secure: secureMiddleware
diff --git a/server/middlewares/reqValidators/index.js b/server/middlewares/reqValidators/index.js
index 345dbd0e2..c6c5e1309 100644
--- a/server/middlewares/reqValidators/index.js
+++ b/server/middlewares/reqValidators/index.js
@@ -1,10 +1,10 @@
1'use strict' 1'use strict'
2 2
3var podsReqValidators = require('./pods') 3const podsReqValidators = require('./pods')
4var remoteReqValidators = require('./remote') 4const remoteReqValidators = require('./remote')
5var videosReqValidators = require('./videos') 5const videosReqValidators = require('./videos')
6 6
7var reqValidators = { 7const reqValidators = {
8 pods: podsReqValidators, 8 pods: podsReqValidators,
9 remote: remoteReqValidators, 9 remote: remoteReqValidators,
10 videos: videosReqValidators 10 videos: videosReqValidators
diff --git a/server/middlewares/reqValidators/pods.js b/server/middlewares/reqValidators/pods.js
index ef09d51cf..45e34c1ab 100644
--- a/server/middlewares/reqValidators/pods.js
+++ b/server/middlewares/reqValidators/pods.js
@@ -1,10 +1,10 @@
1'use strict' 1'use strict'
2 2
3var checkErrors = require('./utils').checkErrors 3const checkErrors = require('./utils').checkErrors
4var friends = require('../../lib/friends') 4const friends = require('../../lib/friends')
5var logger = require('../../helpers/logger') 5const logger = require('../../helpers/logger')
6 6
7var reqValidatorsPod = { 7const reqValidatorsPod = {
8 makeFriends: makeFriends, 8 makeFriends: makeFriends,
9 podsAdd: podsAdd 9 podsAdd: podsAdd
10} 10}
diff --git a/server/middlewares/reqValidators/remote.js b/server/middlewares/reqValidators/remote.js
index 88de16b49..3bc0e0f40 100644
--- a/server/middlewares/reqValidators/remote.js
+++ b/server/middlewares/reqValidators/remote.js
@@ -1,9 +1,9 @@
1'use strict' 1'use strict'
2 2
3var checkErrors = require('./utils').checkErrors 3const checkErrors = require('./utils').checkErrors
4var logger = require('../../helpers/logger') 4const logger = require('../../helpers/logger')
5 5
6var reqValidatorsRemote = { 6const reqValidatorsRemote = {
7 remoteVideosAdd: remoteVideosAdd, 7 remoteVideosAdd: remoteVideosAdd,
8 remoteVideosRemove: remoteVideosRemove, 8 remoteVideosRemove: remoteVideosRemove,
9 secureRequest: secureRequest 9 secureRequest: secureRequest
diff --git a/server/middlewares/reqValidators/utils.js b/server/middlewares/reqValidators/utils.js
index 46c982571..05675c445 100644
--- a/server/middlewares/reqValidators/utils.js
+++ b/server/middlewares/reqValidators/utils.js
@@ -1,16 +1,16 @@
1'use strict' 1'use strict'
2 2
3var util = require('util') 3const util = require('util')
4 4
5var logger = require('../../helpers/logger') 5const logger = require('../../helpers/logger')
6 6
7var reqValidatorsUtils = { 7const reqValidatorsUtils = {
8 checkErrors: checkErrors 8 checkErrors: checkErrors
9} 9}
10 10
11function checkErrors (req, res, next, status_code) { 11function checkErrors (req, res, next, status_code) {
12 if (status_code === undefined) status_code = 400 12 if (status_code === undefined) status_code = 400
13 var errors = req.validationErrors() 13 const errors = req.validationErrors()
14 14
15 if (errors) { 15 if (errors) {
16 logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors }) 16 logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors })
diff --git a/server/middlewares/reqValidators/videos.js b/server/middlewares/reqValidators/videos.js
index b0a6d0360..4057e72cd 100644
--- a/server/middlewares/reqValidators/videos.js
+++ b/server/middlewares/reqValidators/videos.js
@@ -1,11 +1,11 @@
1'use strict' 1'use strict'
2 2
3var checkErrors = require('./utils').checkErrors 3const checkErrors = require('./utils').checkErrors
4var logger = require('../../helpers/logger') 4const logger = require('../../helpers/logger')
5var videos = require('../../lib/videos') 5const videos = require('../../lib/videos')
6var Videos = require('../../models/videos') 6const Videos = require('../../models/videos')
7 7
8var reqValidatorsVideos = { 8const reqValidatorsVideos = {
9 videosAdd: videosAdd, 9 videosAdd: videosAdd,
10 videosGet: videosGet, 10 videosGet: videosGet,
11 videosRemove: videosRemove, 11 videosRemove: videosRemove,
diff --git a/server/middlewares/secure.js b/server/middlewares/secure.js
index bfd28316a..9ecbf5df1 100644
--- a/server/middlewares/secure.js
+++ b/server/middlewares/secure.js
@@ -1,15 +1,15 @@
1'use strict' 1'use strict'
2 2
3var logger = require('../helpers/logger') 3const logger = require('../helpers/logger')
4var peertubeCrypto = require('../helpers/peertubeCrypto') 4const peertubeCrypto = require('../helpers/peertubeCrypto')
5var Pods = require('../models/pods') 5const Pods = require('../models/pods')
6 6
7var secureMiddleware = { 7const secureMiddleware = {
8 decryptBody: decryptBody 8 decryptBody: decryptBody
9} 9}
10 10
11function decryptBody (req, res, next) { 11function decryptBody (req, res, next) {
12 var url = req.body.signature.url 12 const url = req.body.signature.url
13 Pods.findByUrl(url, function (err, pod) { 13 Pods.findByUrl(url, function (err, pod) {
14 if (err) { 14 if (err) {
15 logger.error('Cannot get signed url in decryptBody.', { error: err }) 15 logger.error('Cannot get signed url in decryptBody.', { error: err })
@@ -23,7 +23,7 @@ function decryptBody (req, res, next) {
23 23
24 logger.debug('Decrypting body from %s.', url) 24 logger.debug('Decrypting body from %s.', url)
25 25
26 var signature_ok = peertubeCrypto.checkSignature(pod.publicKey, url, req.body.signature.signature) 26 const signature_ok = peertubeCrypto.checkSignature(pod.publicKey, url, req.body.signature.signature)
27 27
28 if (signature_ok === true) { 28 if (signature_ok === true) {
29 peertubeCrypto.decrypt(req.body.key, req.body.data, function (err, decrypted) { 29 peertubeCrypto.decrypt(req.body.key, req.body.data, function (err, decrypted) {
diff --git a/server/models/pods.js b/server/models/pods.js
index 57ed20292..4e21001f5 100644
--- a/server/models/pods.js
+++ b/server/models/pods.js
@@ -1,22 +1,22 @@
1'use strict' 1'use strict'
2 2
3var mongoose = require('mongoose') 3const mongoose = require('mongoose')
4 4
5var constants = require('../initializers/constants') 5const constants = require('../initializers/constants')
6var logger = require('../helpers/logger') 6const logger = require('../helpers/logger')
7 7
8// --------------------------------------------------------------------------- 8// ---------------------------------------------------------------------------
9 9
10var podsSchema = mongoose.Schema({ 10const podsSchema = mongoose.Schema({
11 url: String, 11 url: String,
12 publicKey: String, 12 publicKey: String,
13 score: { type: Number, max: constants.FRIEND_BASE_SCORE } 13 score: { type: Number, max: constants.FRIEND_BASE_SCORE }
14}) 14})
15var PodsDB = mongoose.model('pods', podsSchema) 15const PodsDB = mongoose.model('pods', podsSchema)
16 16
17// --------------------------------------------------------------------------- 17// ---------------------------------------------------------------------------
18 18
19var Pods = { 19const Pods = {
20 add: add, 20 add: add,
21 count: count, 21 count: count,
22 findByUrl: findByUrl, 22 findByUrl: findByUrl,
@@ -31,7 +31,7 @@ var Pods = {
31// TODO: check if the pod is not already a friend 31// TODO: check if the pod is not already a friend
32function add (data, callback) { 32function add (data, callback) {
33 if (!callback) callback = function () {} 33 if (!callback) callback = function () {}
34 var params = { 34 const params = {
35 url: data.url, 35 url: data.url,
36 publicKey: data.publicKey, 36 publicKey: data.publicKey,
37 score: constants.FRIEND_BASE_SCORE 37 score: constants.FRIEND_BASE_SCORE
diff --git a/server/models/poolRequests.js b/server/models/poolRequests.js
index 970315597..28093a94c 100644
--- a/server/models/poolRequests.js
+++ b/server/models/poolRequests.js
@@ -1,21 +1,21 @@
1'use strict' 1'use strict'
2 2
3var mongoose = require('mongoose') 3const mongoose = require('mongoose')
4 4
5var logger = require('../helpers/logger') 5const logger = require('../helpers/logger')
6 6
7// --------------------------------------------------------------------------- 7// ---------------------------------------------------------------------------
8 8
9var poolRequestsSchema = mongoose.Schema({ 9const poolRequestsSchema = mongoose.Schema({
10 type: String, 10 type: String,
11 id: String, // Special id to find duplicates (video created we want to remove...) 11 id: String, // Special id to find duplicates (video created we want to remove...)
12 request: mongoose.Schema.Types.Mixed 12 request: mongoose.Schema.Types.Mixed
13}) 13})
14var PoolRequestsDB = mongoose.model('poolRequests', poolRequestsSchema) 14const PoolRequestsDB = mongoose.model('poolRequests', poolRequestsSchema)
15 15
16// --------------------------------------------------------------------------- 16// ---------------------------------------------------------------------------
17 17
18var PoolRequests = { 18const PoolRequests = {
19 create: create, 19 create: create,
20 findById: findById, 20 findById: findById,
21 list: list, 21 list: list,
diff --git a/server/models/videos.js b/server/models/videos.js
index fd02ec9e1..0141cbb7f 100644
--- a/server/models/videos.js
+++ b/server/models/videos.js
@@ -1,33 +1,33 @@
1'use strict' 1'use strict'
2 2
3var async = require('async') 3const async = require('async')
4var config = require('config') 4const config = require('config')
5var dz = require('dezalgo') 5const dz = require('dezalgo')
6var fs = require('fs') 6const fs = require('fs')
7var mongoose = require('mongoose') 7const mongoose = require('mongoose')
8var path = require('path') 8const path = require('path')
9 9
10var logger = require('../helpers/logger') 10const logger = require('../helpers/logger')
11 11
12var http = config.get('webserver.https') === true ? 'https' : 'http' 12const http = config.get('webserver.https') === true ? 'https' : 'http'
13var host = config.get('webserver.host') 13const host = config.get('webserver.host')
14var port = config.get('webserver.port') 14const port = config.get('webserver.port')
15var uploadDir = path.join(__dirname, '..', '..', config.get('storage.uploads')) 15const uploadDir = path.join(__dirname, '..', '..', config.get('storage.uploads'))
16 16
17// --------------------------------------------------------------------------- 17// ---------------------------------------------------------------------------
18 18
19var videosSchema = mongoose.Schema({ 19const videosSchema = mongoose.Schema({
20 name: String, 20 name: String,
21 namePath: String, 21 namePath: String,
22 description: String, 22 description: String,
23 magnetUri: String, 23 magnetUri: String,
24 podUrl: String 24 podUrl: String
25}) 25})
26var VideosDB = mongoose.model('videos', videosSchema) 26const VideosDB = mongoose.model('videos', videosSchema)
27 27
28// --------------------------------------------------------------------------- 28// ---------------------------------------------------------------------------
29 29
30var Videos = { 30const Videos = {
31 add: add, 31 add: add,
32 addRemotes: addRemotes, 32 addRemotes: addRemotes,
33 get: get, 33 get: get,
@@ -43,7 +43,7 @@ var Videos = {
43function add (video, callback) { 43function add (video, callback) {
44 logger.info('Adding %s video to database.', video.name) 44 logger.info('Adding %s video to database.', video.name)
45 45
46 var params = video 46 const params = video
47 params.podUrl = http + '://' + host + ':' + port 47 params.podUrl = http + '://' + host + ':' + port
48 48
49 VideosDB.create(params, function (err, video) { 49 VideosDB.create(params, function (err, video) {
@@ -60,13 +60,13 @@ function add (video, callback) {
60function addRemotes (videos, callback) { 60function addRemotes (videos, callback) {
61 if (!callback) callback = function () {} 61 if (!callback) callback = function () {}
62 62
63 var to_add = [] 63 const to_add = []
64 64
65 async.each(videos, function (video, callback_each) { 65 async.each(videos, function (video, callback_each) {
66 callback_each = dz(callback_each) 66 callback_each = dz(callback_each)
67 logger.debug('Add remote video from pod: %s', video.podUrl) 67 logger.debug('Add remote video from pod: %s', video.podUrl)
68 68
69 var params = { 69 const params = {
70 name: video.name, 70 name: video.name,
71 namePath: null, 71 namePath: null,
72 description: video.description, 72 description: video.description,
@@ -159,7 +159,7 @@ function removeRemotesOfByMagnetUris (fromUrl, magnetUris, callback) {
159 return callback(err) 159 return callback(err)
160 } 160 }
161 161
162 var to_remove = [] 162 const to_remove = []
163 async.each(videos, function (video, callback_async) { 163 async.each(videos, function (video, callback_async) {
164 callback_async = dz(callback_async) 164 callback_async = dz(callback_async)
165 165
diff --git a/server/tests/api/checkParams.js b/server/tests/api/checkParams.js
index 01b620873..b31b0e894 100644
--- a/server/tests/api/checkParams.js
+++ b/server/tests/api/checkParams.js
@@ -1,27 +1,27 @@
1'use strict' 1'use strict'
2 2
3var async = require('async') 3const async = require('async')
4var chai = require('chai') 4const chai = require('chai')
5var expect = chai.expect 5const expect = chai.expect
6var pathUtils = require('path') 6const pathUtils = require('path')
7var request = require('supertest') 7const request = require('supertest')
8 8
9var utils = require('./utils') 9const utils = require('./utils')
10 10
11describe('Test parameters validator', function () { 11describe('Test parameters validator', function () {
12 var app = null 12 let app = null
13 var url = '' 13 let url = ''
14 14
15 function makePostRequest (path, fields, attach, done, fail) { 15 function makePostRequest (path, fields, attach, done, fail) {
16 var status_code = 400 16 let status_code = 400
17 if (fail !== undefined && fail === false) status_code = 200 17 if (fail !== undefined && fail === false) status_code = 200
18 18
19 var req = request(url) 19 const req = request(url)
20 .post(path) 20 .post(path)
21 .set('Accept', 'application/json') 21 .set('Accept', 'application/json')
22 22
23 Object.keys(fields).forEach(function (field) { 23 Object.keys(fields).forEach(function (field) {
24 var value = fields[field] 24 const value = fields[field]
25 req.field(field, value) 25 req.field(field, value)
26 }) 26 })
27 27
@@ -29,7 +29,7 @@ describe('Test parameters validator', function () {
29 } 29 }
30 30
31 function makePostBodyRequest (path, fields, done, fail) { 31 function makePostBodyRequest (path, fields, done, fail) {
32 var status_code = 400 32 let status_code = 400
33 if (fail !== undefined && fail === false) status_code = 200 33 if (fail !== undefined && fail === false) status_code = 200
34 34
35 request(url) 35 request(url)
@@ -59,16 +59,16 @@ describe('Test parameters validator', function () {
59 }) 59 })
60 60
61 describe('Of the pods API', function () { 61 describe('Of the pods API', function () {
62 var path = '/api/v1/pods/' 62 const path = '/api/v1/pods/'
63 63
64 describe('When adding a pod', function () { 64 describe('When adding a pod', function () {
65 it('Should fail with nothing', function (done) { 65 it('Should fail with nothing', function (done) {
66 var data = {} 66 const data = {}
67 makePostBodyRequest(path, data, done) 67 makePostBodyRequest(path, data, done)
68 }) 68 })
69 69
70 it('Should fail without public key', function (done) { 70 it('Should fail without public key', function (done) {
71 var data = { 71 const data = {
72 data: { 72 data: {
73 url: 'http://coucou.com' 73 url: 'http://coucou.com'
74 } 74 }
@@ -77,7 +77,7 @@ describe('Test parameters validator', function () {
77 }) 77 })
78 78
79 it('Should fail without an url', function (done) { 79 it('Should fail without an url', function (done) {
80 var data = { 80 const data = {
81 data: { 81 data: {
82 publicKey: 'mysuperpublickey' 82 publicKey: 'mysuperpublickey'
83 } 83 }
@@ -86,7 +86,7 @@ describe('Test parameters validator', function () {
86 }) 86 })
87 87
88 it('Should fail with an incorrect url', function (done) { 88 it('Should fail with an incorrect url', function (done) {
89 var data = { 89 const data = {
90 data: { 90 data: {
91 url: 'coucou.com', 91 url: 'coucou.com',
92 publicKey: 'mysuperpublickey' 92 publicKey: 'mysuperpublickey'
@@ -102,7 +102,7 @@ describe('Test parameters validator', function () {
102 }) 102 })
103 103
104 it('Should succeed with the correct parameters', function (done) { 104 it('Should succeed with the correct parameters', function (done) {
105 var data = { 105 const data = {
106 data: { 106 data: {
107 url: 'http://coucou.com', 107 url: 'http://coucou.com',
108 publicKey: 'mysuperpublickey' 108 publicKey: 'mysuperpublickey'
@@ -114,7 +114,7 @@ describe('Test parameters validator', function () {
114 }) 114 })
115 115
116 describe('Of the videos API', function () { 116 describe('Of the videos API', function () {
117 var path = '/api/v1/videos/' 117 const path = '/api/v1/videos/'
118 118
119 describe('When searching a video', function () { 119 describe('When searching a video', function () {
120 it('Should fail with nothing', function (done) { 120 it('Should fail with nothing', function (done) {
@@ -127,81 +127,81 @@ describe('Test parameters validator', function () {
127 127
128 describe('When adding a video', function () { 128 describe('When adding a video', function () {
129 it('Should fail with nothing', function (done) { 129 it('Should fail with nothing', function (done) {
130 var data = {} 130 const data = {}
131 var attach = {} 131 const attach = {}
132 makePostRequest(path, data, attach, done) 132 makePostRequest(path, data, attach, done)
133 }) 133 })
134 134
135 it('Should fail without name', function (done) { 135 it('Should fail without name', function (done) {
136 var data = { 136 const data = {
137 description: 'my super description' 137 description: 'my super description'
138 } 138 }
139 var attach = { 139 const attach = {
140 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 140 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
141 } 141 }
142 makePostRequest(path, data, attach, done) 142 makePostRequest(path, data, attach, done)
143 }) 143 })
144 144
145 it('Should fail with a long name', function (done) { 145 it('Should fail with a long name', function (done) {
146 var data = { 146 const data = {
147 name: 'My very very very very very very very very very very very very very very very very long name', 147 name: 'My very very very very very very very very very very very very very very very very long name',
148 description: 'my super description' 148 description: 'my super description'
149 } 149 }
150 var attach = { 150 const attach = {
151 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 151 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
152 } 152 }
153 makePostRequest(path, data, attach, done) 153 makePostRequest(path, data, attach, done)
154 }) 154 })
155 155
156 it('Should fail without description', function (done) { 156 it('Should fail without description', function (done) {
157 var data = { 157 const data = {
158 name: 'my super name' 158 name: 'my super name'
159 } 159 }
160 var attach = { 160 const attach = {
161 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 161 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
162 } 162 }
163 makePostRequest(path, data, attach, done) 163 makePostRequest(path, data, attach, done)
164 }) 164 })
165 165
166 it('Should fail with a long description', function (done) { 166 it('Should fail with a long description', function (done) {
167 var data = { 167 const data = {
168 name: 'my super name', 168 name: 'my super name',
169 description: 'my super description which is very very very very very very very very very very very very very very' + 169 description: 'my super description which is very very very very very very very very very very very very very very' +
170 'very very very very very very very very very very very very very very very very very very very very very' + 170 'very very very very very very very very very very very very very very very very very very very very very' +
171 'very very very very very very very very very very very very very very very long' 171 'very very very very very very very very very very very very very very very long'
172 } 172 }
173 var attach = { 173 const attach = {
174 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 174 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
175 } 175 }
176 makePostRequest(path, data, attach, done) 176 makePostRequest(path, data, attach, done)
177 }) 177 })
178 178
179 it('Should fail without an input file', function (done) { 179 it('Should fail without an input file', function (done) {
180 var data = { 180 const data = {
181 name: 'my super name', 181 name: 'my super name',
182 description: 'my super description' 182 description: 'my super description'
183 } 183 }
184 var attach = {} 184 const attach = {}
185 makePostRequest(path, data, attach, done) 185 makePostRequest(path, data, attach, done)
186 }) 186 })
187 187
188 it('Should fail without an incorrect input file', function (done) { 188 it('Should fail without an incorrect input file', function (done) {
189 var data = { 189 const data = {
190 name: 'my super name', 190 name: 'my super name',
191 description: 'my super description' 191 description: 'my super description'
192 } 192 }
193 var attach = { 193 const attach = {
194 'input_video': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm') 194 'input_video': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
195 } 195 }
196 makePostRequest(path, data, attach, done) 196 makePostRequest(path, data, attach, done)
197 }) 197 })
198 198
199 it('Should succeed with the correct parameters', function (done) { 199 it('Should succeed with the correct parameters', function (done) {
200 var data = { 200 const data = {
201 name: 'my super name', 201 name: 'my super name',
202 description: 'my super description' 202 description: 'my super description'
203 } 203 }
204 var attach = { 204 const attach = {
205 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 205 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
206 } 206 }
207 makePostRequest(path, data, attach, function () { 207 makePostRequest(path, data, attach, function () {
diff --git a/server/tests/api/friendsAdvanced.js b/server/tests/api/friendsAdvanced.js
index 9838d890f..6c4b7567f 100644
--- a/server/tests/api/friendsAdvanced.js
+++ b/server/tests/api/friendsAdvanced.js
@@ -1,14 +1,14 @@
1'use strict' 1'use strict'
2 2
3var async = require('async') 3const async = require('async')
4var chai = require('chai') 4const chai = require('chai')
5var expect = chai.expect 5const expect = chai.expect
6 6
7var utils = require('./utils') 7const utils = require('./utils')
8 8
9describe('Test advanced friends', function () { 9describe('Test advanced friends', function () {
10 var apps = [] 10 let apps = []
11 var urls = [] 11 let urls = []
12 12
13 function makeFriends (pod_number, callback) { 13 function makeFriends (pod_number, callback) {
14 return utils.makeFriends(urls[pod_number - 1], callback) 14 return utils.makeFriends(urls[pod_number - 1], callback)
@@ -23,9 +23,9 @@ describe('Test advanced friends', function () {
23 } 23 }
24 24
25 function uploadVideo (pod_number, callback) { 25 function uploadVideo (pod_number, callback) {
26 var name = 'my super video' 26 const name = 'my super video'
27 var description = 'my super description' 27 const description = 'my super description'
28 var fixture = 'video_short.webm' 28 const fixture = 'video_short.webm'
29 29
30 return utils.uploadVideo(urls[pod_number - 1], name, description, fixture, callback) 30 return utils.uploadVideo(urls[pod_number - 1], name, description, fixture, callback)
31 } 31 }
@@ -171,9 +171,9 @@ describe('Test advanced friends', function () {
171 if (err) throw err 171 if (err) throw err
172 172
173 // Pod 4 should not be our friend 173 // Pod 4 should not be our friend
174 var result = res.body 174 const result = res.body
175 expect(result.length).to.equal(3) 175 expect(result.length).to.equal(3)
176 for (var pod of result) { 176 for (const pod of result) {
177 expect(pod.url).not.equal(urls[3]) 177 expect(pod.url).not.equal(urls[3])
178 } 178 }
179 179
diff --git a/server/tests/api/friendsBasic.js b/server/tests/api/friendsBasic.js
index 328724936..62eac51ec 100644
--- a/server/tests/api/friendsBasic.js
+++ b/server/tests/api/friendsBasic.js
@@ -1,19 +1,19 @@
1'use strict' 1'use strict'
2 2
3var async = require('async') 3const async = require('async')
4var chai = require('chai') 4const chai = require('chai')
5var expect = chai.expect 5const expect = chai.expect
6var request = require('supertest') 6const request = require('supertest')
7 7
8var utils = require('./utils') 8const utils = require('./utils')
9 9
10describe('Test basic friends', function () { 10describe('Test basic friends', function () {
11 var apps = [] 11 let apps = []
12 var urls = [] 12 let urls = []
13 13
14 function testMadeFriends (urls, url_to_test, callback) { 14 function testMadeFriends (urls, url_to_test, callback) {
15 var friends = [] 15 const friends = []
16 for (var i = 0; i < urls.length; i++) { 16 for (let i = 0; i < urls.length; i++) {
17 if (urls[i] === url_to_test) continue 17 if (urls[i] === url_to_test) continue
18 friends.push(urls[i]) 18 friends.push(urls[i])
19 } 19 }
@@ -21,13 +21,13 @@ describe('Test basic friends', function () {
21 utils.getFriendsList(url_to_test, function (err, res) { 21 utils.getFriendsList(url_to_test, function (err, res) {
22 if (err) throw err 22 if (err) throw err
23 23
24 var result = res.body 24 const result = res.body
25 var result_urls = [ result[0].url, result[1].url ] 25 const result_urls = [ result[0].url, result[1].url ]
26 expect(result).to.be.an('array') 26 expect(result).to.be.an('array')
27 expect(result.length).to.equal(2) 27 expect(result.length).to.equal(2)
28 expect(result_urls[0]).to.not.equal(result_urls[1]) 28 expect(result_urls[0]).to.not.equal(result_urls[1])
29 29
30 var error_string = 'Friends url do not correspond for ' + url_to_test 30 const error_string = 'Friends url do not correspond for ' + url_to_test
31 expect(friends).to.contain(result_urls[0], error_string) 31 expect(friends).to.contain(result_urls[0], error_string)
32 expect(friends).to.contain(result_urls[1], error_string) 32 expect(friends).to.contain(result_urls[1], error_string)
33 callback() 33 callback()
@@ -50,7 +50,7 @@ describe('Test basic friends', function () {
50 utils.getFriendsList(url, function (err, res) { 50 utils.getFriendsList(url, function (err, res) {
51 if (err) throw err 51 if (err) throw err
52 52
53 var result = res.body 53 const result = res.body
54 expect(result).to.be.an('array') 54 expect(result).to.be.an('array')
55 expect(result.length).to.equal(0) 55 expect(result.length).to.equal(0)
56 callback() 56 callback()
@@ -61,7 +61,7 @@ describe('Test basic friends', function () {
61 it('Should make friends', function (done) { 61 it('Should make friends', function (done) {
62 this.timeout(10000) 62 this.timeout(10000)
63 63
64 var path = '/api/v1/pods/makefriends' 64 const path = '/api/v1/pods/makefriends'
65 65
66 async.series([ 66 async.series([
67 // The second pod make friend with the third 67 // The second pod make friend with the third
@@ -81,7 +81,7 @@ describe('Test basic friends', function () {
81 utils.getFriendsList(urls[1], function (err, res) { 81 utils.getFriendsList(urls[1], function (err, res) {
82 if (err) throw err 82 if (err) throw err
83 83
84 var result = res.body 84 const result = res.body
85 expect(result).to.be.an('array') 85 expect(result).to.be.an('array')
86 expect(result.length).to.equal(1) 86 expect(result.length).to.equal(1)
87 expect(result[0].url).to.be.equal(urls[2]) 87 expect(result[0].url).to.be.equal(urls[2])
@@ -94,7 +94,7 @@ describe('Test basic friends', function () {
94 utils.getFriendsList(urls[2], function (err, res) { 94 utils.getFriendsList(urls[2], function (err, res) {
95 if (err) throw err 95 if (err) throw err
96 96
97 var result = res.body 97 const result = res.body
98 expect(result).to.be.an('array') 98 expect(result).to.be.an('array')
99 expect(result.length).to.equal(1) 99 expect(result.length).to.equal(1)
100 expect(result[0].url).to.be.equal(urls[1]) 100 expect(result[0].url).to.be.equal(urls[1])
@@ -139,7 +139,7 @@ describe('Test basic friends', function () {
139 utils.getFriendsList(urls[1], function (err, res) { 139 utils.getFriendsList(urls[1], function (err, res) {
140 if (err) throw err 140 if (err) throw err
141 141
142 var result = res.body 142 const result = res.body
143 expect(result).to.be.an('array') 143 expect(result).to.be.an('array')
144 expect(result.length).to.equal(0) 144 expect(result.length).to.equal(0)
145 145
@@ -152,7 +152,7 @@ describe('Test basic friends', function () {
152 utils.getFriendsList(url, function (err, res) { 152 utils.getFriendsList(url, function (err, res) {
153 if (err) throw err 153 if (err) throw err
154 154
155 var result = res.body 155 const result = res.body
156 expect(result).to.be.an('array') 156 expect(result).to.be.an('array')
157 expect(result.length).to.equal(1) 157 expect(result.length).to.equal(1)
158 expect(result[0].url).not.to.be.equal(urls[1]) 158 expect(result[0].url).not.to.be.equal(urls[1])
diff --git a/server/tests/api/multiplePods.js b/server/tests/api/multiplePods.js
index 9fdd0f308..e8b182622 100644
--- a/server/tests/api/multiplePods.js
+++ b/server/tests/api/multiplePods.js
@@ -1,18 +1,18 @@
1'use strict' 1'use strict'
2 2
3var async = require('async') 3const async = require('async')
4var chai = require('chai') 4const chai = require('chai')
5var expect = chai.expect 5const expect = chai.expect
6var pathUtils = require('path') 6const pathUtils = require('path')
7 7
8var utils = require('./utils') 8const utils = require('./utils')
9var webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) 9const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
10webtorrent.silent = true 10webtorrent.silent = true
11 11
12describe('Test multiple pods', function () { 12describe('Test multiple pods', function () {
13 var apps = [] 13 let apps = []
14 var urls = [] 14 let urls = []
15 var to_remove = [] 15 const to_remove = []
16 16
17 before(function (done) { 17 before(function (done) {
18 this.timeout(30000) 18 this.timeout(30000)
@@ -73,15 +73,15 @@ describe('Test multiple pods', function () {
73 if (err) throw err 73 if (err) throw err
74 74
75 async.each(urls, function (url, callback) { 75 async.each(urls, function (url, callback) {
76 var base_magnet = null 76 let base_magnet = null
77 77
78 utils.getVideosList(url, function (err, res) { 78 utils.getVideosList(url, function (err, res) {
79 if (err) throw err 79 if (err) throw err
80 80
81 var videos = res.body 81 const videos = res.body
82 expect(videos).to.be.an('array') 82 expect(videos).to.be.an('array')
83 expect(videos.length).to.equal(1) 83 expect(videos.length).to.equal(1)
84 var video = videos[0] 84 const video = videos[0]
85 expect(video.name).to.equal('my super name for pod 1') 85 expect(video.name).to.equal('my super name for pod 1')
86 expect(video.description).to.equal('my super description for pod 1') 86 expect(video.description).to.equal('my super description for pod 1')
87 expect(video.podUrl).to.equal('http://localhost:9001') 87 expect(video.podUrl).to.equal('http://localhost:9001')
@@ -116,15 +116,15 @@ describe('Test multiple pods', function () {
116 if (err) throw err 116 if (err) throw err
117 117
118 async.each(urls, function (url, callback) { 118 async.each(urls, function (url, callback) {
119 var base_magnet = null 119 let base_magnet = null
120 120
121 utils.getVideosList(url, function (err, res) { 121 utils.getVideosList(url, function (err, res) {
122 if (err) throw err 122 if (err) throw err
123 123
124 var videos = res.body 124 const videos = res.body
125 expect(videos).to.be.an('array') 125 expect(videos).to.be.an('array')
126 expect(videos.length).to.equal(2) 126 expect(videos.length).to.equal(2)
127 var video = videos[1] 127 const video = videos[1]
128 expect(video.name).to.equal('my super name for pod 2') 128 expect(video.name).to.equal('my super name for pod 2')
129 expect(video.description).to.equal('my super description for pod 2') 129 expect(video.description).to.equal('my super description for pod 2')
130 expect(video.podUrl).to.equal('http://localhost:9002') 130 expect(video.podUrl).to.equal('http://localhost:9002')
@@ -160,16 +160,16 @@ describe('Test multiple pods', function () {
160 function (err) { 160 function (err) {
161 if (err) throw err 161 if (err) throw err
162 162
163 var base_magnet = null 163 let base_magnet = null
164 // All pods should have this video 164 // All pods should have this video
165 async.each(urls, function (url, callback) { 165 async.each(urls, function (url, callback) {
166 utils.getVideosList(url, function (err, res) { 166 utils.getVideosList(url, function (err, res) {
167 if (err) throw err 167 if (err) throw err
168 168
169 var videos = res.body 169 const videos = res.body
170 expect(videos).to.be.an('array') 170 expect(videos).to.be.an('array')
171 expect(videos.length).to.equal(4) 171 expect(videos.length).to.equal(4)
172 var video = videos[2] 172 let video = videos[2]
173 expect(video.name).to.equal('my super name for pod 3') 173 expect(video.name).to.equal('my super name for pod 3')
174 expect(video.description).to.equal('my super description for pod 3') 174 expect(video.description).to.equal('my super description for pod 3')
175 expect(video.podUrl).to.equal('http://localhost:9003') 175 expect(video.podUrl).to.equal('http://localhost:9003')
@@ -204,7 +204,7 @@ describe('Test multiple pods', function () {
204 utils.getVideosList(urls[2], function (err, res) { 204 utils.getVideosList(urls[2], function (err, res) {
205 if (err) throw err 205 if (err) throw err
206 206
207 var video = res.body[0] 207 const video = res.body[0]
208 to_remove.push(res.body[2]._id) 208 to_remove.push(res.body[2]._id)
209 to_remove.push(res.body[3]._id) 209 to_remove.push(res.body[3]._id)
210 210
@@ -225,7 +225,7 @@ describe('Test multiple pods', function () {
225 utils.getVideosList(urls[0], function (err, res) { 225 utils.getVideosList(urls[0], function (err, res) {
226 if (err) throw err 226 if (err) throw err
227 227
228 var video = res.body[1] 228 const video = res.body[1]
229 229
230 webtorrent.add(video.magnetUri, function (torrent) { 230 webtorrent.add(video.magnetUri, function (torrent) {
231 expect(torrent.files).to.exist 231 expect(torrent.files).to.exist
@@ -244,7 +244,7 @@ describe('Test multiple pods', function () {
244 utils.getVideosList(urls[1], function (err, res) { 244 utils.getVideosList(urls[1], function (err, res) {
245 if (err) throw err 245 if (err) throw err
246 246
247 var video = res.body[2] 247 const video = res.body[2]
248 248
249 webtorrent.add(video.magnetUri, function (torrent) { 249 webtorrent.add(video.magnetUri, function (torrent) {
250 expect(torrent.files).to.exist 250 expect(torrent.files).to.exist
@@ -263,7 +263,7 @@ describe('Test multiple pods', function () {
263 utils.getVideosList(urls[0], function (err, res) { 263 utils.getVideosList(urls[0], function (err, res) {
264 if (err) throw err 264 if (err) throw err
265 265
266 var video = res.body[3] 266 const video = res.body[3]
267 267
268 webtorrent.add(video.magnetUri, function (torrent) { 268 webtorrent.add(video.magnetUri, function (torrent) {
269 expect(torrent.files).to.exist 269 expect(torrent.files).to.exist
@@ -297,7 +297,7 @@ describe('Test multiple pods', function () {
297 utils.getVideosList(url, function (err, res) { 297 utils.getVideosList(url, function (err, res) {
298 if (err) throw err 298 if (err) throw err
299 299
300 var videos = res.body 300 const videos = res.body
301 expect(videos).to.be.an('array') 301 expect(videos).to.be.an('array')
302 expect(videos.length).to.equal(2) 302 expect(videos.length).to.equal(2)
303 expect(videos[0]._id).not.to.equal(videos[1]._id) 303 expect(videos[0]._id).not.to.equal(videos[1]._id)
diff --git a/server/tests/api/singlePod.js b/server/tests/api/singlePod.js
index d572aacf6..14f893f13 100644
--- a/server/tests/api/singlePod.js
+++ b/server/tests/api/singlePod.js
@@ -1,20 +1,20 @@
1'use strict' 1'use strict'
2 2
3var async = require('async') 3const async = require('async')
4var chai = require('chai') 4const chai = require('chai')
5var expect = chai.expect 5const expect = chai.expect
6var fs = require('fs') 6const fs = require('fs')
7var pathUtils = require('path') 7const pathUtils = require('path')
8 8
9var webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) 9const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
10webtorrent.silent = true 10webtorrent.silent = true
11 11
12var utils = require('./utils') 12const utils = require('./utils')
13 13
14describe('Test a single pod', function () { 14describe('Test a single pod', function () {
15 var app = null 15 let app = null
16 var url = '' 16 let url = ''
17 var video_id = -1 17 let video_id = -1
18 18
19 before(function (done) { 19 before(function (done) {
20 this.timeout(20000) 20 this.timeout(20000)
@@ -62,7 +62,7 @@ describe('Test a single pod', function () {
62 expect(res.body).to.be.an('array') 62 expect(res.body).to.be.an('array')
63 expect(res.body.length).to.equal(1) 63 expect(res.body.length).to.equal(1)
64 64
65 var video = res.body[0] 65 const video = res.body[0]
66 expect(video.name).to.equal('my super name') 66 expect(video.name).to.equal('my super name')
67 expect(video.description).to.equal('my super description') 67 expect(video.description).to.equal('my super description')
68 expect(video.podUrl).to.equal('http://localhost:9001') 68 expect(video.podUrl).to.equal('http://localhost:9001')
@@ -87,7 +87,7 @@ describe('Test a single pod', function () {
87 expect(res.body).to.be.an('array') 87 expect(res.body).to.be.an('array')
88 expect(res.body.length).to.equal(1) 88 expect(res.body.length).to.equal(1)
89 89
90 var video = res.body[0] 90 const video = res.body[0]
91 expect(video.name).to.equal('my super name') 91 expect(video.name).to.equal('my super name')
92 expect(video.description).to.equal('my super description') 92 expect(video.description).to.equal('my super description')
93 expect(video.podUrl).to.equal('http://localhost:9001') 93 expect(video.podUrl).to.equal('http://localhost:9001')
diff --git a/server/tests/api/utils.js b/server/tests/api/utils.js
index 60c3c8d4e..05142085f 100644
--- a/server/tests/api/utils.js
+++ b/server/tests/api/utils.js
@@ -1,12 +1,12 @@
1'use strict' 1'use strict'
2 2
3var child_process = require('child_process') 3const child_process = require('child_process')
4var exec = child_process.exec 4const exec = child_process.exec
5var fork = child_process.fork 5const fork = child_process.fork
6var pathUtils = require('path') 6const pathUtils = require('path')
7var request = require('supertest') 7const request = require('supertest')
8 8
9var testUtils = { 9const testUtils = {
10 flushTests: flushTests, 10 flushTests: flushTests,
11 getFriendsList: getFriendsList, 11 getFriendsList: getFriendsList,
12 getVideosList: getVideosList, 12 getVideosList: getVideosList,
@@ -26,7 +26,7 @@ function flushTests (callback) {
26} 26}
27 27
28function getFriendsList (url, end) { 28function getFriendsList (url, end) {
29 var path = '/api/v1/pods/' 29 const path = '/api/v1/pods/'
30 30
31 request(url) 31 request(url)
32 .get(path) 32 .get(path)
@@ -37,7 +37,7 @@ function getFriendsList (url, end) {
37} 37}
38 38
39function getVideosList (url, end) { 39function getVideosList (url, end) {
40 var path = '/api/v1/videos' 40 const path = '/api/v1/videos'
41 41
42 request(url) 42 request(url)
43 .get(path) 43 .get(path)
@@ -53,7 +53,7 @@ function makeFriends (url, expected_status, callback) {
53 expected_status = 204 53 expected_status = 204
54 } 54 }
55 55
56 var path = '/api/v1/pods/makefriends' 56 const path = '/api/v1/pods/makefriends'
57 57
58 // The first pod make friend with the third 58 // The first pod make friend with the third
59 request(url) 59 request(url)
@@ -69,7 +69,7 @@ function makeFriends (url, expected_status, callback) {
69} 69}
70 70
71function quitFriends (url, callback) { 71function quitFriends (url, callback) {
72 var path = '/api/v1/pods/quitfriends' 72 const path = '/api/v1/pods/quitfriends'
73 73
74 // The first pod make friend with the third 74 // The first pod make friend with the third
75 request(url) 75 request(url)
@@ -85,7 +85,7 @@ function quitFriends (url, callback) {
85} 85}
86 86
87function removeVideo (url, id, end) { 87function removeVideo (url, id, end) {
88 var path = '/api/v1/videos' 88 const path = '/api/v1/videos'
89 89
90 request(url) 90 request(url)
91 .delete(path + '/' + id) 91 .delete(path + '/' + id)
@@ -95,9 +95,9 @@ function removeVideo (url, id, end) {
95} 95}
96 96
97function flushAndRunMultipleServers (total_servers, serversRun) { 97function flushAndRunMultipleServers (total_servers, serversRun) {
98 var apps = [] 98 let apps = []
99 var urls = [] 99 let urls = []
100 var i = 0 100 let i = 0
101 101
102 function anotherServerDone (number, app, url) { 102 function anotherServerDone (number, app, url) {
103 apps[number - 1] = app 103 apps[number - 1] = app
@@ -109,41 +109,39 @@ function flushAndRunMultipleServers (total_servers, serversRun) {
109 } 109 }
110 110
111 flushTests(function () { 111 flushTests(function () {
112 for (var j = 1; j <= total_servers; j++) { 112 for (let j = 1; j <= total_servers; j++) {
113 (function (k) { // TODO: ES6 with let 113 // For the virtual buffer
114 // For the virtual buffer 114 setTimeout(function () {
115 setTimeout(function () { 115 runServer(j, function (app, url) {
116 runServer(k, function (app, url) { 116 anotherServerDone(j, app, url)
117 anotherServerDone(k, app, url) 117 })
118 }) 118 }, 1000 * j)
119 }, 1000 * k)
120 })(j)
121 } 119 }
122 }) 120 })
123} 121}
124 122
125function runServer (number, callback) { 123function runServer (number, callback) {
126 var port = 9000 + number 124 const port = 9000 + number
127 var server_run_string = { 125 const server_run_string = {
128 'Connected to mongodb': false, 126 'Connected to mongodb': false,
129 'Server listening on port': false 127 'Server listening on port': false
130 } 128 }
131 129
132 // Share the environment 130 // Share the environment
133 var env = Object.create(process.env) 131 const env = Object.create(process.env)
134 env.NODE_ENV = 'test' 132 env.NODE_ENV = 'test'
135 env.NODE_APP_INSTANCE = number 133 env.NODE_APP_INSTANCE = number
136 var options = { 134 const options = {
137 silent: true, 135 silent: true,
138 env: env, 136 env: env,
139 detached: true 137 detached: true
140 } 138 }
141 139
142 var app = fork(pathUtils.join(__dirname, '../../../server.js'), [], options) 140 const app = fork(pathUtils.join(__dirname, '../../../server.js'), [], options)
143 app.stdout.on('data', function onStdout (data) { 141 app.stdout.on('data', function onStdout (data) {
144 var dont_continue = false 142 let dont_continue = false
145 // Check if all required sentences are here 143 // Check if all required sentences are here
146 for (var key of Object.keys(server_run_string)) { 144 for (const key of Object.keys(server_run_string)) {
147 if (data.toString().indexOf(key) !== -1) server_run_string[key] = true 145 if (data.toString().indexOf(key) !== -1) server_run_string[key] = true
148 if (server_run_string[key] === false) dont_continue = true 146 if (server_run_string[key] === false) dont_continue = true
149 } 147 }
@@ -157,7 +155,7 @@ function runServer (number, callback) {
157} 155}
158 156
159function searchVideo (url, search, end) { 157function searchVideo (url, search, end) {
160 var path = '/api/v1/videos' 158 const path = '/api/v1/videos'
161 159
162 request(url) 160 request(url)
163 .get(path + '/search/' + search) 161 .get(path + '/search/' + search)
@@ -168,7 +166,7 @@ function searchVideo (url, search, end) {
168} 166}
169 167
170function uploadVideo (url, name, description, fixture, end) { 168function uploadVideo (url, name, description, fixture, end) {
171 var path = '/api/v1/videos' 169 const path = '/api/v1/videos'
172 170
173 request(url) 171 request(url)
174 .post(path) 172 .post(path)
diff --git a/server/tests/index.js b/server/tests/index.js
index ccebbfe51..cb177b87c 100644
--- a/server/tests/index.js
+++ b/server/tests/index.js
@@ -1,6 +1,4 @@
1;(function () { 1'use strict'
2 'use strict'
3 2
4 // Order of the tests we want to execute 3// Order of the tests we want to execute
5 require('./api/') 4require('./api/')
6})()