PeerTube/server/controllers/api/v1/remoteVideos.js

54 lines
1.3 KiB
JavaScript
Raw Normal View History

'use strict'
2015-06-09 10:41:40 -05:00
2016-03-16 16:29:27 -05:00
const express = require('express')
2016-03-18 10:34:50 -05:00
const map = require('lodash-node/modern/collection/map')
2016-03-16 16:29:27 -05: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 10:41:40 -05:00
2016-03-16 16:29:27 -05:00
const router = express.Router()
2016-01-31 04:23:52 -06:00
router.post('/add',
reqValidator.secureRequest,
secureMiddleware.decryptBody,
reqValidator.remoteVideosAdd,
cacheMiddleware.cache(false),
addRemoteVideos
)
2016-01-31 04:23:52 -06:00
router.post('/remove',
reqValidator.secureRequest,
secureMiddleware.decryptBody,
reqValidator.remoteVideosRemove,
cacheMiddleware.cache(false),
removeRemoteVideo
)
2016-01-31 04:23:52 -06:00
// ---------------------------------------------------------------------------
2016-01-31 04:23:52 -06:00
module.exports = router
2016-01-31 04:23:52 -06:00
// ---------------------------------------------------------------------------
2016-01-31 04:23:52 -06:00
function addRemoteVideos (req, res, next) {
videos.addRemotes(req.body.data, function (err, videos) {
if (err) return next(err)
2015-06-09 10:41:40 -05:00
res.json(videos)
})
}
2015-06-09 10:41:40 -05:00
function removeRemoteVideo (req, res, next) {
2016-03-16 16:29:27 -05:00
const url = req.body.signature.url
2016-03-18 10:34:50 -05:00
const magnetUris = map(req.body.data, 'magnetUri')
2016-02-04 14:10:33 -06:00
videos.removeRemotesOfByMagnetUris(url, magnetUris, function (err) {
if (err) return next(err)
2015-06-09 10:41:40 -05:00
2016-03-14 07:50:19 -05:00
res.type('json').status(204).end()
})
}