1
0
Fork 0
peertube/server/controllers/api/v1/remoteVideos.js

54 lines
1.3 KiB
JavaScript
Raw Normal View History

'use strict'
2015-06-09 11:41:40 -04:00
2016-03-16 17:29:27 -04:00
const express = require('express')
2016-04-26 15:56:46 -04:00
const map = require('lodash/map')
2016-03-16 17:29:27 -04:00
const middleware = require('../../../middlewares')
const secureMiddleware = middleware.secure
const cacheMiddleware = middleware.cache
const reqValidator = middleware.reqValidators.remote
const videos = require('../../../models/videos')
2015-06-09 11:41:40 -04:00
2016-03-16 17:29:27 -04:00
const router = express.Router()
2016-01-31 05:23:52 -05:00
router.post('/add',
reqValidator.secureRequest,
secureMiddleware.decryptBody,
reqValidator.remoteVideosAdd,
cacheMiddleware.cache(false),
addRemoteVideos
)
2016-01-31 05:23:52 -05:00
router.post('/remove',
reqValidator.secureRequest,
secureMiddleware.decryptBody,
reqValidator.remoteVideosRemove,
cacheMiddleware.cache(false),
removeRemoteVideo
)
2016-01-31 05:23:52 -05:00
// ---------------------------------------------------------------------------
2016-01-31 05:23:52 -05:00
module.exports = router
2016-01-31 05:23:52 -05:00
// ---------------------------------------------------------------------------
2016-01-31 05:23:52 -05:00
function addRemoteVideos (req, res, next) {
videos.addRemotes(req.body.data, function (err, videos) {
if (err) return next(err)
2015-06-09 11:41:40 -04:00
res.json(videos)
})
}
2015-06-09 11:41:40 -04:00
function removeRemoteVideo (req, res, next) {
2016-03-16 17:29:27 -04:00
const url = req.body.signature.url
2016-03-18 11:34:50 -04:00
const magnetUris = map(req.body.data, 'magnetUri')
2016-02-04 15:10:33 -05:00
videos.removeRemotesOfByMagnetUris(url, magnetUris, function (err) {
if (err) return next(err)
2015-06-09 11:41:40 -04:00
2016-03-14 08:50:19 -04:00
res.type('json').status(204).end()
})
}