From 5fb2e2888ce032c638e4b75d07458642f0833e52 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 29 May 2020 16:16:24 +0200 Subject: First implem global search --- server/lib/activitypub/videos.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'server/lib/activitypub') diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index 7d16bd390..6d20e0e65 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts @@ -272,11 +272,22 @@ async function getOrCreateVideoAndAccountAndChannel ( const actor = await getOrCreateVideoChannelFromVideoObject(fetchedVideo) const videoChannel = actor.VideoChannel - const { autoBlacklisted, videoCreated } = await retryTransactionWrapper(createVideo, fetchedVideo, videoChannel, syncParam.thumbnail) - await syncVideoExternalAttributes(videoCreated, fetchedVideo, syncParam) + try { + const { autoBlacklisted, videoCreated } = await retryTransactionWrapper(createVideo, fetchedVideo, videoChannel, syncParam.thumbnail) + + await syncVideoExternalAttributes(videoCreated, fetchedVideo, syncParam) - return { video: videoCreated, created: true, autoBlacklisted } + return { video: videoCreated, created: true, autoBlacklisted } + } catch (err) { + // Maybe a concurrent getOrCreateVideoAndAccountAndChannel call created this video + if (err.name === 'SequelizeUniqueConstraintError') { + const fallbackVideo = await fetchVideoByUrl(videoUrl, fetchType) + if (fallbackVideo) return { video: fallbackVideo, created: false } + } + + throw err + } } async function updateVideoFromAP (options: { -- cgit v1.2.3