aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos.js')
-rw-r--r--server/controllers/api/videos.js61
1 files changed, 50 insertions, 11 deletions
diff --git a/server/controllers/api/videos.js b/server/controllers/api/videos.js
index 35d6979e5..6829804ec 100644
--- a/server/controllers/api/videos.js
+++ b/server/controllers/api/videos.js
@@ -11,6 +11,7 @@ const db = require('../../initializers/database')
11const logger = require('../../helpers/logger') 11const logger = require('../../helpers/logger')
12const friends = require('../../lib/friends') 12const friends = require('../../lib/friends')
13const middlewares = require('../../middlewares') 13const middlewares = require('../../middlewares')
14const admin = middlewares.admin
14const oAuth = middlewares.oauth 15const oAuth = middlewares.oauth
15const pagination = middlewares.pagination 16const pagination = middlewares.pagination
16const validators = middlewares.validators 17const validators = middlewares.validators
@@ -43,6 +44,21 @@ const storage = multer.diskStorage({
43 44
44const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) 45const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }])
45 46
47router.get('/abuse',
48 oAuth.authenticate,
49 admin.ensureIsAdmin,
50 validatorsPagination.pagination,
51 validatorsSort.videoAbusesSort,
52 sort.setVideoAbusesSort,
53 pagination.setPagination,
54 listVideoAbuses
55)
56router.post('/:id/abuse',
57 oAuth.authenticate,
58 validatorsVideos.videoAbuseReport,
59 reportVideoAbuse
60)
61
46router.get('/', 62router.get('/',
47 validatorsPagination.pagination, 63 validatorsPagination.pagination,
48 validatorsSort.videosSort, 64 validatorsSort.videosSort,
@@ -283,7 +299,7 @@ function listVideos (req, res, next) {
283 db.Video.listForApi(req.query.start, req.query.count, req.query.sort, function (err, videosList, videosTotal) { 299 db.Video.listForApi(req.query.start, req.query.count, req.query.sort, function (err, videosList, videosTotal) {
284 if (err) return next(err) 300 if (err) return next(err)
285 301
286 res.json(getFormatedVideos(videosList, videosTotal)) 302 res.json(utils.getFormatedObjects(videosList, videosTotal))
287 }) 303 })
288} 304}
289 305
@@ -306,22 +322,45 @@ function searchVideos (req, res, next) {
306 function (err, videosList, videosTotal) { 322 function (err, videosList, videosTotal) {
307 if (err) return next(err) 323 if (err) return next(err)
308 324
309 res.json(getFormatedVideos(videosList, videosTotal)) 325 res.json(utils.getFormatedObjects(videosList, videosTotal))
310 } 326 }
311 ) 327 )
312} 328}
313 329
314// --------------------------------------------------------------------------- 330function listVideoAbuses (req, res, next) {
315 331 db.VideoAbuse.listForApi(req.query.start, req.query.count, req.query.sort, function (err, abusesList, abusesTotal) {
316function getFormatedVideos (videos, videosTotal) { 332 if (err) return next(err)
317 const formatedVideos = []
318 333
319 videos.forEach(function (video) { 334 res.json(utils.getFormatedObjects(abusesList, abusesTotal))
320 formatedVideos.push(video.toFormatedJSON())
321 }) 335 })
336}
322 337
323 return { 338function reportVideoAbuse (req, res, next) {
324 total: videosTotal, 339 const videoInstance = res.locals.video
325 data: formatedVideos 340 const reporterUsername = res.locals.oauth.token.User.username
341
342 const abuse = {
343 reporterUsername,
344 reason: req.body.reason,
345 videoId: videoInstance.id,
346 reporterPodId: null // This is our pod that reported this abuse
326 } 347 }
348
349 db.VideoAbuse.create(abuse).asCallback(function (err) {
350 if (err) return next(err)
351
352 // We send the information to the destination pod
353 if (videoInstance.isOwned() === false) {
354 const reportData = {
355 reporterUsername,
356 reportReason: abuse.reason,
357 videoRemoteId: videoInstance.remoteId
358 }
359
360 friends.reportAbuseVideoToFriend(reportData, videoInstance)
361 }
362
363 return res.type('json').status(204).end()
364 })
327} 365}
366