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 {
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) {
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: {