From 26649b4215ac68eed5601d9412d2d7ddee98b543 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 1 Oct 2018 10:31:42 +0200 Subject: Ensure video existence before duplicating it --- server/lib/activitypub/videos.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'server/lib/activitypub/videos.ts') diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index 3dccabe12..b1e7f20b9 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts @@ -370,13 +370,15 @@ async function refreshVideoIfNeeded (options: { try { const { response, videoObject } = await fetchRemoteVideo(video.url) if (response.statusCode === 404) { + logger.info('Cannot refresh remote video %s: video does not exist anymore. Deleting it.', video.url) + // Video does not exist anymore await video.destroy() return undefined } if (videoObject === undefined) { - logger.warn('Cannot refresh remote video: invalid body.') + logger.warn('Cannot refresh remote video %s: invalid body.', video.url) return video } @@ -390,8 +392,10 @@ async function refreshVideoIfNeeded (options: { channel: channelActor.VideoChannel, updateViews: options.refreshViews } - await retryTransactionWrapper(updateVideoFromAP, updateOptions) - await syncVideoExternalAttributes(video, videoObject, options.syncParam) + const videoUpdated = await retryTransactionWrapper(updateVideoFromAP, updateOptions) + await syncVideoExternalAttributes(videoUpdated, videoObject, options.syncParam) + + return videoUpdated } catch (err) { logger.warn('Cannot refresh video.', { err }) return video -- cgit v1.2.3