aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-03-18 16:28:09 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-03-18 16:28:09 +0100
commit2df82d42cb57783cd90ccfc11fc8ffe4b95ebb70 (patch)
tree9c177f135a121ee34ed2e4f529dd2cacc3ad3f87 /server/controllers
parentf0f5567b6918fc60c8cab15e13aec03a89a91dfb (diff)
downloadPeerTube-2df82d42cb57783cd90ccfc11fc8ffe4b95ebb70.tar.gz
PeerTube-2df82d42cb57783cd90ccfc11fc8ffe4b95ebb70.tar.zst
PeerTube-2df82d42cb57783cd90ccfc11fc8ffe4b95ebb70.zip
Change api output for videos
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/v1/videos.js36
1 files changed, 30 insertions, 6 deletions
diff --git a/server/controllers/api/v1/videos.js b/server/controllers/api/v1/videos.js
index 1eea417d4..4384724c1 100644
--- a/server/controllers/api/v1/videos.js
+++ b/server/controllers/api/v1/videos.js
@@ -83,14 +83,15 @@ function addVideo (req, res, next) {
83} 83}
84 84
85function getVideos (req, res, next) { 85function getVideos (req, res, next) {
86 Videos.get(req.params.id, function (err, video) { 86 Videos.get(req.params.id, function (err, video_obj) {
87 if (err) return next(err) 87 if (err) return next(err)
88 88
89 if (video === null) { 89 const state = videos.getVideoState(video_obj)
90 res.type('json').status(204).end() 90 if (state.exist === false) {
91 return res.type('json').status(204).end()
91 } 92 }
92 93
93 res.json(video) 94 res.json(getFormatedVideo(video_obj))
94 }) 95 })
95} 96}
96 97
@@ -98,7 +99,7 @@ function listVideos (req, res, next) {
98 Videos.list(function (err, videos_list) { 99 Videos.list(function (err, videos_list) {
99 if (err) return next(err) 100 if (err) return next(err)
100 101
101 res.json(videos_list) 102 res.json(getFormatedVideos(videos_list))
102 }) 103 })
103} 104}
104 105
@@ -127,12 +128,35 @@ function searchVideos (req, res, next) {
127 Videos.search(req.params.name, function (err, videos_list) { 128 Videos.search(req.params.name, function (err, videos_list) {
128 if (err) return next(err) 129 if (err) return next(err)
129 130
130 res.json(videos_list) 131 res.json(getFormatedVideos(videos_list))
131 }) 132 })
132} 133}
133 134
134// --------------------------------------------------------------------------- 135// ---------------------------------------------------------------------------
135 136
137function getFormatedVideo (video_obj) {
138 const formated_video = {
139 id: video_obj._id,
140 name: video_obj.name,
141 description: video_obj.description,
142 podUrl: video_obj.podUrl,
143 isLocal: videos.getVideoState(video_obj).owned,
144 magnetUri: video_obj.magnetUri
145 }
146
147 return formated_video
148}
149
150function getFormatedVideos (videos_obj) {
151 const formated_videos = []
152
153 videos_obj.forEach(function (video_obj) {
154 formated_videos.push(getFormatedVideo(video_obj))
155 })
156
157 return formated_videos
158}
159
136// Maybe the torrent is not seeded, but we catch the error to don't stop the removing process 160// Maybe the torrent is not seeded, but we catch the error to don't stop the removing process
137function removeTorrent (magnetUri, callback) { 161function removeTorrent (magnetUri, callback) {
138 try { 162 try {