aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers')
-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
4 files changed, 58 insertions, 58 deletions
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