X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fvideos.ts;h=6c5f7f3065bdda6b2b9593413307952000686bea;hb=26d6bf6533023326fa017812cf31bbe20c752d36;hp=7d16bd3908fd42f1cc78567f486154e8aefaa8d0;hpb=610d0be13b3d01f653ef269271dd667a57c85ef2;p=oweals%2Fpeertube.git diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index 7d16bd390..6c5f7f306 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts @@ -52,7 +52,7 @@ import { sequelizeTypescript } from '../../initializers/database' import { createPlaceholderThumbnail, createVideoMiniatureFromUrl } from '../thumbnail' import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' import { join } from 'path' -import { FilteredModelAttributes } from '../../typings/sequelize' +import { FilteredModelAttributes } from '../../types/sequelize' import { autoBlacklistVideoIfNeeded } from '../video-blacklist' import { ActorFollowScoreCache } from '../files-cache' import { @@ -71,8 +71,8 @@ import { MVideoId, MVideoImmutable, MVideoThumbnail -} from '../../typings/models' -import { MThumbnail } from '../../typings/models/video/thumbnail' +} from '../../types/models' +import { MThumbnail } from '../../types/models/video/thumbnail' import { maxBy, minBy } from 'lodash' async function federateVideoIfNeeded (videoArg: MVideoAPWithoutCaption, isNewVideo: boolean, transaction?: sequelize.Transaction) { @@ -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: {