Delete storyboard file on video deletion

pull/5870/head
Chocobozzz 2023-06-02 15:32:53 +02:00
parent 9c5cc50133
commit 318aa9c422
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 28 additions and 2 deletions

View File

@ -762,7 +762,8 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
name: 'videoId', name: 'videoId',
allowNull: false allowNull: false
}, },
onDelete: 'cascade' onDelete: 'cascade',
hooks: true
}) })
Storyboard: StoryboardModel Storyboard: StoryboardModel

View File

@ -1,6 +1,8 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import { expect } from 'chai' import { expect } from 'chai'
import { readdir } from 'fs-extra'
import { basename } from 'path'
import { FIXTURE_URLS } from '@server/tests/shared' import { FIXTURE_URLS } from '@server/tests/shared'
import { areHttpImportTestsDisabled } from '@shared/core-utils' import { areHttpImportTestsDisabled } from '@shared/core-utils'
import { HttpStatusCode, VideoPrivacy } from '@shared/models' import { HttpStatusCode, VideoPrivacy } from '@shared/models'
@ -48,6 +50,8 @@ async function checkStoryboard (options: {
describe('Test video storyboard', function () { describe('Test video storyboard', function () {
let servers: PeerTubeServer[] let servers: PeerTubeServer[]
let baseUUID: string
before(async function () { before(async function () {
this.timeout(120000) this.timeout(120000)
@ -63,6 +67,7 @@ describe('Test video storyboard', function () {
// 5s video // 5s video
const { uuid } = await servers[0].videos.quickUpload({ name: 'upload', fixture: 'video_short.webm' }) const { uuid } = await servers[0].videos.quickUpload({ name: 'upload', fixture: 'video_short.webm' })
baseUUID = uuid
await waitJobs(servers) await waitJobs(servers)
for (const server of servers) { for (const server of servers) {
@ -173,9 +178,29 @@ describe('Test video storyboard', function () {
} }
}) })
it('Should generate a storyboard with different video durations', async function () { it('Should cleanup storyboards on video deletion', async function () {
this.timeout(60000) this.timeout(60000)
const { storyboards } = await servers[0].storyboard.list({ id: baseUUID })
const storyboardName = basename(storyboards[0].storyboardPath)
const listFiles = () => {
const storyboardPath = servers[0].getDirectoryPath('storyboards')
return readdir(storyboardPath)
}
{
const storyboads = await listFiles()
expect(storyboads).to.include(storyboardName)
}
await servers[0].videos.remove({ id: baseUUID })
await waitJobs(servers)
{
const storyboads = await listFiles()
expect(storyboads).to.not.include(storyboardName)
}
}) })
after(async function () { after(async function () {