]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/controllers/api/v1/pods.js
3 const each
= require('async/each')
4 const express
= require('express')
5 const mongoose
= require('mongoose')
6 const waterfall
= require('async/waterfall')
8 const logger
= require('../../../helpers/logger')
9 const friends
= require('../../../lib/friends')
10 const middlewares
= require('../../../middlewares')
11 const oAuth
= middlewares
.oauth
12 const validators
= middlewares
.validators
.pods
13 const signatureValidator
= middlewares
.validators
.remote
.signature
15 const router
= express
.Router()
16 const Pod
= mongoose
.model('Pod')
17 const Video
= mongoose
.model('Video')
19 router
.get('/', listPodsUrl
)
20 router
.post('/', validators
.podsAdd
, addPods
)
21 router
.get('/makefriends', oAuth
.authenticate
, validators
.makeFriends
, makeFriends
)
22 router
.get('/quitfriends', oAuth
.authenticate
, quitFriends
)
23 // Post because this is a secured request
24 router
.post('/remove', signatureValidator
, removePods
)
26 // ---------------------------------------------------------------------------
28 module
.exports
= router
30 // ---------------------------------------------------------------------------
32 function addPods (req
, res
, next
) {
33 const informations
= req
.body
36 function addPod (callback
) {
37 const pod
= new Pod(informations
)
38 pod
.save(function (err
, podCreated
) {
39 // Be sure about the number of parameters for the callback
40 return callback(err
, podCreated
)
44 function sendMyVideos (podCreated
, callback
) {
45 friends
.sendOwnedVideosToPod(podCreated
._id
)
50 function fetchMyCertificate (callback
) {
51 friends
.getMyCertificate(function (err
, cert
) {
53 logger
.error('Cannot read cert file.')
57 return callback(null, cert
)
60 ], function (err
, cert
) {
61 if (err
) return next(err
)
63 return res
.json({ cert: cert
})
67 function listPodsUrl (req
, res
, next
) {
68 Pod
.listOnlyUrls(function (err
, podsUrlList
) {
69 if (err
) return next(err
)
75 function makeFriends (req
, res
, next
) {
76 friends
.makeFriends(function (err
) {
77 if (err
) return next(err
)
79 res
.type('json').status(204).end()
83 function removePods (req
, res
, next
) {
84 const url
= req
.body
.signature
.url
87 function loadPod (callback
) {
88 Pod
.loadByUrl(url
, callback
)
91 function removePod (pod
, callback
) {
92 pod
.remove(function (err
) {
93 // Be sure we only return one argument in the callback
99 Video
.listByUrls([ url
], function (err
, videosList
) {
101 logger
.error('Cannot list videos from url.', { error: err
})
105 return callback(null, videosList
)
109 function removeTheRemoteVideos (videosList
, callback
) {
110 each(videosList
, function (video
, callbackEach
) {
111 video
.remove(callbackEach
)
115 if (err
) return next(err
)
117 return res
.type('json').status(204).end()
121 function quitFriends (req
, res
, next
) {
122 friends
.quitFriends(function (err
) {
123 if (err
) return next(err
)
125 res
.type('json').status(204).end()