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