From: Chocobozzz Date: Fri, 27 Jan 2017 11:05:19 +0000 (+0100) Subject: Server: assert remoteId and host pair is unique X-Git-Tag: v0.0.1-alpha~541 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=cddadde81f91219204cec1f4057a191c02a70894;p=oweals%2Fpeertube.git Server: assert remoteId and host pair is unique --- 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) { databaseUtils.startSerializableTransaction, + function assertRemoteIdAndHostUnique (t, callback) { + db.Video.loadByHostAndRemoteId(fromPod.host, videoToCreateData.remoteId, function (err, video) { + if (err) return callback(err) + + if (video) return callback(new Error('RemoteId and host pair is not unique.')) + + return callback(null, t) + }) + }, + function findOrCreateAuthor (t, callback) { const name = videoToCreateData.author 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 () { describe('When adding a video', function () { it('Should check when adding a video') + + it('Should not add an existing remoteId and host pair') }) describe('When removing a video', function () {