diff options
Diffstat (limited to 'server/controllers/api/v1/pods.js')
-rw-r--r-- | server/controllers/api/v1/pods.js | 27 |
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 | ||
3 | const express = require('express') | 3 | const express = require('express') |
4 | const fs = require('fs') | ||
5 | 4 | ||
6 | const logger = require('../../../helpers/logger') | 5 | const logger = require('../../../helpers/logger') |
7 | const friends = require('../../../lib/friends') | 6 | const friends = require('../../../lib/friends') |
8 | const middleware = require('../../../middlewares') | 7 | const middleware = require('../../../middlewares') |
9 | const cacheMiddleware = middleware.cache | 8 | const cacheMiddleware = middleware.cache |
10 | const peertubeCrypto = require('../../../helpers/peertubeCrypto') | ||
11 | const Pods = require('../../../models/pods') | 9 | const Pods = require('../../../models/pods') |
12 | const reqValidator = middleware.reqValidators.pods | 10 | const reqValidator = middleware.reqValidators.pods |
13 | const secureMiddleware = middleware.secure | 11 | const secureMiddleware = middleware.secure |
14 | const secureRequest = middleware.reqValidators.remote.secureRequest | 12 | const secureRequest = middleware.reqValidators.remote.secureRequest |
13 | const videos = require('../../../lib/videos') | ||
15 | const Videos = require('../../../models/videos') | 14 | const Videos = require('../../../models/videos') |
16 | 15 | ||
17 | const router = express.Router() | 16 | const 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 | } |