aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-05-11 21:19:34 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-05-13 14:23:11 +0200
commitbc503c2a62dcf9aed6b8d90b68f0f27a7755ac01 (patch)
treea1fe1ad88afd29ee4d7cb05c480649d5a9c6f9a0
parent881a5e68b64e4acd43408852bbdc914643d8fac6 (diff)
downloadPeerTube-bc503c2a62dcf9aed6b8d90b68f0f27a7755ac01.tar.gz
PeerTube-bc503c2a62dcf9aed6b8d90b68f0f27a7755ac01.tar.zst
PeerTube-bc503c2a62dcf9aed6b8d90b68f0f27a7755ac01.zip
Update to standard 7. Goodbye snake_case, I used to love you
-rw-r--r--package.json2
-rw-r--r--server.js8
-rw-r--r--server/controllers/api/v1/pods.js12
-rw-r--r--server/controllers/api/v1/remoteVideos.js8
-rw-r--r--server/controllers/api/v1/users.js12
-rw-r--r--server/controllers/api/v1/videos.js84
-rw-r--r--server/helpers/peertubeCrypto.js20
-rw-r--r--server/helpers/requests.js30
-rw-r--r--server/helpers/utils.js4
-rw-r--r--server/lib/friends.js72
-rw-r--r--server/lib/requestsScheduler.js66
-rw-r--r--server/lib/videos.js54
-rw-r--r--server/lib/webtorrent.js34
-rw-r--r--server/lib/webtorrentProcess.js14
-rw-r--r--server/middlewares/reqValidators/pods.js4
-rw-r--r--server/middlewares/reqValidators/utils.js6
-rw-r--r--server/middlewares/secure.js4
-rw-r--r--server/models/pods.js4
-rw-r--r--server/models/users.js20
-rw-r--r--server/models/videos.js8
-rw-r--r--server/tests/api/checkParams.js12
-rw-r--r--server/tests/api/friendsAdvanced.js34
-rw-r--r--server/tests/api/friendsBasic.js20
-rw-r--r--server/tests/api/multiplePods.js50
-rw-r--r--server/tests/api/singlePod.js34
-rw-r--r--server/tests/api/users.js20
-rw-r--r--server/tests/api/utils.js64
27 files changed, 349 insertions, 351 deletions
diff --git a/package.json b/package.json
index 746a0d968..3b9e84175 100644
--- a/package.json
+++ b/package.json
@@ -77,7 +77,7 @@
77 "node-livereload": "^0.6.0", 77 "node-livereload": "^0.6.0",
78 "node-sass": "^3.4.2", 78 "node-sass": "^3.4.2",
79 "scripty": "^1.5.0", 79 "scripty": "^1.5.0",
80 "standard": "^6.0.1", 80 "standard": "^7.0.1",
81 "supertest": "^1.1.0" 81 "supertest": "^1.1.0"
82 }, 82 },
83 "standard": { 83 "standard": {
diff --git a/server.js b/server.js
index ef26ea773..989c60477 100644
--- a/server.js
+++ b/server.js
@@ -65,8 +65,8 @@ app.use(require('connect-livereload')({
65require('segfault-handler').registerHandler() 65require('segfault-handler').registerHandler()
66 66
67// API routes 67// API routes
68const api_route = '/api/' + constants.API_VERSION 68const apiRoute = '/api/' + constants.API_VERSION
69app.use(api_route, routes.api) 69app.use(apiRoute, routes.api)
70 70
71// Static files 71// Static files
72app.use('/app', express.static(path.join(__dirname, '/client'), { maxAge: 0 })) 72app.use('/app', express.static(path.join(__dirname, '/client'), { maxAge: 0 }))
@@ -76,8 +76,8 @@ app.use('/app/*', function (req, res, next) {
76}) 76})
77 77
78// Thumbnails path for express 78// Thumbnails path for express
79const thumbnails_physical_path = path.join(__dirname, config.get('storage.thumbnails')) 79const thumbnailsPhysicalPath = path.join(__dirname, config.get('storage.thumbnails'))
80app.use(constants.THUMBNAILS_STATIC_PATH, express.static(thumbnails_physical_path, { maxAge: 0 })) 80app.use(constants.THUMBNAILS_STATIC_PATH, express.static(thumbnailsPhysicalPath, { maxAge: 0 }))
81 81
82// Client application 82// Client application
83app.use('/*', function (req, res, next) { 83app.use('/*', function (req, res, next) {
diff --git a/server/controllers/api/v1/pods.js b/server/controllers/api/v1/pods.js
index d08b7860d..b16fea4f6 100644
--- a/server/controllers/api/v1/pods.js
+++ b/server/controllers/api/v1/pods.js
@@ -44,23 +44,23 @@ function addPods (req, res, next) {
44 return next(err) 44 return next(err)
45 } 45 }
46 46
47 Videos.listOwned(function (err, videos_list) { 47 Videos.listOwned(function (err, videosList) {
48 if (err) { 48 if (err) {
49 logger.error('Cannot get the list of owned videos.') 49 logger.error('Cannot get the list of owned videos.')
50 return next(err) 50 return next(err)
51 } 51 }
52 52
53 res.json({ cert: cert, videos: videos_list }) 53 res.json({ cert: cert, videos: videosList })
54 }) 54 })
55 }) 55 })
56 }) 56 })
57} 57}
58 58
59function listPods (req, res, next) { 59function listPods (req, res, next) {
60 Pods.list(function (err, pods_list) { 60 Pods.list(function (err, podsList) {
61 if (err) return next(err) 61 if (err) return next(err)
62 62
63 res.json(pods_list) 63 res.json(podsList)
64 }) 64 })
65} 65}
66 66
@@ -77,13 +77,13 @@ function removePods (req, res, next) {
77 Pods.remove(url, function (err) { 77 Pods.remove(url, function (err) {
78 if (err) return next(err) 78 if (err) return next(err)
79 79
80 Videos.listFromUrl(url, function (err, videos_list) { 80 Videos.listFromUrl(url, function (err, videosList) {
81 if (err) { 81 if (err) {
82 logger.error('Cannot list videos from url.', { error: err }) 82 logger.error('Cannot list videos from url.', { error: err })
83 next(err) 83 next(err)
84 } 84 }
85 85
86 videos.removeRemoteVideos(videos_list, function (err) { 86 videos.removeRemoteVideos(videosList, function (err) {
87 if (err) { 87 if (err) {
88 logger.error('Cannot remove remote videos.', { error: err }) 88 logger.error('Cannot remove remote videos.', { error: err })
89 next(err) 89 next(err)
diff --git a/server/controllers/api/v1/remoteVideos.js b/server/controllers/api/v1/remoteVideos.js
index 8ff212b7f..7da9f0105 100644
--- a/server/controllers/api/v1/remoteVideos.js
+++ b/server/controllers/api/v1/remoteVideos.js
@@ -36,8 +36,8 @@ module.exports = router
36// --------------------------------------------------------------------------- 36// ---------------------------------------------------------------------------
37 37
38function addRemoteVideos (req, res, next) { 38function addRemoteVideos (req, res, next) {
39 const videos_to_create = req.body.data 39 const videosToCreate = req.body.data
40 videos.createRemoteVideos(videos_to_create, function (err, remote_videos) { 40 videos.createRemoteVideos(videosToCreate, function (err, remoteVideos) {
41 if (err) { 41 if (err) {
42 logger.error('Cannot create remote videos.', { error: err }) 42 logger.error('Cannot create remote videos.', { error: err })
43 return next(err) 43 return next(err)
@@ -51,13 +51,13 @@ function removeRemoteVideo (req, res, next) {
51 const fromUrl = req.body.signature.url 51 const fromUrl = req.body.signature.url
52 const magnetUris = map(req.body.data, 'magnetUri') 52 const magnetUris = map(req.body.data, 'magnetUri')
53 53
54 Videos.listFromUrlAndMagnets(fromUrl, magnetUris, function (err, videos_list) { 54 Videos.listFromUrlAndMagnets(fromUrl, magnetUris, function (err, videosList) {
55 if (err) { 55 if (err) {
56 logger.error('Cannot list videos from url and magnets.', { error: err }) 56 logger.error('Cannot list videos from url and magnets.', { error: err })
57 return next(err) 57 return next(err)
58 } 58 }
59 59
60 videos.removeRemoteVideos(videos_list, function (err) { 60 videos.removeRemoteVideos(videosList, function (err) {
61 if (err) { 61 if (err) {
62 logger.error('Cannot remove remote videos.', { error: err }) 62 logger.error('Cannot remove remote videos.', { error: err })
63 return next(err) 63 return next(err)
diff --git a/server/controllers/api/v1/users.js b/server/controllers/api/v1/users.js
index 1125b9faa..0584d5cdf 100644
--- a/server/controllers/api/v1/users.js
+++ b/server/controllers/api/v1/users.js
@@ -20,14 +20,14 @@ module.exports = router
20// --------------------------------------------------------------------------- 20// ---------------------------------------------------------------------------
21 21
22function getAngularClient (req, res, next) { 22function getAngularClient (req, res, next) {
23 const server_host = config.get('webserver.host') 23 const serverHost = config.get('webserver.host')
24 const server_port = config.get('webserver.port') 24 const serverPort = config.get('webserver.port')
25 let header_host_should_be = server_host 25 let headerHostShouldBe = serverHost
26 if (server_port !== 80 && server_port !== 443) { 26 if (serverPort !== 80 && serverPort !== 443) {
27 header_host_should_be += ':' + server_port 27 headerHostShouldBe += ':' + serverPort
28 } 28 }
29 29
30 if (req.get('host') !== header_host_should_be) return res.type('json').status(403).end() 30 if (req.get('host') !== headerHostShouldBe) return res.type('json').status(403).end()
31 31
32 Users.getFirstClient(function (err, client) { 32 Users.getFirstClient(function (err, client) {
33 if (err) return next(err) 33 if (err) return next(err)
diff --git a/server/controllers/api/v1/videos.js b/server/controllers/api/v1/videos.js
index c6ea439f9..c86a96a25 100644
--- a/server/controllers/api/v1/videos.js
+++ b/server/controllers/api/v1/videos.js
@@ -32,8 +32,8 @@ const storage = multer.diskStorage({
32 if (file.mimetype === 'video/webm') extension = 'webm' 32 if (file.mimetype === 'video/webm') extension = 'webm'
33 else if (file.mimetype === 'video/mp4') extension = 'mp4' 33 else if (file.mimetype === 'video/mp4') extension = 'mp4'
34 else if (file.mimetype === 'video/ogg') extension = 'ogv' 34 else if (file.mimetype === 'video/ogg') extension = 'ogv'
35 utils.generateRandomString(16, function (err, random_string) { 35 utils.generateRandomString(16, function (err, randomString) {
36 const fieldname = err ? undefined : random_string 36 const fieldname = err ? undefined : randomString
37 cb(null, fieldname + '.' + extension) 37 cb(null, fieldname + '.' + extension)
38 }) 38 })
39 } 39 }
@@ -55,47 +55,47 @@ module.exports = router
55// --------------------------------------------------------------------------- 55// ---------------------------------------------------------------------------
56 56
57function addVideo (req, res, next) { 57function addVideo (req, res, next) {
58 const video_file = req.files.videofile[0] 58 const videoFile = req.files.videofile[0]
59 const video_infos = req.body 59 const videoInfos = req.body
60 60
61 videos.seed(video_file.path, function (err, torrent) { 61 videos.seed(videoFile.path, function (err, torrent) {
62 if (err) { 62 if (err) {
63 logger.error('Cannot seed this video.') 63 logger.error('Cannot seed this video.')
64 return next(err) 64 return next(err)
65 } 65 }
66 66
67 videos.getVideoDuration(video_file.path, function (err, duration) { 67 videos.getVideoDuration(videoFile.path, function (err, duration) {
68 if (err) { 68 if (err) {
69 // TODO: unseed the video 69 // TODO: unseed the video
70 logger.error('Cannot retrieve metadata of the file.') 70 logger.error('Cannot retrieve metadata of the file.')
71 return next(err) 71 return next(err)
72 } 72 }
73 73
74 videos.getVideoThumbnail(video_file.path, function (err, thumbnail_name) { 74 videos.getVideoThumbnail(videoFile.path, function (err, thumbnailName) {
75 if (err) { 75 if (err) {
76 // TODO: unseed the video 76 // TODO: unseed the video
77 logger.error('Cannot make a thumbnail of the video file.') 77 logger.error('Cannot make a thumbnail of the video file.')
78 return next(err) 78 return next(err)
79 } 79 }
80 80
81 const video_data = { 81 const videoData = {
82 name: video_infos.name, 82 name: videoInfos.name,
83 namePath: video_file.filename, 83 namePath: videoFile.filename,
84 description: video_infos.description, 84 description: videoInfos.description,
85 magnetUri: torrent.magnetURI, 85 magnetUri: torrent.magnetURI,
86 author: res.locals.oauth.token.user.username, 86 author: res.locals.oauth.token.user.username,
87 duration: duration, 87 duration: duration,
88 thumbnail: thumbnail_name 88 thumbnail: thumbnailName
89 } 89 }
90 90
91 Videos.add(video_data, function (err) { 91 Videos.add(videoData, function (err) {
92 if (err) { 92 if (err) {
93 // TODO unseed the video 93 // TODO unseed the video
94 logger.error('Cannot insert this video in the database.') 94 logger.error('Cannot insert this video in the database.')
95 return next(err) 95 return next(err)
96 } 96 }
97 97
98 fs.readFile(thumbnailsDir + thumbnail_name, function (err, data) { 98 fs.readFile(thumbnailsDir + thumbnailName, function (err, data) {
99 if (err) { 99 if (err) {
100 // TODO: remove video? 100 // TODO: remove video?
101 logger.error('Cannot read the thumbnail of the video') 101 logger.error('Cannot read the thumbnail of the video')
@@ -103,9 +103,9 @@ function addVideo (req, res, next) {
103 } 103 }
104 104
105 // Set the image in base64 105 // Set the image in base64
106 video_data.thumbnail_base64 = new Buffer(data).toString('base64') 106 videoData.thumbnailBase64 = new Buffer(data).toString('base64')
107 // Now we'll add the video's meta data to our friends 107 // Now we'll add the video's meta data to our friends
108 friends.addVideoToFriends(video_data) 108 friends.addVideoToFriends(videoData)
109 109
110 // TODO : include Location of the new video -> 201 110 // TODO : include Location of the new video -> 201
111 res.type('json').status(204).end() 111 res.type('json').status(204).end()
@@ -117,29 +117,29 @@ function addVideo (req, res, next) {
117} 117}
118 118
119function getVideos (req, res, next) { 119function getVideos (req, res, next) {
120 Videos.get(req.params.id, function (err, video_obj) { 120 Videos.get(req.params.id, function (err, videoObj) {
121 if (err) return next(err) 121 if (err) return next(err)
122 122
123 const state = videos.getVideoState(video_obj) 123 const state = videos.getVideoState(videoObj)
124 if (state.exist === false) { 124 if (state.exist === false) {
125 return res.type('json').status(204).end() 125 return res.type('json').status(204).end()
126 } 126 }
127 127
128 res.json(getFormatedVideo(video_obj)) 128 res.json(getFormatedVideo(videoObj))
129 }) 129 })
130} 130}
131 131
132function listVideos (req, res, next) { 132function listVideos (req, res, next) {
133 Videos.list(function (err, videos_list) { 133 Videos.list(function (err, videosList) {
134 if (err) return next(err) 134 if (err) return next(err)
135 135
136 res.json(getFormatedVideos(videos_list)) 136 res.json(getFormatedVideos(videosList))
137 }) 137 })
138} 138}
139 139
140function removeVideo (req, res, next) { 140function removeVideo (req, res, next) {
141 const video_id = req.params.id 141 const videoId = req.params.id
142 Videos.get(video_id, function (err, video) { 142 Videos.get(videoId, function (err, video) {
143 if (err) return next(err) 143 if (err) return next(err)
144 144
145 removeTorrent(video.magnetUri, function () { 145 removeTorrent(video.magnetUri, function () {
@@ -163,39 +163,39 @@ function removeVideo (req, res, next) {
163} 163}
164 164
165function searchVideos (req, res, next) { 165function searchVideos (req, res, next) {
166 Videos.search(req.params.name, function (err, videos_list) { 166 Videos.search(req.params.name, function (err, videosList) {
167 if (err) return next(err) 167 if (err) return next(err)
168 168
169 res.json(getFormatedVideos(videos_list)) 169 res.json(getFormatedVideos(videosList))
170 }) 170 })
171} 171}
172 172
173// --------------------------------------------------------------------------- 173// ---------------------------------------------------------------------------
174 174
175function getFormatedVideo (video_obj) { 175function getFormatedVideo (videoObj) {
176 const formated_video = { 176 const formatedVideo = {
177 id: video_obj._id, 177 id: videoObj._id,
178 name: video_obj.name, 178 name: videoObj.name,
179 description: video_obj.description, 179 description: videoObj.description,
180 podUrl: video_obj.podUrl, 180 podUrl: videoObj.podUrl,
181 isLocal: videos.getVideoState(video_obj).owned, 181 isLocal: videos.getVideoState(videoObj).owned,
182 magnetUri: video_obj.magnetUri, 182 magnetUri: videoObj.magnetUri,
183 author: video_obj.author, 183 author: videoObj.author,
184 duration: video_obj.duration, 184 duration: videoObj.duration,
185 thumbnailPath: constants.THUMBNAILS_STATIC_PATH + '/' + video_obj.thumbnail 185 thumbnailPath: constants.THUMBNAILS_STATIC_PATH + '/' + videoObj.thumbnail
186 } 186 }
187 187
188 return formated_video 188 return formatedVideo
189} 189}
190 190
191function getFormatedVideos (videos_obj) { 191function getFormatedVideos (videosObj) {
192 const formated_videos = [] 192 const formatedVideos = []
193 193
194 videos_obj.forEach(function (video_obj) { 194 videosObj.forEach(function (videoObj) {
195 formated_videos.push(getFormatedVideo(video_obj)) 195 formatedVideos.push(getFormatedVideo(videoObj))
196 }) 196 })
197 197
198 return formated_videos 198 return formatedVideos
199} 199}
200 200
201// Maybe the torrent is not seeded, but we catch the error to don't stop the removing process 201// Maybe the torrent is not seeded, but we catch the error to don't stop the removing process
diff --git a/server/helpers/peertubeCrypto.js b/server/helpers/peertubeCrypto.js
index 3826ebaf6..46dff8d03 100644
--- a/server/helpers/peertubeCrypto.js
+++ b/server/helpers/peertubeCrypto.js
@@ -21,10 +21,10 @@ const peertubeCrypto = {
21 sign: sign 21 sign: sign
22} 22}
23 23
24function checkSignature (public_key, raw_data, hex_signature) { 24function checkSignature (publicKey, rawData, hexSignature) {
25 const crt = ursa.createPublicKey(public_key) 25 const crt = ursa.createPublicKey(publicKey)
26 const is_valid = crt.hashAndVerify('sha256', new Buffer(raw_data).toString('hex'), hex_signature, 'hex') 26 const isValid = crt.hashAndVerify('sha256', new Buffer(rawData).toString('hex'), hexSignature, 'hex')
27 return is_valid 27 return isValid
28} 28}
29 29
30function createCertsIfNotExist (callback) { 30function createCertsIfNotExist (callback) {
@@ -43,16 +43,16 @@ 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 const my_private_key = ursa.createPrivateKey(file) 46 const myPrivateKey = ursa.createPrivateKey(file)
47 const decrypted_key = my_private_key.decrypt(key, 'hex', 'utf8') 47 const decryptedKey = myPrivateKey.decrypt(key, 'hex', 'utf8')
48 const decrypted_data = symetricDecrypt(data, decrypted_key) 48 const decryptedData = symetricDecrypt(data, decryptedKey)
49 49
50 return callback(null, decrypted_data) 50 return callback(null, decryptedData)
51 }) 51 })
52} 52}
53 53
54function encrypt (public_key, data, callback) { 54function encrypt (publicKey, data, callback) {
55 const crt = ursa.createPublicKey(public_key) 55 const crt = ursa.createPublicKey(publicKey)
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)
diff --git a/server/helpers/requests.js b/server/helpers/requests.js
index 17b1127c0..1e1bb4111 100644
--- a/server/helpers/requests.js
+++ b/server/helpers/requests.js
@@ -17,7 +17,7 @@ const requests = {
17 makeMultipleRetryRequest: makeMultipleRetryRequest 17 makeMultipleRetryRequest: makeMultipleRetryRequest
18} 18}
19 19
20function makeMultipleRetryRequest (all_data, pods, callbackEach, callback) { 20function makeMultipleRetryRequest (allData, pods, callbackEach, callback) {
21 if (!callback) { 21 if (!callback) {
22 callback = callbackEach 22 callback = callbackEach
23 callbackEach = null 23 callbackEach = null
@@ -27,32 +27,32 @@ function makeMultipleRetryRequest (all_data, pods, callbackEach, callback) {
27 let 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 (allData.method === 'POST' && allData.data && allData.sign === true) {
31 signature = peertubeCrypto.sign(url) 31 signature = peertubeCrypto.sign(url)
32 } 32 }
33 33
34 // Make a request for each pod 34 // Make a request for each pod
35 async.each(pods, function (pod, callback_each_async) { 35 async.each(pods, function (pod, callbackEachAsync) {
36 function callbackEachRetryRequest (err, response, body, url, pod) { 36 function callbackEachRetryRequest (err, response, body, url, pod) {
37 if (callbackEach !== null) { 37 if (callbackEach !== null) {
38 callbackEach(err, response, body, url, pod, function () { 38 callbackEach(err, response, body, url, pod, function () {
39 callback_each_async() 39 callbackEachAsync()
40 }) 40 })
41 } else { 41 } else {
42 callback_each_async() 42 callbackEachAsync()
43 } 43 }
44 } 44 }
45 45
46 const params = { 46 const params = {
47 url: pod.url + all_data.path, 47 url: pod.url + allData.path,
48 method: all_data.method 48 method: allData.method
49 } 49 }
50 50
51 // Add data with POST requst ? 51 // Add data with POST requst ?
52 if (all_data.method === 'POST' && all_data.data) { 52 if (allData.method === 'POST' && allData.data) {
53 // Encrypt data ? 53 // Encrypt data ?
54 if (all_data.encrypt === true) { 54 if (allData.encrypt === true) {
55 peertubeCrypto.encrypt(pod.publicKey, JSON.stringify(all_data.data), function (err, encrypted) { 55 peertubeCrypto.encrypt(pod.publicKey, JSON.stringify(allData.data), function (err, encrypted) {
56 if (err) return callback(err) 56 if (err) return callback(err)
57 57
58 params.json = { 58 params.json = {
@@ -63,7 +63,7 @@ function makeMultipleRetryRequest (all_data, pods, callbackEach, callback) {
63 makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest) 63 makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest)
64 }) 64 })
65 } else { 65 } else {
66 params.json = { data: all_data.data } 66 params.json = { data: allData.data }
67 makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest) 67 makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest)
68 } 68 }
69 } else { 69 } else {
@@ -78,20 +78,20 @@ module.exports = requests
78 78
79// --------------------------------------------------------------------------- 79// ---------------------------------------------------------------------------
80 80
81function makeRetryRequest (params, from_url, to_pod, signature, callbackEach) { 81function makeRetryRequest (params, fromUrl, toPod, signature, callbackEach) {
82 // Append the signature 82 // Append the signature
83 if (signature) { 83 if (signature) {
84 params.json.signature = { 84 params.json.signature = {
85 url: from_url, 85 url: fromUrl,
86 signature: signature 86 signature: signature
87 } 87 }
88 } 88 }
89 89
90 logger.debug('Make retry requests to %s.', to_pod.url) 90 logger.debug('Make retry requests to %s.', toPod.url)
91 91
92 replay( 92 replay(
93 request.post(params, function (err, response, body) { 93 request.post(params, function (err, response, body) {
94 callbackEach(err, response, body, params.url, to_pod) 94 callbackEach(err, response, body, params.url, toPod)
95 }), 95 }),
96 { 96 {
97 retries: constants.REQUEST_RETRIES, 97 retries: constants.REQUEST_RETRIES,
diff --git a/server/helpers/utils.js b/server/helpers/utils.js
index 9d4d51c46..a77116e08 100644
--- a/server/helpers/utils.js
+++ b/server/helpers/utils.js
@@ -17,9 +17,9 @@ function generateRandomString (size, callback) {
17 }) 17 })
18} 18}
19 19
20function cleanForExit (webtorrent_process) { 20function cleanForExit (webtorrentProcess) {
21 logger.info('Gracefully exiting.') 21 logger.info('Gracefully exiting.')
22 process.kill(-webtorrent_process.pid) 22 process.kill(-webtorrentProcess.pid)
23} 23}
24 24
25// --------------------------------------------------------------------------- 25// ---------------------------------------------------------------------------
diff --git a/server/lib/friends.js b/server/lib/friends.js
index 3b8a52060..f4f2ada87 100644
--- a/server/lib/friends.js
+++ b/server/lib/friends.js
@@ -39,8 +39,8 @@ function hasFriends (callback) {
39 Pods.count(function (err, count) { 39 Pods.count(function (err, count) {
40 if (err) return callback(err) 40 if (err) return callback(err)
41 41
42 const has_friends = (count !== 0) 42 const hasFriends = (count !== 0)
43 callback(null, has_friends) 43 callback(null, hasFriends)
44 }) 44 })
45} 45}
46 46
@@ -49,7 +49,7 @@ function getMyCertificate (callback) {
49} 49}
50 50
51function makeFriends (callback) { 51function makeFriends (callback) {
52 const pods_score = {} 52 const podsScore = {}
53 53
54 logger.info('Make friends!') 54 logger.info('Make friends!')
55 getMyCertificate(function (err, cert) { 55 getMyCertificate(function (err, cert) {
@@ -60,16 +60,16 @@ function makeFriends (callback) {
60 60
61 const urls = config.get('network.friends') 61 const urls = config.get('network.friends')
62 62
63 async.each(urls, function (url, callback_each) { 63 async.each(urls, function (url, callbackEach) {
64 computeForeignPodsList(url, pods_score, callback_each) 64 computeForeignPodsList(url, podsScore, callbackEach)
65 }, function (err) { 65 }, function (err) {
66 if (err) return callback(err) 66 if (err) return callback(err)
67 67
68 logger.debug('Pods scores computed.', { pods_score: pods_score }) 68 logger.debug('Pods scores computed.', { podsScore: podsScore })
69 const pods_list = computeWinningPods(urls, pods_score) 69 const podsList = computeWinningPods(urls, podsScore)
70 logger.debug('Pods that we keep.', { pods_to_keep: pods_list }) 70 logger.debug('Pods that we keep.', { podsToKeep: podsList })
71 71
72 makeRequestsToWinningPods(cert, pods_list, callback) 72 makeRequestsToWinningPods(cert, podsList, callback)
73 }) 73 })
74 }) 74 })
75} 75}
@@ -102,10 +102,10 @@ function quitFriends (callback) {
102 102
103 logger.info('Broke friends, so sad :(') 103 logger.info('Broke friends, so sad :(')
104 104
105 Videos.listFromRemotes(function (err, videos_list) { 105 Videos.listFromRemotes(function (err, videosList) {
106 if (err) return callback(err) 106 if (err) return callback(err)
107 107
108 videos.removeRemoteVideos(videos_list, function (err) { 108 videos.removeRemoteVideos(videosList, function (err) {
109 if (err) { 109 if (err) {
110 logger.error('Cannot remove remote videos.', { error: err }) 110 logger.error('Cannot remove remote videos.', { error: err })
111 return callback(err) 111 return callback(err)
@@ -132,35 +132,35 @@ module.exports = pods
132 132
133// --------------------------------------------------------------------------- 133// ---------------------------------------------------------------------------
134 134
135function computeForeignPodsList (url, pods_score, callback) { 135function computeForeignPodsList (url, podsScore, callback) {
136 // Let's give 1 point to the pod we ask the friends list 136 // Let's give 1 point to the pod we ask the friends list
137 pods_score[url] = 1 137 podsScore[url] = 1
138 138
139 getForeignPodsList(url, function (err, foreign_pods_list) { 139 getForeignPodsList(url, function (err, foreignPodsList) {
140 if (err) return callback(err) 140 if (err) return callback(err)
141 if (foreign_pods_list.length === 0) return callback() 141 if (foreignPodsList.length === 0) return callback()
142 142
143 foreign_pods_list.forEach(function (foreign_pod) { 143 foreignPodsList.forEach(function (foreignPod) {
144 const foreign_url = foreign_pod.url 144 const foreignUrl = foreignPod.url
145 145
146 if (pods_score[foreign_url]) pods_score[foreign_url]++ 146 if (podsScore[foreignUrl]) podsScore[foreignUrl]++
147 else pods_score[foreign_url] = 1 147 else podsScore[foreignUrl] = 1
148 }) 148 })
149 149
150 callback() 150 callback()
151 }) 151 })
152} 152}
153 153
154function computeWinningPods (urls, pods_score) { 154function computeWinningPods (urls, podsScore) {
155 // Build the list of pods to add 155 // Build the list of pods to add
156 // Only add a pod if it exists in more than a half base pods 156 // Only add a pod if it exists in more than a half base pods
157 const pods_list = [] 157 const podsList = []
158 const base_score = urls.length / 2 158 const baseScore = urls.length / 2
159 Object.keys(pods_score).forEach(function (pod) { 159 Object.keys(baseScore).forEach(function (pod) {
160 if (pods_score[pod] > base_score) pods_list.push({ url: pod }) 160 if (podsScore[pod] > baseScore) podsList.push({ url: pod })
161 }) 161 })
162 162
163 return pods_list 163 return podsList
164} 164}
165 165
166function getForeignPodsList (url, callback) { 166function getForeignPodsList (url, callback) {
@@ -173,14 +173,14 @@ function getForeignPodsList (url, callback) {
173 }) 173 })
174} 174}
175 175
176function makeRequestsToWinningPods (cert, pods_list, callback) { 176function makeRequestsToWinningPods (cert, podsList, callback) {
177 // Stop pool requests 177 // Stop pool requests
178 requestsScheduler.deactivate() 178 requestsScheduler.deactivate()
179 // Flush pool requests 179 // Flush pool requests
180 requestsScheduler.forceSend() 180 requestsScheduler.forceSend()
181 181
182 // Get the list of our videos to send to our new friends 182 // Get the list of our videos to send to our new friends
183 Videos.listOwned(function (err, videos_list) { 183 Videos.listOwned(function (err, videosList) {
184 if (err) { 184 if (err) {
185 logger.error('Cannot get the list of videos we own.') 185 logger.error('Cannot get the list of videos we own.')
186 return callback(err) 186 return callback(err)
@@ -189,38 +189,36 @@ function makeRequestsToWinningPods (cert, pods_list, callback) {
189 const data = { 189 const data = {
190 url: http + '://' + host + ':' + port, 190 url: http + '://' + host + ':' + port,
191 publicKey: cert, 191 publicKey: cert,
192 videos: videos_list 192 videos: videosList
193 } 193 }
194 194
195 requests.makeMultipleRetryRequest( 195 requests.makeMultipleRetryRequest(
196 { method: 'POST', path: '/api/' + constants.API_VERSION + '/pods/', data: data }, 196 { method: 'POST', path: '/api/' + constants.API_VERSION + '/pods/', data: data },
197 197
198 pods_list, 198 podsList,
199 199
200 function eachRequest (err, response, body, url, pod, callback_each_request) { 200 function eachRequest (err, response, body, url, pod, callbackEachRequest) {
201 // We add the pod if it responded correctly with its public certificate 201 // We add the pod if it responded correctly with its public certificate
202 if (!err && response.statusCode === 200) { 202 if (!err && response.statusCode === 200) {
203 Pods.add({ url: pod.url, publicKey: body.cert, score: constants.FRIEND_BASE_SCORE }, function (err) { 203 Pods.add({ url: pod.url, publicKey: body.cert, score: constants.FRIEND_BASE_SCORE }, function (err) {
204 if (err) { 204 if (err) {
205 logger.error('Error with adding %s pod.', pod.url, { error: err }) 205 logger.error('Error with adding %s pod.', pod.url, { error: err })
206 return callback_each_request() 206 return callbackEachRequest()
207 } 207 }
208 console.log('hihi') 208
209 videos.createRemoteVideos(body.videos, function (err) { 209 videos.createRemoteVideos(body.videos, function (err) {
210 if (err) { 210 if (err) {
211 logger.error('Error with adding videos of pod.', pod.url, { error: err }) 211 logger.error('Error with adding videos of pod.', pod.url, { error: err })
212 return callback_each_request() 212 return callbackEachRequest()
213 } 213 }
214 214
215 console.log('kik')
216
217 logger.debug('Adding remote videos from %s.', pod.url, { videos: body.videos }) 215 logger.debug('Adding remote videos from %s.', pod.url, { videos: body.videos })
218 return callback_each_request() 216 return callbackEachRequest()
219 }) 217 })
220 }) 218 })
221 } else { 219 } else {
222 logger.error('Error with adding %s pod.', pod.url, { error: err || new Error('Status not 200') }) 220 logger.error('Error with adding %s pod.', pod.url, { error: err || new Error('Status not 200') })
223 return callback_each_request() 221 return callbackEachRequest()
224 } 222 }
225 }, 223 },
226 224
diff --git a/server/lib/requestsScheduler.js b/server/lib/requestsScheduler.js
index 4953f6a91..f10de6276 100644
--- a/server/lib/requestsScheduler.js
+++ b/server/lib/requestsScheduler.js
@@ -72,7 +72,7 @@ module.exports = requestsScheduler
72 72
73// --------------------------------------------------------------------------- 73// ---------------------------------------------------------------------------
74 74
75function makeRequest (type, requests_to_make, callback) { 75function makeRequest (type, requestsToMake, callback) {
76 if (!callback) callback = function () {} 76 if (!callback) callback = function () {}
77 77
78 Pods.list(function (err, pods) { 78 Pods.list(function (err, pods) {
@@ -83,7 +83,7 @@ function makeRequest (type, requests_to_make, callback) {
83 sign: true, 83 sign: true,
84 method: 'POST', 84 method: 'POST',
85 path: null, 85 path: null,
86 data: requests_to_make 86 data: requestsToMake
87 } 87 }
88 88
89 if (type === 'add') { 89 if (type === 'add') {
@@ -94,26 +94,26 @@ function makeRequest (type, requests_to_make, callback) {
94 return callback(new Error('Unkown pool request type.')) 94 return callback(new Error('Unkown pool request type.'))
95 } 95 }
96 96
97 const bad_pods = [] 97 const badPods = []
98 const good_pods = [] 98 const goodPods = []
99 99
100 requests.makeMultipleRetryRequest(params, pods, callbackEachPodFinished, callbackAllPodsFinished) 100 requests.makeMultipleRetryRequest(params, pods, callbackEachPodFinished, callbackAllPodsFinished)
101 101
102 function callbackEachPodFinished (err, response, body, url, pod, callback_each_pod_finished) { 102 function callbackEachPodFinished (err, response, body, url, pod, callbackEachPodFinished) {
103 if (err || (response.statusCode !== 200 && response.statusCode !== 201 && response.statusCode !== 204)) { 103 if (err || (response.statusCode !== 200 && response.statusCode !== 201 && response.statusCode !== 204)) {
104 bad_pods.push(pod._id) 104 badPods.push(pod._id)
105 logger.error('Error sending secure request to %s pod.', url, { error: err || new Error('Status code not 20x') }) 105 logger.error('Error sending secure request to %s pod.', url, { error: err || new Error('Status code not 20x') })
106 } else { 106 } else {
107 good_pods.push(pod._id) 107 goodPods.push(pod._id)
108 } 108 }
109 109
110 return callback_each_pod_finished() 110 return callbackEachPodFinished()
111 } 111 }
112 112
113 function callbackAllPodsFinished (err) { 113 function callbackAllPodsFinished (err) {
114 if (err) return callback(err) 114 if (err) return callback(err)
115 115
116 updatePodsScore(good_pods, bad_pods) 116 updatePodsScore(goodPods, badPods)
117 callback(null) 117 callback(null)
118 } 118 }
119 }) 119 })
@@ -130,7 +130,7 @@ function makeRequests () {
130 130
131 if (requests.length === 0) return 131 if (requests.length === 0) return
132 132
133 const requests_to_make = { 133 const requestsToMake = {
134 add: { 134 add: {
135 ids: [], 135 ids: [],
136 requests: [] 136 requests: []
@@ -141,35 +141,35 @@ function makeRequests () {
141 } 141 }
142 } 142 }
143 143
144 async.each(requests, function (pool_request, callback_each) { 144 async.each(requests, function (poolRequest, callbackEach) {
145 if (pool_request.type === 'add') { 145 if (poolRequest.type === 'add') {
146 requests_to_make.add.requests.push(pool_request.request) 146 requestsToMake.add.requests.push(poolRequest.request)
147 requests_to_make.add.ids.push(pool_request._id) 147 requestsToMake.add.ids.push(poolRequest._id)
148 } else if (pool_request.type === 'remove') { 148 } else if (poolRequest.type === 'remove') {
149 requests_to_make.remove.requests.push(pool_request.request) 149 requestsToMake.remove.requests.push(poolRequest.request)
150 requests_to_make.remove.ids.push(pool_request._id) 150 requestsToMake.remove.ids.push(poolRequest._id)
151 } else { 151 } else {
152 logger.error('Unkown request type.', { request_type: pool_request.type }) 152 logger.error('Unkown request type.', { request_type: poolRequest.type })
153 return // abort 153 return // abort
154 } 154 }
155 155
156 callback_each() 156 callbackEach()
157 }, function () { 157 }, function () {
158 // Send the add requests 158 // Send the add requests
159 if (requests_to_make.add.requests.length !== 0) { 159 if (requestsToMake.add.requests.length !== 0) {
160 makeRequest('add', requests_to_make.add.requests, function (err) { 160 makeRequest('add', requestsToMake.add.requests, function (err) {
161 if (err) logger.error('Errors when sent add requests.', { error: err }) 161 if (err) logger.error('Errors when sent add requests.', { error: err })
162 162
163 Requests.removeRequests(requests_to_make.add.ids) 163 Requests.removeRequests(requestsToMake.add.ids)
164 }) 164 })
165 } 165 }
166 166
167 // Send the remove requests 167 // Send the remove requests
168 if (requests_to_make.remove.requests.length !== 0) { 168 if (requestsToMake.remove.requests.length !== 0) {
169 makeRequest('remove', requests_to_make.remove.requests, function (err) { 169 makeRequest('remove', requestsToMake.remove.requests, function (err) {
170 if (err) logger.error('Errors when sent remove pool requests.', { error: err }) 170 if (err) logger.error('Errors when sent remove pool requests.', { error: err })
171 171
172 Requests.removeRequests(requests_to_make.remove.ids) 172 Requests.removeRequests(requestsToMake.remove.ids)
173 }) 173 })
174 } 174 }
175 }) 175 })
@@ -188,11 +188,11 @@ function removeBadPods () {
188 const urls = map(pods, 'url') 188 const urls = map(pods, 'url')
189 const ids = map(pods, '_id') 189 const ids = map(pods, '_id')
190 190
191 Videos.listFromUrls(urls, function (err, videos_list) { 191 Videos.listFromUrls(urls, function (err, videosList) {
192 if (err) { 192 if (err) {
193 logger.error('Cannot list videos urls.', { error: err, urls: urls }) 193 logger.error('Cannot list videos urls.', { error: err, urls: urls })
194 } else { 194 } else {
195 videos.removeRemoteVideos(videos_list, function (err) { 195 videos.removeRemoteVideos(videosList, function (err) {
196 if (err) logger.error('Cannot remove remote videos.', { error: err }) 196 if (err) logger.error('Cannot remove remote videos.', { error: err })
197 }) 197 })
198 } 198 }
@@ -201,22 +201,22 @@ function removeBadPods () {
201 if (err) { 201 if (err) {
202 logger.error('Cannot remove bad pods.', { error: err }) 202 logger.error('Cannot remove bad pods.', { error: err })
203 } else { 203 } else {
204 const pods_removed = r.result.n 204 const podsRemoved = r.result.n
205 logger.info('Removed %d pods.', pods_removed) 205 logger.info('Removed %d pods.', podsRemoved)
206 } 206 }
207 }) 207 })
208 }) 208 })
209 }) 209 })
210} 210}
211 211
212function updatePodsScore (good_pods, bad_pods) { 212function updatePodsScore (goodPods, badPods) {
213 logger.info('Updating %d good pods and %d bad pods scores.', good_pods.length, bad_pods.length) 213 logger.info('Updating %d good pods and %d bad pods scores.', goodPods.length, badPods.length)
214 214
215 Pods.incrementScores(good_pods, constants.PODS_SCORE.BONUS, function (err) { 215 Pods.incrementScores(goodPods, constants.PODS_SCORE.BONUS, function (err) {
216 if (err) logger.error('Cannot increment scores of good pods.') 216 if (err) logger.error('Cannot increment scores of good pods.')
217 }) 217 })
218 218
219 Pods.incrementScores(bad_pods, constants.PODS_SCORE.MALUS, function (err) { 219 Pods.incrementScores(badPods, constants.PODS_SCORE.MALUS, function (err) {
220 if (err) logger.error('Cannot increment scores of bad pods.') 220 if (err) logger.error('Cannot increment scores of bad pods.')
221 removeBadPods() 221 removeBadPods()
222 }) 222 })
diff --git a/server/lib/videos.js b/server/lib/videos.js
index b3497743a..7da4b11d2 100644
--- a/server/lib/videos.js
+++ b/server/lib/videos.js
@@ -29,15 +29,15 @@ const videos = {
29 29
30function createRemoteVideos (videos, callback) { 30function createRemoteVideos (videos, callback) {
31 // Create the remote videos from the new pod 31 // Create the remote videos from the new pod
32 createRemoteVideoObjects(videos, function (err, remote_videos) { 32 createRemoteVideoObjects(videos, function (err, remoteVideos) {
33 if (err) return callback(err) 33 if (err) return callback(err)
34 34
35 Videos.addRemotes(remote_videos, callback) 35 Videos.addRemotes(remoteVideos, callback)
36 }) 36 })
37} 37}
38 38
39function getVideoDuration (video_path, callback) { 39function getVideoDuration (videoPath, callback) {
40 ffmpeg.ffprobe(video_path, function (err, metadata) { 40 ffmpeg.ffprobe(videoPath, function (err, metadata) {
41 if (err) return callback(err) 41 if (err) return callback(err)
42 42
43 return callback(null, Math.floor(metadata.format.duration)) 43 return callback(null, Math.floor(metadata.format.duration))
@@ -54,9 +54,9 @@ function getVideoState (video) {
54 return { exist: exist, owned: owned } 54 return { exist: exist, owned: owned }
55} 55}
56 56
57function getVideoThumbnail (video_path, callback) { 57function getVideoThumbnail (videoPath, callback) {
58 const filename = pathUtils.basename(video_path) + '.jpg' 58 const filename = pathUtils.basename(videoPath) + '.jpg'
59 ffmpeg(video_path) 59 ffmpeg(videoPath)
60 .on('error', callback) 60 .on('error', callback)
61 .on('end', function () { 61 .on('end', function () {
62 callback(null, filename) 62 callback(null, filename)
@@ -71,7 +71,7 @@ function getVideoThumbnail (video_path, callback) {
71 71
72// Remove video datas from disk (video file, thumbnail...) 72// Remove video datas from disk (video file, thumbnail...)
73function removeVideosDataFromDisk (videos, callback) { 73function removeVideosDataFromDisk (videos, callback) {
74 async.each(videos, function (video, callback_each) { 74 async.each(videos, function (video, callbackEach) {
75 fs.unlink(thumbnailsDir + video.thumbnail, function (err) { 75 fs.unlink(thumbnailsDir + video.thumbnail, function (err) {
76 if (err) logger.error('Cannot remove the video thumbnail') 76 if (err) logger.error('Cannot remove the video thumbnail')
77 77
@@ -79,13 +79,13 @@ function removeVideosDataFromDisk (videos, callback) {
79 fs.unlink(uploadDir + video.namePath, function (err) { 79 fs.unlink(uploadDir + video.namePath, function (err) {
80 if (err) { 80 if (err) {
81 logger.error('Cannot remove this video file.') 81 logger.error('Cannot remove this video file.')
82 return callback_each(err) 82 return callbackEach(err)
83 } 83 }
84 84
85 callback_each(null) 85 callbackEach(null)
86 }) 86 })
87 } else { 87 } else {
88 callback_each(null) 88 callbackEach(null)
89 } 89 }
90 }) 90 })
91 }, callback) 91 }, callback)
@@ -110,20 +110,20 @@ function seed (path, callback) {
110} 110}
111 111
112function seedAllExisting (callback) { 112function seedAllExisting (callback) {
113 Videos.listOwned(function (err, videos_list) { 113 Videos.listOwned(function (err, videosList) {
114 if (err) { 114 if (err) {
115 logger.error('Cannot get list of the videos to seed.') 115 logger.error('Cannot get list of the videos to seed.')
116 return callback(err) 116 return callback(err)
117 } 117 }
118 118
119 async.each(videos_list, function (video, each_callback) { 119 async.each(videosList, function (video, callbackEach) {
120 seed(uploadDir + video.namePath, function (err) { 120 seed(uploadDir + video.namePath, function (err) {
121 if (err) { 121 if (err) {
122 logger.error('Cannot seed this video.') 122 logger.error('Cannot seed this video.')
123 return callback(err) 123 return callback(err)
124 } 124 }
125 125
126 each_callback(null) 126 callbackEach(null)
127 }) 127 })
128 }, callback) 128 }, callback)
129 }) 129 })
@@ -136,16 +136,16 @@ module.exports = videos
136// --------------------------------------------------------------------------- 136// ---------------------------------------------------------------------------
137 137
138function createRemoteVideoObjects (videos, callback) { 138function createRemoteVideoObjects (videos, callback) {
139 const remote_videos = [] 139 const remoteVideos = []
140 140
141 async.each(videos, function (video, callback_each) { 141 async.each(videos, function (video, callbackEach) {
142 // Creating the thumbnail for this remote video 142 // Creating the thumbnail for this remote video
143 utils.generateRandomString(16, function (err, random_string) { 143 utils.generateRandomString(16, function (err, randomString) {
144 if (err) return callback_each(err) 144 if (err) return callbackEach(err)
145 145
146 const thumbnail_name = random_string + '.jpg' 146 const thumbnailName = randomString + '.jpg'
147 createThumbnailFromBase64(thumbnail_name, video.thumbnail_base64, function (err) { 147 createThumbnailFromBase64(thumbnailName, video.thumbnailBase64, function (err) {
148 if (err) return callback_each(err) 148 if (err) return callbackEach(err)
149 149
150 const params = { 150 const params = {
151 name: video.name, 151 name: video.name,
@@ -153,21 +153,21 @@ function createRemoteVideoObjects (videos, callback) {
153 magnetUri: video.magnetUri, 153 magnetUri: video.magnetUri,
154 podUrl: video.podUrl, 154 podUrl: video.podUrl,
155 duration: video.duration, 155 duration: video.duration,
156 thumbnail: thumbnail_name 156 thumbnail: thumbnailName
157 } 157 }
158 remote_videos.push(params) 158 remoteVideos.push(params)
159 159
160 callback_each(null) 160 callbackEach(null)
161 }) 161 })
162 }) 162 })
163 }, 163 },
164 function (err) { 164 function (err) {
165 if (err) return callback(err) 165 if (err) return callback(err)
166 166
167 callback(null, remote_videos) 167 callback(null, remoteVideos)
168 }) 168 })
169} 169}
170 170
171function createThumbnailFromBase64 (thumbnail_name, data, callback) { 171function createThumbnailFromBase64 (thumbnailName, data, callback) {
172 fs.writeFile(thumbnailsDir + thumbnail_name, data, { encoding: 'base64' }, callback) 172 fs.writeFile(thumbnailsDir + thumbnailName, data, { encoding: 'base64' }, callback)
173} 173}
diff --git a/server/lib/webtorrent.js b/server/lib/webtorrent.js
index 656f8c7a8..fe2ee357f 100644
--- a/server/lib/webtorrent.js
+++ b/server/lib/webtorrent.js
@@ -7,7 +7,7 @@ const spawn = require('electron-spawn')
7 7
8const logger = require('../helpers/logger') 8const logger = require('../helpers/logger')
9 9
10const electron_debug = config.get('electron.debug') 10const electronDebug = config.get('electron.debug')
11let host = config.get('webserver.host') 11let host = config.get('webserver.host')
12let port = config.get('webserver.port') 12let port = config.get('webserver.port')
13let nodeKey = 'webtorrentnode' + port 13let nodeKey = 'webtorrentnode' + port
@@ -43,13 +43,13 @@ function create (options, callback) {
43 if (!webtorrent.silent) logger.info('IPC server ready.') 43 if (!webtorrent.silent) logger.info('IPC server ready.')
44 44
45 // Run a timeout of 30s after which we exit the process 45 // Run a timeout of 30s after which we exit the process
46 const timeout_webtorrent_process = setTimeout(function () { 46 const timeoutWebtorrentProcess = setTimeout(function () {
47 throw new Error('Timeout : cannot run the webtorrent process. Please ensure you have electron-prebuilt npm package installed with xvfb-run.') 47 throw new Error('Timeout : cannot run the webtorrent process. Please ensure you have electron-prebuilt npm package installed with xvfb-run.')
48 }, 30000) 48 }, 30000)
49 49
50 ipc.server.on(processKey + '.ready', function () { 50 ipc.server.on(processKey + '.ready', function () {
51 if (!webtorrent.silent) logger.info('Webtorrent process ready.') 51 if (!webtorrent.silent) logger.info('Webtorrent process ready.')
52 clearTimeout(timeout_webtorrent_process) 52 clearTimeout(timeoutWebtorrentProcess)
53 callback() 53 callback()
54 }) 54 })
55 55
@@ -57,19 +57,19 @@ function create (options, callback) {
57 throw new Error('Received exception error from webtorrent process : ' + data.exception) 57 throw new Error('Received exception error from webtorrent process : ' + data.exception)
58 }) 58 })
59 59
60 const webtorrent_process = spawn(pathUtils.join(__dirname, 'webtorrentProcess.js'), host, port, { detached: true }) 60 const webtorrentProcess = spawn(pathUtils.join(__dirname, 'webtorrentProcess.js'), host, port, { detached: true })
61 61
62 if (electron_debug === true) { 62 if (electronDebug === true) {
63 webtorrent_process.stderr.on('data', function (data) { 63 webtorrentProcess.stderr.on('data', function (data) {
64 logger.debug('Webtorrent process stderr: ', data.toString()) 64 logger.debug('Webtorrent process stderr: ', data.toString())
65 }) 65 })
66 66
67 webtorrent_process.stdout.on('data', function (data) { 67 webtorrentProcess.stdout.on('data', function (data) {
68 logger.debug('Webtorrent process:', data.toString()) 68 logger.debug('Webtorrent process:', data.toString())
69 }) 69 })
70 } 70 }
71 71
72 webtorrent.app = webtorrent_process 72 webtorrent.app = webtorrentProcess
73 }) 73 })
74 74
75 ipc.server.start() 75 ipc.server.start()
@@ -88,8 +88,8 @@ function seed (path, callback) {
88 if (!webtorrent.silent) logger.debug('Node wants to seed %s.', data._id) 88 if (!webtorrent.silent) logger.debug('Node wants to seed %s.', data._id)
89 89
90 // Finish signal 90 // Finish signal
91 const event_key = nodeKey + '.seedDone.' + data._id 91 const eventKey = nodeKey + '.seedDone.' + data._id
92 ipc.server.on(event_key, function listener (received) { 92 ipc.server.on(eventKey, function listener (received) {
93 if (!webtorrent.silent) logger.debug('Process seeded torrent %s.', received.magnetUri) 93 if (!webtorrent.silent) logger.debug('Process seeded torrent %s.', received.magnetUri)
94 94
95 // This is a fake object, we just use the magnetUri in this project 95 // This is a fake object, we just use the magnetUri in this project
@@ -97,7 +97,7 @@ function seed (path, callback) {
97 magnetURI: received.magnetUri 97 magnetURI: received.magnetUri
98 } 98 }
99 99
100 ipc.server.off(event_key) 100 ipc.server.off(eventKey)
101 callback(torrent) 101 callback(torrent)
102 }) 102 })
103 103
@@ -115,8 +115,8 @@ function add (magnetUri, callback) {
115 if (!webtorrent.silent) logger.debug('Node wants to add ' + data._id) 115 if (!webtorrent.silent) logger.debug('Node wants to add ' + data._id)
116 116
117 // Finish signal 117 // Finish signal
118 const event_key = nodeKey + '.addDone.' + data._id 118 const eventKey = nodeKey + '.addDone.' + data._id
119 ipc.server.on(event_key, function (received) { 119 ipc.server.on(eventKey, function (received) {
120 if (!webtorrent.silent) logger.debug('Process added torrent.') 120 if (!webtorrent.silent) logger.debug('Process added torrent.')
121 121
122 // This is a fake object, we just use the magnetUri in this project 122 // This is a fake object, we just use the magnetUri in this project
@@ -124,7 +124,7 @@ function add (magnetUri, callback) {
124 files: received.files 124 files: received.files
125 } 125 }
126 126
127 ipc.server.off(event_key) 127 ipc.server.off(eventKey)
128 callback(torrent) 128 callback(torrent)
129 }) 129 })
130 130
@@ -142,14 +142,14 @@ function remove (magnetUri, callback) {
142 if (!webtorrent.silent) logger.debug('Node wants to stop seeding %s.', data._id) 142 if (!webtorrent.silent) logger.debug('Node wants to stop seeding %s.', data._id)
143 143
144 // Finish signal 144 // Finish signal
145 const event_key = nodeKey + '.removeDone.' + data._id 145 const eventKey = nodeKey + '.removeDone.' + data._id
146 ipc.server.on(event_key, function (received) { 146 ipc.server.on(eventKey, function (received) {
147 if (!webtorrent.silent) logger.debug('Process removed torrent %s.', data._id) 147 if (!webtorrent.silent) logger.debug('Process removed torrent %s.', data._id)
148 148
149 let err = null 149 let err = null
150 if (received.err) err = received.err 150 if (received.err) err = received.err
151 151
152 ipc.server.off(event_key) 152 ipc.server.off(eventKey)
153 callback(err) 153 callback(err)
154 }) 154 })
155 155
diff --git a/server/lib/webtorrentProcess.js b/server/lib/webtorrentProcess.js
index 7889e7128..be7ac5bb4 100644
--- a/server/lib/webtorrentProcess.js
+++ b/server/lib/webtorrentProcess.js
@@ -26,11 +26,11 @@ function webtorrent (args) {
26 const _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 const to_send = { 29 const toSend = {
30 magnetUri: torrent.magnetURI 30 magnetUri: torrent.magnetURI
31 } 31 }
32 32
33 ipc.of[nodeKey].emit(nodeKey + '.seedDone.' + _id, to_send) 33 ipc.of[nodeKey].emit(nodeKey + '.seedDone.' + _id, toSend)
34 }) 34 })
35 } 35 }
36 36
@@ -40,15 +40,15 @@ function webtorrent (args) {
40 const _id = data._id 40 const _id = data._id
41 41
42 wt.add(magnetUri, function (torrent) { 42 wt.add(magnetUri, function (torrent) {
43 const to_send = { 43 const toSend = {
44 files: [] 44 files: []
45 } 45 }
46 46
47 torrent.files.forEach(function (file) { 47 torrent.files.forEach(function (file) {
48 to_send.files.push({ path: file.path }) 48 toSend.files.push({ path: file.path })
49 }) 49 })
50 50
51 ipc.of[nodeKey].emit(nodeKey + '.addDone.' + _id, to_send) 51 ipc.of[nodeKey].emit(nodeKey + '.addDone.' + _id, toSend)
52 }) 52 })
53 } 53 }
54 54
@@ -65,8 +65,8 @@ function webtorrent (args) {
65 } 65 }
66 66
67 function callback () { 67 function callback () {
68 const to_send = {} 68 const toSend = {}
69 ipc.of[nodeKey].emit(nodeKey + '.removeDone.' + _id, to_send) 69 ipc.of[nodeKey].emit(nodeKey + '.removeDone.' + _id, toSend)
70 } 70 }
71 } 71 }
72 72
diff --git a/server/middlewares/reqValidators/pods.js b/server/middlewares/reqValidators/pods.js
index 45e34c1ab..77449480c 100644
--- a/server/middlewares/reqValidators/pods.js
+++ b/server/middlewares/reqValidators/pods.js
@@ -10,13 +10,13 @@ const reqValidatorsPod = {
10} 10}
11 11
12function makeFriends (req, res, next) { 12function makeFriends (req, res, next) {
13 friends.hasFriends(function (err, has_friends) { 13 friends.hasFriends(function (err, hasFriends) {
14 if (err) { 14 if (err) {
15 logger.error('Cannot know if we have friends.', { error: err }) 15 logger.error('Cannot know if we have friends.', { error: err })
16 res.sendStatus(500) 16 res.sendStatus(500)
17 } 17 }
18 18
19 if (has_friends === true) { 19 if (hasFriends === true) {
20 // We need to quit our friends before make new ones 20 // We need to quit our friends before make new ones
21 res.sendStatus(409) 21 res.sendStatus(409)
22 } else { 22 } else {
diff --git a/server/middlewares/reqValidators/utils.js b/server/middlewares/reqValidators/utils.js
index 05675c445..198ed8d26 100644
--- a/server/middlewares/reqValidators/utils.js
+++ b/server/middlewares/reqValidators/utils.js
@@ -8,13 +8,13 @@ const reqValidatorsUtils = {
8 checkErrors: checkErrors 8 checkErrors: checkErrors
9} 9}
10 10
11function checkErrors (req, res, next, status_code) { 11function checkErrors (req, res, next, statusCode) {
12 if (status_code === undefined) status_code = 400 12 if (statusCode === undefined) statusCode = 400
13 const 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 })
17 return res.status(status_code).send('There have been validation errors: ' + util.inspect(errors)) 17 return res.status(statusCode).send('There have been validation errors: ' + util.inspect(errors))
18 } 18 }
19 19
20 return next() 20 return next()
diff --git a/server/middlewares/secure.js b/server/middlewares/secure.js
index 9ecbf5df1..ad7b0fbf7 100644
--- a/server/middlewares/secure.js
+++ b/server/middlewares/secure.js
@@ -23,9 +23,9 @@ 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 const signature_ok = peertubeCrypto.checkSignature(pod.publicKey, url, req.body.signature.signature) 26 const signatureOk = peertubeCrypto.checkSignature(pod.publicKey, url, req.body.signature.signature)
27 27
28 if (signature_ok === true) { 28 if (signatureOk === 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) {
30 if (err) { 30 if (err) {
31 logger.error('Cannot decrypt data.', { error: err }) 31 logger.error('Cannot decrypt data.', { error: err })
diff --git a/server/models/pods.js b/server/models/pods.js
index 4e21001f5..04cc2d6fc 100644
--- a/server/models/pods.js
+++ b/server/models/pods.js
@@ -58,13 +58,13 @@ function incrementScores (ids, value, callback) {
58} 58}
59 59
60function list (callback) { 60function list (callback) {
61 PodsDB.find(function (err, pods_list) { 61 PodsDB.find(function (err, podsList) {
62 if (err) { 62 if (err) {
63 logger.error('Cannot get the list of the pods.') 63 logger.error('Cannot get the list of the pods.')
64 return callback(err) 64 return callback(err)
65 } 65 }
66 66
67 return callback(null, pods_list) 67 return callback(null, podsList)
68 }) 68 })
69} 69}
70 70
diff --git a/server/models/users.js b/server/models/users.js
index a852bf25b..a1bdece23 100644
--- a/server/models/users.js
+++ b/server/models/users.js
@@ -45,11 +45,11 @@ const Users = {
45function createClient (secret, grants, callback) { 45function createClient (secret, grants, callback) {
46 logger.debug('Creating client.') 46 logger.debug('Creating client.')
47 47
48 const mongo_id = new mongoose.mongo.ObjectID() 48 const mongoId = new mongoose.mongo.ObjectID()
49 return OAuthClientsDB.create({ _id: mongo_id, clientSecret: secret, grants: grants }, function (err) { 49 return OAuthClientsDB.create({ _id: mongoId, clientSecret: secret, grants: grants }, function (err) {
50 if (err) return callback(err) 50 if (err) return callback(err)
51 51
52 return callback(null, mongo_id) 52 return callback(null, mongoId)
53 }) 53 })
54} 54}
55 55
@@ -73,8 +73,8 @@ function getClient (clientId, clientSecret) {
73 logger.debug('Getting Client (clientId: ' + clientId + ', clientSecret: ' + clientSecret + ').') 73 logger.debug('Getting Client (clientId: ' + clientId + ', clientSecret: ' + clientSecret + ').')
74 74
75 // TODO req validator 75 // TODO req validator
76 const mongo_id = new mongoose.mongo.ObjectID(clientId) 76 const mongoId = new mongoose.mongo.ObjectID(clientId)
77 return OAuthClientsDB.findOne({ _id: mongo_id, clientSecret: clientSecret }) 77 return OAuthClientsDB.findOne({ _id: mongoId, clientSecret: clientSecret })
78} 78}
79 79
80function getClients (callback) { 80function getClients (callback) {
@@ -99,7 +99,7 @@ function getUsers (callback) {
99function saveToken (token, client, user) { 99function saveToken (token, client, user) {
100 logger.debug('Saving token for client ' + client.id + ' and user ' + user.id + '.') 100 logger.debug('Saving token for client ' + client.id + ' and user ' + user.id + '.')
101 101
102 const token_to_create = { 102 const tokenToCreate = {
103 accessToken: token.accessToken, 103 accessToken: token.accessToken,
104 accessTokenExpiresOn: token.accessTokenExpiresOn, 104 accessTokenExpiresOn: token.accessTokenExpiresOn,
105 client: client.id, 105 client: client.id,
@@ -108,13 +108,13 @@ function saveToken (token, client, user) {
108 user: user.id 108 user: user.id
109 } 109 }
110 110
111 return OAuthTokensDB.create(token_to_create, function (err, token_created) { 111 return OAuthTokensDB.create(tokenToCreate, function (err, tokenCreated) {
112 if (err) throw err // node-oauth2-server library uses Promise.try 112 if (err) throw err // node-oauth2-server library uses Promise.try
113 113
114 token_created.client = client 114 tokenCreated.client = client
115 token_created.user = user 115 tokenCreated.user = user
116 116
117 return token_created 117 return tokenCreated
118 }) 118 })
119} 119}
120 120
diff --git a/server/models/videos.js b/server/models/videos.js
index eedb6eb58..eaea35b7f 100644
--- a/server/models/videos.js
+++ b/server/models/videos.js
@@ -77,13 +77,13 @@ function get (id, callback) {
77} 77}
78 78
79function list (callback) { 79function list (callback) {
80 VideosDB.find(function (err, videos_list) { 80 VideosDB.find(function (err, videosList) {
81 if (err) { 81 if (err) {
82 logger.error('Cannot get the list of the videos.') 82 logger.error('Cannot get the list of the videos.')
83 return callback(err) 83 return callback(err)
84 } 84 }
85 85
86 return callback(null, videos_list) 86 return callback(null, videosList)
87 }) 87 })
88} 88}
89 89
@@ -105,13 +105,13 @@ function listFromRemotes (callback) {
105 105
106function listOwned (callback) { 106function listOwned (callback) {
107 // If namePath is not null this is *our* video 107 // If namePath is not null this is *our* video
108 VideosDB.find({ namePath: { $ne: null } }, function (err, videos_list) { 108 VideosDB.find({ namePath: { $ne: null } }, function (err, videosList) {
109 if (err) { 109 if (err) {
110 logger.error('Cannot get the list of owned videos.') 110 logger.error('Cannot get the list of owned videos.')
111 return callback(err) 111 return callback(err)
112 } 112 }
113 113
114 return callback(null, videos_list) 114 return callback(null, videosList)
115 }) 115 })
116} 116}
117 117
diff --git a/server/tests/api/checkParams.js b/server/tests/api/checkParams.js
index 59ee0bfc3..71113fd39 100644
--- a/server/tests/api/checkParams.js
+++ b/server/tests/api/checkParams.js
@@ -12,8 +12,8 @@ describe('Test parameters validator', function () {
12 let server = null 12 let server = null
13 13
14 function makePostRequest (path, token, fields, attach, done, fail) { 14 function makePostRequest (path, token, fields, attach, done, fail) {
15 let status_code = 400 15 let statusCode = 400
16 if (fail !== undefined && fail === false) status_code = 200 16 if (fail !== undefined && fail === false) statusCode = 200
17 17
18 const req = request(server.url) 18 const req = request(server.url)
19 .post(path) 19 .post(path)
@@ -26,18 +26,18 @@ describe('Test parameters validator', function () {
26 req.field(field, value) 26 req.field(field, value)
27 }) 27 })
28 28
29 req.expect(status_code, done) 29 req.expect(statusCode, done)
30 } 30 }
31 31
32 function makePostBodyRequest (path, fields, done, fail) { 32 function makePostBodyRequest (path, fields, done, fail) {
33 let status_code = 400 33 let statusCode = 400
34 if (fail !== undefined && fail === false) status_code = 200 34 if (fail !== undefined && fail === false) statusCode = 200
35 35
36 request(server.url) 36 request(server.url)
37 .post(path) 37 .post(path)
38 .set('Accept', 'application/json') 38 .set('Accept', 'application/json')
39 .send(fields) 39 .send(fields)
40 .expect(status_code, done) 40 .expect(statusCode, done)
41 } 41 }
42 42
43 // --------------------------------------------------------------- 43 // ---------------------------------------------------------------
diff --git a/server/tests/api/friendsAdvanced.js b/server/tests/api/friendsAdvanced.js
index 6f18648d7..833a530dd 100644
--- a/server/tests/api/friendsAdvanced.js
+++ b/server/tests/api/friendsAdvanced.js
@@ -9,44 +9,44 @@ const utils = require('./utils')
9describe('Test advanced friends', function () { 9describe('Test advanced friends', function () {
10 let servers = [] 10 let servers = []
11 11
12 function makeFriends (pod_number, callback) { 12 function makeFriends (podNumber, callback) {
13 return utils.makeFriends(servers[pod_number - 1].url, callback) 13 return utils.makeFriends(servers[podNumber - 1].url, callback)
14 } 14 }
15 15
16 function quitFriends (pod_number, callback) { 16 function quitFriends (podNumber, callback) {
17 return utils.quitFriends(servers[pod_number - 1].url, callback) 17 return utils.quitFriends(servers[podNumber - 1].url, callback)
18 } 18 }
19 19
20 function getFriendsList (pod_number, end) { 20 function getFriendsList (podNumber, end) {
21 return utils.getFriendsList(servers[pod_number - 1].url, end) 21 return utils.getFriendsList(servers[podNumber - 1].url, end)
22 } 22 }
23 23
24 function uploadVideo (pod_number, callback) { 24 function uploadVideo (podNumber, callback) {
25 const name = 'my super video' 25 const name = 'my super video'
26 const description = 'my super description' 26 const description = 'my super description'
27 const fixture = 'video_short.webm' 27 const fixture = 'video_short.webm'
28 const server = servers[pod_number - 1] 28 const server = servers[podNumber - 1]
29 29
30 return utils.uploadVideo(server.url, server.access_token, name, description, fixture, callback) 30 return utils.uploadVideo(server.url, server.access_token, name, description, fixture, callback)
31 } 31 }
32 32
33 function getVideos (pod_number, callback) { 33 function getVideos (podNumber, callback) {
34 return utils.getVideosList(servers[pod_number - 1].url, callback) 34 return utils.getVideosList(servers[podNumber - 1].url, callback)
35 } 35 }
36 36
37 // --------------------------------------------------------------- 37 // ---------------------------------------------------------------
38 38
39 before(function (done) { 39 before(function (done) {
40 this.timeout(30000) 40 this.timeout(30000)
41 utils.flushAndRunMultipleServers(6, function (servers_run, urls_run) { 41 utils.flushAndRunMultipleServers(6, function (serversRun, urlsRun) {
42 servers = servers_run 42 servers = serversRun
43 43
44 async.each(servers, function (server, callback_each) { 44 async.each(servers, function (server, callbackEach) {
45 utils.loginAndGetAccessToken(server, function (err, access_token) { 45 utils.loginAndGetAccessToken(server, function (err, accessToken) {
46 if (err) return callback_each(err) 46 if (err) return callbackEach(err)
47 47
48 server.access_token = access_token 48 server.accessToken = accessToken
49 callback_each() 49 callbackEach()
50 }) 50 })
51 }, done) 51 }, done)
52 }) 52 })
diff --git a/server/tests/api/friendsBasic.js b/server/tests/api/friendsBasic.js
index 49e51804f..c9e3bc9ad 100644
--- a/server/tests/api/friendsBasic.js
+++ b/server/tests/api/friendsBasic.js
@@ -10,25 +10,25 @@ const utils = require('./utils')
10describe('Test basic friends', function () { 10describe('Test basic friends', function () {
11 let servers = [] 11 let servers = []
12 12
13 function testMadeFriends (servers, server_to_test, callback) { 13 function testMadeFriends (servers, serverToTest, callback) {
14 const friends = [] 14 const friends = []
15 for (let i = 0; i < servers.length; i++) { 15 for (let i = 0; i < servers.length; i++) {
16 if (servers[i].url === server_to_test.url) continue 16 if (servers[i].url === serverToTest.url) continue
17 friends.push(servers[i].url) 17 friends.push(servers[i].url)
18 } 18 }
19 19
20 utils.getFriendsList(server_to_test.url, function (err, res) { 20 utils.getFriendsList(serverToTest.url, function (err, res) {
21 if (err) throw err 21 if (err) throw err
22 22
23 const result = res.body 23 const result = res.body
24 const result_urls = [ result[0].url, result[1].url ] 24 const resultUrls = [ result[0].url, result[1].url ]
25 expect(result).to.be.an('array') 25 expect(result).to.be.an('array')
26 expect(result.length).to.equal(2) 26 expect(result.length).to.equal(2)
27 expect(result_urls[0]).to.not.equal(result_urls[1]) 27 expect(resultUrls[0]).to.not.equal(resultUrls[1])
28 28
29 const error_string = 'Friends url do not correspond for ' + server_to_test.url 29 const errorString = 'Friends url do not correspond for ' + serverToTest.url
30 expect(friends).to.contain(result_urls[0], error_string) 30 expect(friends).to.contain(resultUrls[0], errorString)
31 expect(friends).to.contain(result_urls[1], error_string) 31 expect(friends).to.contain(resultUrls[1], errorString)
32 callback() 32 callback()
33 }) 33 })
34 } 34 }
@@ -37,8 +37,8 @@ describe('Test basic friends', function () {
37 37
38 before(function (done) { 38 before(function (done) {
39 this.timeout(20000) 39 this.timeout(20000)
40 utils.flushAndRunMultipleServers(3, function (servers_run, urls_run) { 40 utils.flushAndRunMultipleServers(3, function (serversRun, urlsRun) {
41 servers = servers_run 41 servers = serversRun
42 done() 42 done()
43 }) 43 })
44 }) 44 })
diff --git a/server/tests/api/multiplePods.js b/server/tests/api/multiplePods.js
index b361e373b..f1415f6f1 100644
--- a/server/tests/api/multiplePods.js
+++ b/server/tests/api/multiplePods.js
@@ -11,7 +11,7 @@ webtorrent.silent = true
11 11
12describe('Test multiple pods', function () { 12describe('Test multiple pods', function () {
13 let servers = [] 13 let servers = []
14 const to_remove = [] 14 const toRemove = []
15 15
16 before(function (done) { 16 before(function (done) {
17 this.timeout(30000) 17 this.timeout(30000)
@@ -19,19 +19,19 @@ describe('Test multiple pods', function () {
19 async.series([ 19 async.series([
20 // Run servers 20 // Run servers
21 function (next) { 21 function (next) {
22 utils.flushAndRunMultipleServers(3, function (servers_run) { 22 utils.flushAndRunMultipleServers(3, function (serversRun) {
23 servers = servers_run 23 servers = serversRun
24 next() 24 next()
25 }) 25 })
26 }, 26 },
27 // Get the access tokens 27 // Get the access tokens
28 function (next) { 28 function (next) {
29 async.each(servers, function (server, callback_each) { 29 async.each(servers, function (server, callbackEach) {
30 utils.loginAndGetAccessToken(server, function (err, access_token) { 30 utils.loginAndGetAccessToken(server, function (err, accessToken) {
31 if (err) return callback_each(err) 31 if (err) return callbackEach(err)
32 32
33 server.access_token = access_token 33 server.accessToken = accessToken
34 callback_each() 34 callbackEach()
35 }) 35 })
36 }, next) 36 }, next)
37 }, 37 },
@@ -82,7 +82,7 @@ describe('Test multiple pods', function () {
82 if (err) throw err 82 if (err) throw err
83 83
84 async.each(servers, function (server, callback) { 84 async.each(servers, function (server, callback) {
85 let base_magnet = null 85 let baseMagnet = null
86 86
87 utils.getVideosList(server.url, function (err, res) { 87 utils.getVideosList(server.url, function (err, res) {
88 if (err) throw err 88 if (err) throw err
@@ -104,8 +104,8 @@ describe('Test multiple pods', function () {
104 } 104 }
105 105
106 // All pods should have the same magnet Uri 106 // All pods should have the same magnet Uri
107 if (base_magnet === null) { 107 if (baseMagnet === null) {
108 base_magnet = video.magnetUri 108 baseMagnet = video.magnetUri
109 } else { 109 } else {
110 expect(video.magnetUri).to.equal.magnetUri 110 expect(video.magnetUri).to.equal.magnetUri
111 } 111 }
@@ -137,7 +137,7 @@ describe('Test multiple pods', function () {
137 if (err) throw err 137 if (err) throw err
138 138
139 async.each(servers, function (server, callback) { 139 async.each(servers, function (server, callback) {
140 let base_magnet = null 140 let baseMagnet = null
141 141
142 utils.getVideosList(server.url, function (err, res) { 142 utils.getVideosList(server.url, function (err, res) {
143 if (err) throw err 143 if (err) throw err
@@ -159,8 +159,8 @@ describe('Test multiple pods', function () {
159 } 159 }
160 160
161 // All pods should have the same magnet Uri 161 // All pods should have the same magnet Uri
162 if (base_magnet === null) { 162 if (baseMagnet === null) {
163 base_magnet = video.magnetUri 163 baseMagnet = video.magnetUri
164 } else { 164 } else {
165 expect(video.magnetUri).to.equal.magnetUri 165 expect(video.magnetUri).to.equal.magnetUri
166 } 166 }
@@ -193,7 +193,7 @@ describe('Test multiple pods', function () {
193 function (err) { 193 function (err) {
194 if (err) throw err 194 if (err) throw err
195 195
196 let base_magnet = null 196 let baseMagnet = null
197 // All pods should have this video 197 // All pods should have this video
198 async.each(servers, function (server, callback) { 198 async.each(servers, function (server, callback) {
199 utils.getVideosList(server.url, function (err, res) { 199 utils.getVideosList(server.url, function (err, res) {
@@ -235,8 +235,8 @@ describe('Test multiple pods', function () {
235 } 235 }
236 236
237 // All pods should have the same magnet Uri 237 // All pods should have the same magnet Uri
238 if (base_magnet === null) { 238 if (baseMagnet === null) {
239 base_magnet = video2.magnetUri 239 baseMagnet = video2.magnetUri
240 } else { 240 } else {
241 expect(video2.magnetUri).to.equal.magnetUri 241 expect(video2.magnetUri).to.equal.magnetUri
242 } 242 }
@@ -268,8 +268,8 @@ describe('Test multiple pods', function () {
268 if (err) throw err 268 if (err) throw err
269 269
270 const video = res.body[0] 270 const video = res.body[0]
271 to_remove.push(res.body[2].id) 271 toRemove.push(res.body[2].id)
272 to_remove.push(res.body[3].id) 272 toRemove.push(res.body[3].id)
273 273
274 webtorrent.add(video.magnetUri, function (torrent) { 274 webtorrent.add(video.magnetUri, function (torrent) {
275 expect(torrent.files).to.exist 275 expect(torrent.files).to.exist
@@ -343,10 +343,10 @@ describe('Test multiple pods', function () {
343 343
344 async.series([ 344 async.series([
345 function (next) { 345 function (next) {
346 utils.removeVideo(servers[2].url, servers[2].access_token, to_remove[0], next) 346 utils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0], next)
347 }, 347 },
348 function (next) { 348 function (next) {
349 utils.removeVideo(servers[2].url, servers[2].access_token, to_remove[1], next) 349 utils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1], next)
350 }], 350 }],
351 function (err) { 351 function (err) {
352 if (err) throw err 352 if (err) throw err
@@ -364,10 +364,10 @@ describe('Test multiple pods', function () {
364 expect(videos).to.be.an('array') 364 expect(videos).to.be.an('array')
365 expect(videos.length).to.equal(2) 365 expect(videos.length).to.equal(2)
366 expect(videos[0].id).not.to.equal(videos[1].id) 366 expect(videos[0].id).not.to.equal(videos[1].id)
367 expect(videos[0].id).not.to.equal(to_remove[0]) 367 expect(videos[0].id).not.to.equal(toRemove[0])
368 expect(videos[1].id).not.to.equal(to_remove[0]) 368 expect(videos[1].id).not.to.equal(toRemove[0])
369 expect(videos[0].id).not.to.equal(to_remove[1]) 369 expect(videos[0].id).not.to.equal(toRemove[1])
370 expect(videos[1].id).not.to.equal(to_remove[1]) 370 expect(videos[1].id).not.to.equal(toRemove[1])
371 371
372 callback() 372 callback()
373 }) 373 })
diff --git a/server/tests/api/singlePod.js b/server/tests/api/singlePod.js
index e8b578770..542dea430 100644
--- a/server/tests/api/singlePod.js
+++ b/server/tests/api/singlePod.js
@@ -14,7 +14,7 @@ const utils = require('./utils')
14 14
15describe('Test a single pod', function () { 15describe('Test a single pod', function () {
16 let server = null 16 let server = null
17 let video_id = -1 17 let videoId = -1
18 18
19 before(function (done) { 19 before(function (done) {
20 this.timeout(20000) 20 this.timeout(20000)
@@ -80,7 +80,7 @@ describe('Test a single pod', function () {
80 if (err) throw err 80 if (err) throw err
81 expect(test).to.equal(true) 81 expect(test).to.equal(true)
82 82
83 video_id = video.id 83 videoId = video.id
84 84
85 webtorrent.add(video.magnetUri, function (torrent) { 85 webtorrent.add(video.magnetUri, function (torrent) {
86 expect(torrent.files).to.exist 86 expect(torrent.files).to.exist
@@ -97,7 +97,7 @@ describe('Test a single pod', function () {
97 // Yes, this could be long 97 // Yes, this could be long
98 this.timeout(60000) 98 this.timeout(60000)
99 99
100 utils.getVideo(server.url, video_id, function (err, res) { 100 utils.getVideo(server.url, videoId, function (err, res) {
101 if (err) throw err 101 if (err) throw err
102 102
103 const video = res.body 103 const video = res.body
@@ -158,7 +158,7 @@ describe('Test a single pod', function () {
158 }) 158 })
159 159
160 it('Should remove the video', function (done) { 160 it('Should remove the video', function (done) {
161 utils.removeVideo(server.url, server.access_token, video_id, function (err) { 161 utils.removeVideo(server.url, server.accessToken, videoId, function (err) {
162 if (err) throw err 162 if (err) throw err
163 163
164 fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) { 164 fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) {
@@ -187,8 +187,8 @@ describe('Test a single pod', function () {
187 'video_short.mp4', 'video_short.ogv', 'video_short.webm', 187 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
188 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' 188 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
189 ] 189 ]
190 async.each(videos, function (video, callback_each) { 190 async.each(videos, function (video, callbackEach) {
191 utils.uploadVideo(server.url, server.access_token, video + ' name', video + ' description', video, callback_each) 191 utils.uploadVideo(server.url, server.accessToken, video + ' name', video + ' description', video, callbackEach)
192 }, done) 192 }, done)
193 }) 193 })
194 194
@@ -200,13 +200,13 @@ describe('Test a single pod', function () {
200 expect(videos).to.be.an('array') 200 expect(videos).to.be.an('array')
201 expect(videos.length).to.equal(6) 201 expect(videos.length).to.equal(6)
202 202
203 const videos_by_name = keyBy(videos, 'name') 203 const videosByName = keyBy(videos, 'name')
204 expect(videos_by_name['video_short.mp4 name'].duration).to.equal(5) 204 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
205 expect(videos_by_name['video_short.ogv name'].duration).to.equal(5) 205 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
206 expect(videos_by_name['video_short.webm name'].duration).to.equal(5) 206 expect(videosByName['video_short.webm name'].duration).to.equal(5)
207 expect(videos_by_name['video_short1.webm name'].duration).to.equal(10) 207 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
208 expect(videos_by_name['video_short2.webm name'].duration).to.equal(5) 208 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
209 expect(videos_by_name['video_short3.webm name'].duration).to.equal(5) 209 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
210 210
211 done() 211 done()
212 }) 212 })
@@ -216,15 +216,15 @@ describe('Test a single pod', function () {
216 utils.getVideosList(server.url, function (err, res) { 216 utils.getVideosList(server.url, function (err, res) {
217 const videos = res.body 217 const videos = res.body
218 218
219 async.each(videos, function (video, callback_each) { 219 async.each(videos, function (video, callbackEach) {
220 if (err) throw err 220 if (err) throw err
221 const video_name = video.name.replace(' name', '') 221 const videoName = video.name.replace(' name', '')
222 222
223 utils.testImage(server.url, video_name, video.thumbnailPath, function (err, test) { 223 utils.testImage(server.url, videoName, video.thumbnailPath, function (err, test) {
224 if (err) throw err 224 if (err) throw err
225 225
226 expect(test).to.equal(true) 226 expect(test).to.equal(true)
227 callback_each() 227 callbackEach()
228 }) 228 })
229 }, done) 229 }, done)
230 }) 230 })
diff --git a/server/tests/api/users.js b/server/tests/api/users.js
index e5395a79f..57417a69e 100644
--- a/server/tests/api/users.js
+++ b/server/tests/api/users.js
@@ -12,8 +12,8 @@ const utils = require('./utils')
12 12
13describe('Test users', function () { 13describe('Test users', function () {
14 let server = null 14 let server = null
15 let access_token = null 15 let accessToken = null
16 let video_id 16 let videoId
17 17
18 before(function (done) { 18 before(function (done) {
19 this.timeout(20000) 19 this.timeout(20000)
@@ -78,21 +78,21 @@ describe('Test users', function () {
78 }) 78 })
79 79
80 it('Should not be able to upload a video', function (done) { 80 it('Should not be able to upload a video', function (done) {
81 access_token = 'mysupertoken' 81 accessToken = 'mysupertoken'
82 utils.uploadVideo(server.url, access_token, 'my super name', 'my super description', 'video_short.webm', 401, done) 82 utils.uploadVideo(server.url, accessToken, 'my super name', 'my super description', 'video_short.webm', 401, done)
83 }) 83 })
84 84
85 it('Should be able to login', function (done) { 85 it('Should be able to login', function (done) {
86 utils.login(server.url, server.client, server.user, 200, function (err, res) { 86 utils.login(server.url, server.client, server.user, 200, function (err, res) {
87 if (err) throw err 87 if (err) throw err
88 88
89 access_token = res.body.access_token 89 accessToken = res.body.access_token
90 done() 90 done()
91 }) 91 })
92 }) 92 })
93 93
94 it('Should upload the video with the correct token', function (done) { 94 it('Should upload the video with the correct token', function (done) {
95 utils.uploadVideo(server.url, access_token, 'my super name', 'my super description', 'video_short.webm', 204, function (err, res) { 95 utils.uploadVideo(server.url, accessToken, 'my super name', 'my super description', 'video_short.webm', 204, function (err, res) {
96 if (err) throw err 96 if (err) throw err
97 97
98 utils.getVideosList(server.url, function (err, res) { 98 utils.getVideosList(server.url, function (err, res) {
@@ -101,24 +101,24 @@ describe('Test users', function () {
101 const video = res.body[0] 101 const video = res.body[0]
102 expect(video.author).to.equal('root') 102 expect(video.author).to.equal('root')
103 103
104 video_id = video.id 104 videoId = video.id
105 done() 105 done()
106 }) 106 })
107 }) 107 })
108 }) 108 })
109 109
110 it('Should upload the video again with the correct token', function (done) { 110 it('Should upload the video again with the correct token', function (done) {
111 utils.uploadVideo(server.url, access_token, 'my super name 2', 'my super description 2', 'video_short.webm', 204, done) 111 utils.uploadVideo(server.url, accessToken, 'my super name 2', 'my super description 2', 'video_short.webm', 204, done)
112 }) 112 })
113 113
114 it('Should not be able to remove the video with an incorrect token', function (done) { 114 it('Should not be able to remove the video with an incorrect token', function (done) {
115 utils.removeVideo(server.url, 'bad_token', video_id, 401, done) 115 utils.removeVideo(server.url, 'bad_token', videoId, 401, done)
116 }) 116 })
117 117
118 it('Should not be able to remove the video with the token of another account') 118 it('Should not be able to remove the video with the token of another account')
119 119
120 it('Should be able to remove the video with the correct token', function (done) { 120 it('Should be able to remove the video with the correct token', function (done) {
121 utils.removeVideo(server.url, access_token, video_id, done) 121 utils.removeVideo(server.url, accessToken, videoId, done)
122 }) 122 })
123 123
124 it('Should logout') 124 it('Should logout')
diff --git a/server/tests/api/utils.js b/server/tests/api/utils.js
index 3d3169fde..45f11ac8f 100644
--- a/server/tests/api/utils.js
+++ b/server/tests/api/utils.js
@@ -1,8 +1,8 @@
1'use strict' 1'use strict'
2 2
3const child_process = require('child_process') 3const childProcess = require('child_process')
4const exec = child_process.exec 4const exec = childProcess.exec
5const fork = child_process.fork 5const fork = childProcess.fork
6const fs = require('fs') 6const fs = require('fs')
7const pathUtils = require('path') 7const pathUtils = require('path')
8const request = require('supertest') 8const request = require('supertest')
@@ -63,10 +63,10 @@ function getVideosList (url, end) {
63 .end(end) 63 .end(end)
64} 64}
65 65
66function login (url, client, user, expected_status, end) { 66function login (url, client, user, expectedStatus, end) {
67 if (!end) { 67 if (!end) {
68 end = expected_status 68 end = expectedStatus
69 expected_status = 200 69 expectedStatus = 200
70 } 70 }
71 71
72 const path = '/api/v1/users/token' 72 const path = '/api/v1/users/token'
@@ -85,7 +85,7 @@ function login (url, client, user, expected_status, end) {
85 .post(path) 85 .post(path)
86 .type('form') 86 .type('form')
87 .send(body) 87 .send(body)
88 .expect(expected_status) 88 .expect(expectedStatus)
89 .end(end) 89 .end(end)
90} 90}
91 91
@@ -97,10 +97,10 @@ function loginAndGetAccessToken (server, callback) {
97 }) 97 })
98} 98}
99 99
100function makeFriends (url, expected_status, callback) { 100function makeFriends (url, expectedStatus, callback) {
101 if (!callback) { 101 if (!callback) {
102 callback = expected_status 102 callback = expectedStatus
103 expected_status = 204 103 expectedStatus = 204
104 } 104 }
105 105
106 const path = '/api/v1/pods/makefriends' 106 const path = '/api/v1/pods/makefriends'
@@ -109,7 +109,7 @@ function makeFriends (url, expected_status, callback) {
109 request(url) 109 request(url)
110 .get(path) 110 .get(path)
111 .set('Accept', 'application/json') 111 .set('Accept', 'application/json')
112 .expect(expected_status) 112 .expect(expectedStatus)
113 .end(function (err, res) { 113 .end(function (err, res) {
114 if (err) throw err 114 if (err) throw err
115 115
@@ -134,10 +134,10 @@ function quitFriends (url, callback) {
134 }) 134 })
135} 135}
136 136
137function removeVideo (url, token, id, expected_status, end) { 137function removeVideo (url, token, id, expectedStatus, end) {
138 if (!end) { 138 if (!end) {
139 end = expected_status 139 end = expectedStatus
140 expected_status = 204 140 expectedStatus = 204
141 } 141 }
142 142
143 const path = '/api/v1/videos' 143 const path = '/api/v1/videos'
@@ -146,11 +146,11 @@ function removeVideo (url, token, id, expected_status, end) {
146 .delete(path + '/' + id) 146 .delete(path + '/' + id)
147 .set('Accept', 'application/json') 147 .set('Accept', 'application/json')
148 .set('Authorization', 'Bearer ' + token) 148 .set('Authorization', 'Bearer ' + token)
149 .expect(expected_status) 149 .expect(expectedStatus)
150 .end(end) 150 .end(end)
151} 151}
152 152
153function flushAndRunMultipleServers (total_servers, serversRun) { 153function flushAndRunMultipleServers (totalServers, serversRun) {
154 let apps = [] 154 let apps = []
155 let urls = [] 155 let urls = []
156 let i = 0 156 let i = 0
@@ -159,13 +159,13 @@ function flushAndRunMultipleServers (total_servers, serversRun) {
159 apps[number - 1] = app 159 apps[number - 1] = app
160 urls[number - 1] = url 160 urls[number - 1] = url
161 i++ 161 i++
162 if (i === total_servers) { 162 if (i === totalServers) {
163 serversRun(apps, urls) 163 serversRun(apps, urls)
164 } 164 }
165 } 165 }
166 166
167 flushTests(function () { 167 flushTests(function () {
168 for (let j = 1; j <= total_servers; j++) { 168 for (let j = 1; j <= totalServers; j++) {
169 // For the virtual buffer 169 // For the virtual buffer
170 setTimeout(function () { 170 setTimeout(function () {
171 runServer(j, function (app, url) { 171 runServer(j, function (app, url) {
@@ -191,7 +191,7 @@ function runServer (number, callback) {
191 } 191 }
192 192
193 // These actions are async so we need to be sure that they have both been done 193 // These actions are async so we need to be sure that they have both been done
194 const server_run_string = { 194 const serverRunString = {
195 'Connected to mongodb': false, 195 'Connected to mongodb': false,
196 'Server listening on port': false 196 'Server listening on port': false
197 } 197 }
@@ -215,7 +215,7 @@ function runServer (number, callback) {
215 215
216 server.app = fork(pathUtils.join(__dirname, '../../../server.js'), [], options) 216 server.app = fork(pathUtils.join(__dirname, '../../../server.js'), [], options)
217 server.app.stdout.on('data', function onStdout (data) { 217 server.app.stdout.on('data', function onStdout (data) {
218 let dont_continue = false 218 let dontContinue = false
219 219
220 // Capture things if we want to 220 // Capture things if we want to
221 for (const key of Object.keys(regexps)) { 221 for (const key of Object.keys(regexps)) {
@@ -230,13 +230,13 @@ function runServer (number, callback) {
230 } 230 }
231 231
232 // Check if all required sentences are here 232 // Check if all required sentences are here
233 for (const key of Object.keys(server_run_string)) { 233 for (const key of Object.keys(serverRunString)) {
234 if (data.toString().indexOf(key) !== -1) server_run_string[key] = true 234 if (data.toString().indexOf(key) !== -1) serverRunString[key] = true
235 if (server_run_string[key] === false) dont_continue = true 235 if (serverRunString[key] === false) dontContinue = true
236 } 236 }
237 237
238 // If no, there is maybe one thing not already initialized (mongodb...) 238 // If no, there is maybe one thing not already initialized (mongodb...)
239 if (dont_continue === true) return 239 if (dontContinue === true) return
240 240
241 server.app.stdout.removeListener('data', onStdout) 241 server.app.stdout.removeListener('data', onStdout)
242 callback(server) 242 callback(server)
@@ -254,14 +254,14 @@ function searchVideo (url, search, end) {
254 .end(end) 254 .end(end)
255} 255}
256 256
257function testImage (url, video_name, image_path, callback) { 257function testImage (url, videoName, imagePath, callback) {
258 request(url) 258 request(url)
259 .get(image_path) 259 .get(imagePath)
260 .expect(200) 260 .expect(200)
261 .end(function (err, res) { 261 .end(function (err, res) {
262 if (err) return callback(err) 262 if (err) return callback(err)
263 263
264 fs.readFile(pathUtils.join(__dirname, 'fixtures', video_name + '.jpg'), function (err, data) { 264 fs.readFile(pathUtils.join(__dirname, 'fixtures', videoName + '.jpg'), function (err, data) {
265 if (err) return callback(err) 265 if (err) return callback(err)
266 266
267 callback(null, data.equals(res.body)) 267 callback(null, data.equals(res.body))
@@ -269,10 +269,10 @@ function testImage (url, video_name, image_path, callback) {
269 }) 269 })
270} 270}
271 271
272function uploadVideo (url, access_token, name, description, fixture, special_status, end) { 272function uploadVideo (url, accessToken, name, description, fixture, specialStatus, end) {
273 if (!end) { 273 if (!end) {
274 end = special_status 274 end = specialStatus
275 special_status = 204 275 specialStatus = 204
276 } 276 }
277 277
278 const path = '/api/v1/videos' 278 const path = '/api/v1/videos'
@@ -280,11 +280,11 @@ function uploadVideo (url, access_token, name, description, fixture, special_sta
280 request(url) 280 request(url)
281 .post(path) 281 .post(path)
282 .set('Accept', 'application/json') 282 .set('Accept', 'application/json')
283 .set('Authorization', 'Bearer ' + access_token) 283 .set('Authorization', 'Bearer ' + accessToken)
284 .field('name', name) 284 .field('name', name)
285 .field('description', description) 285 .field('description', description)
286 .attach('videofile', pathUtils.join(__dirname, 'fixtures', fixture)) 286 .attach('videofile', pathUtils.join(__dirname, 'fixtures', fixture))
287 .expect(special_status) 287 .expect(specialStatus)
288 .end(end) 288 .end(end)
289} 289}
290 290