mirror of https://github.com/Chocobozzz/PeerTube
Fix fk error when generating storyboard
parent
89b9eab5a7
commit
93fd6f3b18
|
@ -1,10 +1,13 @@
|
||||||
import { Job } from 'bullmq'
|
import { Job } from 'bullmq'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
|
import { retryTransactionWrapper } from '@server/helpers/database-utils'
|
||||||
import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg'
|
import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg'
|
||||||
import { generateImageFilename, getImageSize } from '@server/helpers/image-utils'
|
import { generateImageFilename, getImageSize } from '@server/helpers/image-utils'
|
||||||
import { logger, loggerTagsFactory } from '@server/helpers/logger'
|
import { logger, loggerTagsFactory } from '@server/helpers/logger'
|
||||||
|
import { deleteFileAndCatch } from '@server/helpers/utils'
|
||||||
import { CONFIG } from '@server/initializers/config'
|
import { CONFIG } from '@server/initializers/config'
|
||||||
import { STORYBOARD } from '@server/initializers/constants'
|
import { STORYBOARD } from '@server/initializers/constants'
|
||||||
|
import { sequelizeTypescript } from '@server/initializers/database'
|
||||||
import { federateVideoIfNeeded } from '@server/lib/activitypub/videos'
|
import { federateVideoIfNeeded } from '@server/lib/activitypub/videos'
|
||||||
import { VideoPathManager } from '@server/lib/video-path-manager'
|
import { VideoPathManager } from '@server/lib/video-path-manager'
|
||||||
import { StoryboardModel } from '@server/models/video/storyboard'
|
import { StoryboardModel } from '@server/models/video/storyboard'
|
||||||
|
@ -75,8 +78,17 @@ async function processGenerateStoryboard (job: Job): Promise<void> {
|
||||||
|
|
||||||
const imageSize = await getImageSize(destination)
|
const imageSize = await getImageSize(destination)
|
||||||
|
|
||||||
const existing = await StoryboardModel.loadByVideo(video.id)
|
await retryTransactionWrapper(() => {
|
||||||
if (existing) await existing.destroy()
|
return sequelizeTypescript.transaction(async transaction => {
|
||||||
|
const videoStillExists = await VideoModel.load(video.id, transaction)
|
||||||
|
if (!videoStillExists) {
|
||||||
|
logger.info('Video %s does not exist anymore, skipping storyboard generation.', payload.videoUUID, lTags)
|
||||||
|
deleteFileAndCatch(destination)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = await StoryboardModel.loadByVideo(video.id, transaction)
|
||||||
|
if (existing) await existing.destroy({ transaction })
|
||||||
|
|
||||||
await StoryboardModel.create({
|
await StoryboardModel.create({
|
||||||
filename,
|
filename,
|
||||||
|
@ -86,14 +98,19 @@ async function processGenerateStoryboard (job: Job): Promise<void> {
|
||||||
spriteWidth: STORYBOARD.SPRITE_SIZE.width,
|
spriteWidth: STORYBOARD.SPRITE_SIZE.width,
|
||||||
spriteDuration,
|
spriteDuration,
|
||||||
videoId: video.id
|
videoId: video.id
|
||||||
})
|
}, { transaction })
|
||||||
|
|
||||||
logger.info('Storyboard generation %s ended for video %s.', destination, video.uuid, lTags)
|
logger.info('Storyboard generation %s ended for video %s.', destination, video.uuid, lTags)
|
||||||
})
|
|
||||||
|
|
||||||
if (payload.federate) {
|
if (payload.federate) {
|
||||||
await federateVideoIfNeeded(video, false)
|
await federateVideoIfNeeded(video, false, transaction)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
inputFileMutexReleaser()
|
inputFileMutexReleaser()
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ export class StoryboardModel extends Model<Partial<AttributesOnly<StoryboardMode
|
||||||
|
|
||||||
@BelongsTo(() => VideoModel, {
|
@BelongsTo(() => VideoModel, {
|
||||||
foreignKey: {
|
foreignKey: {
|
||||||
allowNull: true
|
allowNull: false
|
||||||
},
|
},
|
||||||
onDelete: 'CASCADE'
|
onDelete: 'CASCADE'
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue