diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-12 15:20:03 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-12 15:20:03 +0100 |
commit | 99fe265a5fc077cb66c322e7f3d191ff7110aea0 (patch) | |
tree | c9e04ccfcc5496d2300d7c26db5833e494b4cdad /server/controllers/api/remote.js | |
parent | fcc5f77b95d330bfcb439c172b7fcc58f3162e4d (diff) | |
parent | 91cc839af88730ba55f84997c56b85ea100070a7 (diff) | |
download | PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.tar.gz PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.tar.zst PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.zip |
Merge branch 'postgresql'
Diffstat (limited to 'server/controllers/api/remote.js')
-rw-r--r-- | server/controllers/api/remote.js | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/server/controllers/api/remote.js b/server/controllers/api/remote.js deleted file mode 100644 index f1046c534..000000000 --- a/server/controllers/api/remote.js +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const each = require('async/each') | ||
4 | const eachSeries = require('async/eachSeries') | ||
5 | const express = require('express') | ||
6 | const mongoose = require('mongoose') | ||
7 | |||
8 | const middlewares = require('../../middlewares') | ||
9 | const secureMiddleware = middlewares.secure | ||
10 | const validators = middlewares.validators.remote | ||
11 | const logger = require('../../helpers/logger') | ||
12 | |||
13 | const router = express.Router() | ||
14 | const Video = mongoose.model('Video') | ||
15 | |||
16 | router.post('/videos', | ||
17 | validators.signature, | ||
18 | secureMiddleware.checkSignature, | ||
19 | validators.remoteVideos, | ||
20 | remoteVideos | ||
21 | ) | ||
22 | |||
23 | // --------------------------------------------------------------------------- | ||
24 | |||
25 | module.exports = router | ||
26 | |||
27 | // --------------------------------------------------------------------------- | ||
28 | |||
29 | function remoteVideos (req, res, next) { | ||
30 | const requests = req.body.data | ||
31 | const fromHost = req.body.signature.host | ||
32 | |||
33 | // We need to process in the same order to keep consistency | ||
34 | // TODO: optimization | ||
35 | eachSeries(requests, function (request, callbackEach) { | ||
36 | const videoData = request.data | ||
37 | |||
38 | if (request.type === 'add') { | ||
39 | addRemoteVideo(videoData, fromHost, callbackEach) | ||
40 | } else if (request.type === 'remove') { | ||
41 | removeRemoteVideo(videoData, fromHost, callbackEach) | ||
42 | } else { | ||
43 | logger.error('Unkown remote request type %s.', request.type) | ||
44 | } | ||
45 | }, function (err) { | ||
46 | if (err) logger.error('Error managing remote videos.', { error: err }) | ||
47 | }) | ||
48 | |||
49 | // We don't need to keep the other pod waiting | ||
50 | return res.type('json').status(204).end() | ||
51 | } | ||
52 | |||
53 | function addRemoteVideo (videoToCreateData, fromHost, callback) { | ||
54 | logger.debug('Adding remote video "%s".', videoToCreateData.name) | ||
55 | |||
56 | const video = new Video(videoToCreateData) | ||
57 | video.podHost = fromHost | ||
58 | Video.generateThumbnailFromBase64(video, videoToCreateData.thumbnailBase64, function (err) { | ||
59 | if (err) { | ||
60 | logger.error('Cannot generate thumbnail from base 64 data.', { error: err }) | ||
61 | return callback(err) | ||
62 | } | ||
63 | |||
64 | video.save(callback) | ||
65 | }) | ||
66 | } | ||
67 | |||
68 | function removeRemoteVideo (videoToRemoveData, fromHost, callback) { | ||
69 | // We need the list because we have to remove some other stuffs (thumbnail etc) | ||
70 | Video.listByHostAndRemoteId(fromHost, videoToRemoveData.remoteId, function (err, videosList) { | ||
71 | if (err) { | ||
72 | logger.error('Cannot list videos from host and magnets.', { error: err }) | ||
73 | return callback(err) | ||
74 | } | ||
75 | |||
76 | if (videosList.length === 0) { | ||
77 | logger.error('No remote video was found for this pod.', { magnetUri: videoToRemoveData.magnetUri, podHost: fromHost }) | ||
78 | } | ||
79 | |||
80 | each(videosList, function (video, callbackEach) { | ||
81 | logger.debug('Removing remote video %s.', video.magnetUri) | ||
82 | |||
83 | video.remove(callbackEach) | ||
84 | }, callback) | ||
85 | }) | ||
86 | } | ||