diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-27 12:05:19 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-27 12:14:53 +0100 |
commit | cddadde81f91219204cec1f4057a191c02a70894 (patch) | |
tree | 06f984ffe21628f6a02f8706a2781e8b6cce2dc7 | |
parent | b09ce6455f8e2bf9dd741532e6ad09309880ff74 (diff) | |
download | PeerTube-cddadde81f91219204cec1f4057a191c02a70894.tar.gz PeerTube-cddadde81f91219204cec1f4057a191c02a70894.tar.zst PeerTube-cddadde81f91219204cec1f4057a191c02a70894.zip |
Server: assert remoteId and host pair is unique
-rw-r--r-- | server/controllers/api/remote/videos.js | 10 | ||||
-rw-r--r-- | server/tests/api/check-params/remotes.js | 2 |
2 files changed, 12 insertions, 0 deletions
diff --git a/server/controllers/api/remote/videos.js b/server/controllers/api/remote/videos.js index 83d9b98bf..f8b4949cd 100644 --- a/server/controllers/api/remote/videos.js +++ b/server/controllers/api/remote/videos.js | |||
@@ -79,6 +79,16 @@ function addRemoteVideo (videoToCreateData, fromPod, finalCallback) { | |||
79 | 79 | ||
80 | databaseUtils.startSerializableTransaction, | 80 | databaseUtils.startSerializableTransaction, |
81 | 81 | ||
82 | function assertRemoteIdAndHostUnique (t, callback) { | ||
83 | db.Video.loadByHostAndRemoteId(fromPod.host, videoToCreateData.remoteId, function (err, video) { | ||
84 | if (err) return callback(err) | ||
85 | |||
86 | if (video) return callback(new Error('RemoteId and host pair is not unique.')) | ||
87 | |||
88 | return callback(null, t) | ||
89 | }) | ||
90 | }, | ||
91 | |||
82 | function findOrCreateAuthor (t, callback) { | 92 | function findOrCreateAuthor (t, callback) { |
83 | const name = videoToCreateData.author | 93 | const name = videoToCreateData.author |
84 | const podId = fromPod.id | 94 | const podId = fromPod.id |
diff --git a/server/tests/api/check-params/remotes.js b/server/tests/api/check-params/remotes.js index c1ab9fb2b..f6a49d6e2 100644 --- a/server/tests/api/check-params/remotes.js +++ b/server/tests/api/check-params/remotes.js | |||
@@ -41,6 +41,8 @@ describe('Test remote videos API validators', function () { | |||
41 | 41 | ||
42 | describe('When adding a video', function () { | 42 | describe('When adding a video', function () { |
43 | it('Should check when adding a video') | 43 | it('Should check when adding a video') |
44 | |||
45 | it('Should not add an existing remoteId and host pair') | ||
44 | }) | 46 | }) |
45 | 47 | ||
46 | describe('When removing a video', function () { | 48 | describe('When removing a video', function () { |