diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-07-05 21:36:01 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-07-05 21:36:01 +0200 |
commit | 6666aad4599a78f98f39409ec0d45391da7bd2d0 (patch) | |
tree | 2935754fb62522b085ffb41af2592b7a9a56e5ac /server | |
parent | 0890478c5c259bb787dc7f847e38be081df7c8e1 (diff) | |
download | PeerTube-6666aad4599a78f98f39409ec0d45391da7bd2d0.tar.gz PeerTube-6666aad4599a78f98f39409ec0d45391da7bd2d0.tar.zst PeerTube-6666aad4599a78f98f39409ec0d45391da7bd2d0.zip |
Fix requests ordering between pods
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/v1/remote.js | 10 | ||||
-rw-r--r-- | server/models/request.js | 2 | ||||
-rw-r--r-- | server/tests/api/utils.js | 15 |
3 files changed, 26 insertions, 1 deletions
diff --git a/server/controllers/api/v1/remote.js b/server/controllers/api/v1/remote.js index 7af9b7e84..9c2ca86e0 100644 --- a/server/controllers/api/v1/remote.js +++ b/server/controllers/api/v1/remote.js | |||
@@ -39,6 +39,8 @@ function remoteVideos (req, res, next) { | |||
39 | addRemoteVideo(videoData, callbackEach) | 39 | addRemoteVideo(videoData, callbackEach) |
40 | } else if (request.type === 'remove') { | 40 | } else if (request.type === 'remove') { |
41 | removeRemoteVideo(videoData, fromUrl, callbackEach) | 41 | removeRemoteVideo(videoData, fromUrl, callbackEach) |
42 | } else { | ||
43 | logger.error('Unkown remote request type %s.', request.type) | ||
42 | } | 44 | } |
43 | }, function (err) { | 45 | }, function (err) { |
44 | if (err) logger.error('Error managing remote videos.', { error: err }) | 46 | if (err) logger.error('Error managing remote videos.', { error: err }) |
@@ -49,6 +51,8 @@ function remoteVideos (req, res, next) { | |||
49 | } | 51 | } |
50 | 52 | ||
51 | function addRemoteVideo (videoToCreateData, callback) { | 53 | function addRemoteVideo (videoToCreateData, callback) { |
54 | logger.debug('Adding remote video %s.', videoToCreateData.magnetUri) | ||
55 | |||
52 | // Mongoose pre hook will automatically create the thumbnail on disk | 56 | // Mongoose pre hook will automatically create the thumbnail on disk |
53 | videoToCreateData.thumbnail = videoToCreateData.thumbnailBase64 | 57 | videoToCreateData.thumbnail = videoToCreateData.thumbnailBase64 |
54 | 58 | ||
@@ -64,7 +68,13 @@ function removeRemoteVideo (videoToRemoveData, fromUrl, callback) { | |||
64 | return callback(err) | 68 | return callback(err) |
65 | } | 69 | } |
66 | 70 | ||
71 | if (videosList.length === 0) { | ||
72 | logger.error('No remote video was found for this pod.', { magnetUri: videoToRemoveData.magnetUri, podUrl: fromUrl }) | ||
73 | } | ||
74 | |||
67 | async.each(videosList, function (video, callbackEach) { | 75 | async.each(videosList, function (video, callbackEach) { |
76 | logger.debug('Removing remote video %s.', video.magnetUri) | ||
77 | |||
68 | video.remove(callbackEach) | 78 | video.remove(callbackEach) |
69 | }, callback) | 79 | }, callback) |
70 | }) | 80 | }) |
diff --git a/server/models/request.js b/server/models/request.js index db6ad5409..7fdf5bd31 100644 --- a/server/models/request.js +++ b/server/models/request.js | |||
@@ -270,7 +270,7 @@ function updatePodsScore (goodPods, badPods) { | |||
270 | } | 270 | } |
271 | 271 | ||
272 | function list (callback) { | 272 | function list (callback) { |
273 | this.find({ }, { _id: 1, request: 1, to: 1 }, callback) | 273 | this.find({ }, { _id: 1, request: 1, to: 1 }).sort({ _id: 1 }).exec(callback) |
274 | } | 274 | } |
275 | 275 | ||
276 | function removeAll (callback) { | 276 | function removeAll (callback) { |
diff --git a/server/tests/api/utils.js b/server/tests/api/utils.js index e0068eada..7c8698a0a 100644 --- a/server/tests/api/utils.js +++ b/server/tests/api/utils.js | |||
@@ -10,6 +10,7 @@ const request = require('supertest') | |||
10 | const testUtils = { | 10 | const testUtils = { |
11 | dateIsValid: dateIsValid, | 11 | dateIsValid: dateIsValid, |
12 | flushTests: flushTests, | 12 | flushTests: flushTests, |
13 | getAllVideosListBy: getAllVideosListBy, | ||
13 | getFriendsList: getFriendsList, | 14 | getFriendsList: getFriendsList, |
14 | getVideo: getVideo, | 15 | getVideo: getVideo, |
15 | getVideosList: getVideosList, | 16 | getVideosList: getVideosList, |
@@ -45,6 +46,20 @@ function flushTests (callback) { | |||
45 | exec('npm run clean:server:test', callback) | 46 | exec('npm run clean:server:test', callback) |
46 | } | 47 | } |
47 | 48 | ||
49 | function getAllVideosListBy (url, end) { | ||
50 | const path = '/api/v1/videos' | ||
51 | |||
52 | request(url) | ||
53 | .get(path) | ||
54 | .query({ sort: 'createdDate' }) | ||
55 | .query({ start: 0 }) | ||
56 | .query({ count: 10000 }) | ||
57 | .set('Accept', 'application/json') | ||
58 | .expect(200) | ||
59 | .expect('Content-Type', /json/) | ||
60 | .end(end) | ||
61 | } | ||
62 | |||
48 | function getFriendsList (url, end) { | 63 | function getFriendsList (url, end) { |
49 | const path = '/api/v1/pods/' | 64 | const path = '/api/v1/pods/' |
50 | 65 | ||