]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/v1/remoteVideos.js
Generate passwords at initialization (client/admin passwords)
[github/Chocobozzz/PeerTube.git] / server / controllers / api / v1 / remoteVideos.js
CommitLineData
9f10b292 1'use strict'
8c308c2b 2
f0f5567b 3const express = require('express')
a4c15751 4const map = require('lodash-node/modern/collection/map')
0b697522 5
f0f5567b
C
6const middleware = require('../../../middlewares')
7const secureMiddleware = middleware.secure
8const cacheMiddleware = middleware.cache
9const reqValidator = middleware.reqValidators.remote
10const videos = require('../../../models/videos')
8c308c2b 11
f0f5567b 12const router = express.Router()
c45f7f84 13
9f10b292
C
14router.post('/add',
15 reqValidator.secureRequest,
16 secureMiddleware.decryptBody,
17 reqValidator.remoteVideosAdd,
18 cacheMiddleware.cache(false),
19 addRemoteVideos
20)
c45f7f84 21
9f10b292
C
22router.post('/remove',
23 reqValidator.secureRequest,
24 secureMiddleware.decryptBody,
25 reqValidator.remoteVideosRemove,
26 cacheMiddleware.cache(false),
27 removeRemoteVideo
28)
c45f7f84 29
9f10b292 30// ---------------------------------------------------------------------------
c45f7f84 31
9f10b292 32module.exports = router
c45f7f84 33
9f10b292 34// ---------------------------------------------------------------------------
c45f7f84 35
9f10b292
C
36function addRemoteVideos (req, res, next) {
37 videos.addRemotes(req.body.data, function (err, videos) {
38 if (err) return next(err)
8c308c2b 39
9f10b292
C
40 res.json(videos)
41 })
42}
8c308c2b 43
9f10b292 44function removeRemoteVideo (req, res, next) {
f0f5567b 45 const url = req.body.signature.url
a4c15751 46 const magnetUris = map(req.body.data, 'magnetUri')
c173e565 47
9f10b292
C
48 videos.removeRemotesOfByMagnetUris(url, magnetUris, function (err) {
49 if (err) return next(err)
8c308c2b 50
dc8bc31b 51 res.type('json').status(204).end()
9f10b292
C
52 })
53}