aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/v1/pods.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/v1/pods.js')
-rw-r--r--server/controllers/api/v1/pods.js27
1 files changed, 19 insertions, 8 deletions
diff --git a/server/controllers/api/v1/pods.js b/server/controllers/api/v1/pods.js
index dbe1a7372..d08b7860d 100644
--- a/server/controllers/api/v1/pods.js
+++ b/server/controllers/api/v1/pods.js
@@ -1,17 +1,16 @@
1'use strict' 1'use strict'
2 2
3const express = require('express') 3const express = require('express')
4const fs = require('fs')
5 4
6const logger = require('../../../helpers/logger') 5const logger = require('../../../helpers/logger')
7const friends = require('../../../lib/friends') 6const friends = require('../../../lib/friends')
8const middleware = require('../../../middlewares') 7const middleware = require('../../../middlewares')
9const cacheMiddleware = middleware.cache 8const cacheMiddleware = middleware.cache
10const peertubeCrypto = require('../../../helpers/peertubeCrypto')
11const Pods = require('../../../models/pods') 9const Pods = require('../../../models/pods')
12const reqValidator = middleware.reqValidators.pods 10const reqValidator = middleware.reqValidators.pods
13const secureMiddleware = middleware.secure 11const secureMiddleware = middleware.secure
14const secureRequest = middleware.reqValidators.remote.secureRequest 12const secureRequest = middleware.reqValidators.remote.secureRequest
13const videos = require('../../../lib/videos')
15const Videos = require('../../../models/videos') 14const Videos = require('../../../models/videos')
16 15
17const router = express.Router() 16const router = express.Router()
@@ -34,9 +33,12 @@ function addPods (req, res, next) {
34 Pods.add(informations, function (err) { 33 Pods.add(informations, function (err) {
35 if (err) return next(err) 34 if (err) return next(err)
36 35
37 Videos.addRemotes(informations.videos) 36 // Create the remote videos from the new pod
37 videos.createRemoteVideos(informations.videos, function (err) {
38 if (err) logger.error('Cannot create remote videos.', { error: err })
39 })
38 40
39 fs.readFile(peertubeCrypto.getCertDir() + 'peertube.pub', 'utf8', function (err, cert) { 41 friends.getMyCertificate(function (err, cert) {
40 if (err) { 42 if (err) {
41 logger.error('Cannot read cert file.') 43 logger.error('Cannot read cert file.')
42 return next(err) 44 return next(err)
@@ -75,11 +77,20 @@ function removePods (req, res, next) {
75 Pods.remove(url, function (err) { 77 Pods.remove(url, function (err) {
76 if (err) return next(err) 78 if (err) return next(err)
77 79
78 Videos.removeAllRemotesOf(url, function (err) { 80 Videos.listFromUrl(url, function (err, videos_list) {
79 if (err) logger.error('Cannot remove all remote videos of %s.', url) 81 if (err) {
80 else logger.info('%s pod removed.', url) 82 logger.error('Cannot list videos from url.', { error: err })
83 next(err)
84 }
81 85
82 res.type('json').status(204).end() 86 videos.removeRemoteVideos(videos_list, function (err) {
87 if (err) {
88 logger.error('Cannot remove remote videos.', { error: err })
89 next(err)
90 }
91
92 res.type('json').status(204).end()
93 })
83 }) 94 })
84 }) 95 })
85} 96}