aboutsummaryrefslogblamecommitdiffhomepage
path: root/routes/api/v1/remoteVideos.js
blob: 10793b2b4cf77f87a29c9b7f0d64c61b3a2828b6 (plain) (tree)
1
2
3
4
5
6
7
8
9




                                  
                                                  

                                                    
                                             


                                                           
                               






                                                                                         
                               




                     

                                                                                                                                                                 


                         
;(function () {
  'use strict'

  var express = require('express')
  var router = express.Router()
  var middleware = require('../../../middlewares')
  var miscMiddleware = middleware.misc
  var reqValidator = middleware.reqValidators.remote
  var videos = require('../../../src/videos')

  function addRemoteVideos (req, res, next) {
    videos.addRemote(req.body.data, function (err, video) {
      if (err) return next(err)

      res.json(video)
    })
  }

  function removeRemoteVideo (req, res, next) {
    videos.removeRemote(req.body.signature.url, req.body.data.magnetUri, function (err) {
      if (err) return next(err)

      res.status(204)
    })
  }

  router.post('/add', reqValidator.secureRequest, miscMiddleware.decryptBody, reqValidator.remoteVideosAdd, miscMiddleware.cache(false), addRemoteVideos)
  router.post('/remove', reqValidator.secureRequest, miscMiddleware.decryptBody, reqValidator.remoteVideosRemove, miscMiddleware.cache(false), removeRemoteVideo)

  module.exports = router
})()