From 6872996d296d5b8024c569fce426562fac2f64bf Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 6 Feb 2020 17:39:19 +0100 Subject: Be more robust with missing thumbnails/previews --- server/lib/activitypub/videos.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'server/lib/activitypub/videos.ts') diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index 7d8296e45..7386c2e53 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts @@ -340,9 +340,11 @@ async function updateVideoFromAP (options: { if (thumbnailModel) await videoUpdated.addAndSaveThumbnail(thumbnailModel, t) - const previewUrl = videoUpdated.getPreview().getFileUrl(videoUpdated) - const previewModel = createPlaceholderThumbnail(previewUrl, video, ThumbnailType.PREVIEW, PREVIEWS_SIZE) - await videoUpdated.addAndSaveThumbnail(previewModel, t) + if (videoUpdated.getPreview()) { + const previewUrl = videoUpdated.getPreview().getFileUrl(videoUpdated) + const previewModel = createPlaceholderThumbnail(previewUrl, video, ThumbnailType.PREVIEW, PREVIEWS_SIZE) + await videoUpdated.addAndSaveThumbnail(previewModel, t) + } { const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoUpdated, videoObject.url) @@ -531,6 +533,10 @@ async function createVideo (videoObject: VideoTorrentObject, channel: MChannelAc const video = VideoModel.build(videoData) as MVideoThumbnail const promiseThumbnail = createVideoMiniatureFromUrl(getThumbnailFromIcons(videoObject).url, video, ThumbnailType.MINIATURE) + .catch(err => { + logger.error('Cannot create miniature from url.', { err }) + return undefined + }) let thumbnailModel: MThumbnail if (waitThumbnail === true) { @@ -602,11 +608,15 @@ async function createVideo (videoObject: VideoTorrentObject, channel: MChannelAc }) if (waitThumbnail === false) { + // Error is already caught above + // eslint-disable-next-line @typescript-eslint/no-floating-promises promiseThumbnail.then(thumbnailModel => { + if (!thumbnailModel) return + thumbnailModel = videoCreated.id return thumbnailModel.save() - }).catch(err => logger.error('Cannot create miniature from url.', { err })) + }) } return { autoBlacklisted, videoCreated } -- cgit v1.2.3