Be more robust with missing thumbnails/previews
This commit is contained in:
parent
a3b7421abb
commit
6872996d29
2 changed files with 18 additions and 4 deletions
|
@ -340,9 +340,11 @@ async function updateVideoFromAP (options: {
|
||||||
|
|
||||||
if (thumbnailModel) await videoUpdated.addAndSaveThumbnail(thumbnailModel, t)
|
if (thumbnailModel) await videoUpdated.addAndSaveThumbnail(thumbnailModel, t)
|
||||||
|
|
||||||
const previewUrl = videoUpdated.getPreview().getFileUrl(videoUpdated)
|
if (videoUpdated.getPreview()) {
|
||||||
const previewModel = createPlaceholderThumbnail(previewUrl, video, ThumbnailType.PREVIEW, PREVIEWS_SIZE)
|
const previewUrl = videoUpdated.getPreview().getFileUrl(videoUpdated)
|
||||||
await videoUpdated.addAndSaveThumbnail(previewModel, t)
|
const previewModel = createPlaceholderThumbnail(previewUrl, video, ThumbnailType.PREVIEW, PREVIEWS_SIZE)
|
||||||
|
await videoUpdated.addAndSaveThumbnail(previewModel, t)
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoUpdated, videoObject.url)
|
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 video = VideoModel.build(videoData) as MVideoThumbnail
|
||||||
|
|
||||||
const promiseThumbnail = createVideoMiniatureFromUrl(getThumbnailFromIcons(videoObject).url, video, ThumbnailType.MINIATURE)
|
const promiseThumbnail = createVideoMiniatureFromUrl(getThumbnailFromIcons(videoObject).url, video, ThumbnailType.MINIATURE)
|
||||||
|
.catch(err => {
|
||||||
|
logger.error('Cannot create miniature from url.', { err })
|
||||||
|
return undefined
|
||||||
|
})
|
||||||
|
|
||||||
let thumbnailModel: MThumbnail
|
let thumbnailModel: MThumbnail
|
||||||
if (waitThumbnail === true) {
|
if (waitThumbnail === true) {
|
||||||
|
@ -602,11 +608,15 @@ async function createVideo (videoObject: VideoTorrentObject, channel: MChannelAc
|
||||||
})
|
})
|
||||||
|
|
||||||
if (waitThumbnail === false) {
|
if (waitThumbnail === false) {
|
||||||
|
// Error is already caught above
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
promiseThumbnail.then(thumbnailModel => {
|
promiseThumbnail.then(thumbnailModel => {
|
||||||
|
if (!thumbnailModel) return
|
||||||
|
|
||||||
thumbnailModel = videoCreated.id
|
thumbnailModel = videoCreated.id
|
||||||
|
|
||||||
return thumbnailModel.save()
|
return thumbnailModel.save()
|
||||||
}).catch(err => logger.error('Cannot create miniature from url.', { err }))
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return { autoBlacklisted, videoCreated }
|
return { autoBlacklisted, videoCreated }
|
||||||
|
|
|
@ -1937,6 +1937,10 @@ export class VideoModel extends Model<VideoModel> {
|
||||||
return this.uuid + '.jpg'
|
return this.uuid + '.jpg'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasPreview () {
|
||||||
|
return !!this.getPreview()
|
||||||
|
}
|
||||||
|
|
||||||
getPreview () {
|
getPreview () {
|
||||||
if (Array.isArray(this.Thumbnails) === false) return undefined
|
if (Array.isArray(this.Thumbnails) === false) return undefined
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue