From cddadde81f91219204cec1f4057a191c02a70894 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 27 Jan 2017 12:05:19 +0100 Subject: Server: assert remoteId and host pair is unique --- server/controllers/api/remote/videos.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'server/controllers') 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 -- cgit v1.2.3