diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-04 20:59:23 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-04 21:05:13 +0100 |
commit | 55fa55a9be566cca2ba95322f2ae23b434aed62a (patch) | |
tree | f51ef35c120ce8a928917a659418079538cdb8dc /server/controllers/api/videos.js | |
parent | a6fd2b30bf717eec14972a2175354781f5f43e77 (diff) | |
download | PeerTube-55fa55a9be566cca2ba95322f2ae23b434aed62a.tar.gz PeerTube-55fa55a9be566cca2ba95322f2ae23b434aed62a.tar.zst PeerTube-55fa55a9be566cca2ba95322f2ae23b434aed62a.zip |
Server: add video abuse support
Diffstat (limited to 'server/controllers/api/videos.js')
-rw-r--r-- | server/controllers/api/videos.js | 61 |
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') | |||
11 | const logger = require('../../helpers/logger') | 11 | const logger = require('../../helpers/logger') |
12 | const friends = require('../../lib/friends') | 12 | const friends = require('../../lib/friends') |
13 | const middlewares = require('../../middlewares') | 13 | const middlewares = require('../../middlewares') |
14 | const admin = middlewares.admin | ||
14 | const oAuth = middlewares.oauth | 15 | const oAuth = middlewares.oauth |
15 | const pagination = middlewares.pagination | 16 | const pagination = middlewares.pagination |
16 | const validators = middlewares.validators | 17 | const validators = middlewares.validators |
@@ -43,6 +44,21 @@ const storage = multer.diskStorage({ | |||
43 | 44 | ||
44 | const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) | 45 | const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) |
45 | 46 | ||
47 | router.get('/abuse', | ||
48 | oAuth.authenticate, | ||
49 | admin.ensureIsAdmin, | ||
50 | validatorsPagination.pagination, | ||
51 | validatorsSort.videoAbusesSort, | ||
52 | sort.setVideoAbusesSort, | ||
53 | pagination.setPagination, | ||
54 | listVideoAbuses | ||
55 | ) | ||
56 | router.post('/:id/abuse', | ||
57 | oAuth.authenticate, | ||
58 | validatorsVideos.videoAbuseReport, | ||
59 | reportVideoAbuse | ||
60 | ) | ||
61 | |||
46 | router.get('/', | 62 | router.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 | // --------------------------------------------------------------------------- | 330 | function listVideoAbuses (req, res, next) { |
315 | 331 | db.VideoAbuse.listForApi(req.query.start, req.query.count, req.query.sort, function (err, abusesList, abusesTotal) { | |
316 | function 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 { | 338 | function 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 | |||