From 585050821a46080dd90a370b606311676a8903b0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 5 Jun 2024 15:47:37 +0200 Subject: [PATCH] Also prune storyboards and actor images --- packages/tests/src/cli/prune-storage.ts | 56 +++++++++---------- .../avatar-permanent-file-cache.ts | 2 +- server/core/models/actor/actor-image.ts | 2 +- server/scripts/prune-storage.ts | 24 +++++++- 4 files changed, 53 insertions(+), 31 deletions(-) diff --git a/packages/tests/src/cli/prune-storage.ts b/packages/tests/src/cli/prune-storage.ts index b36653036..da4a183f7 100644 --- a/packages/tests/src/cli/prune-storage.ts +++ b/packages/tests/src/cli/prune-storage.ts @@ -43,7 +43,13 @@ describe('Test prune storage CLI', function () { await server.videos.quickUpload({ name: 'video 1', privacy: VideoPrivacy.PUBLIC }) await server.videos.quickUpload({ name: 'video 2', privacy: VideoPrivacy.PUBLIC }) - await server.videos.quickUpload({ name: 'video 3', privacy: VideoPrivacy.PRIVATE }) + const { uuid } = await server.videos.quickUpload({ name: 'video 3', privacy: VideoPrivacy.PRIVATE }) + + await server.captions.add({ + language: 'ar', + videoId: uuid, + fixture: 'subtitle-good1.vtt' + }) await server.users.updateMyAvatar({ fixture: 'avatar.png' }) @@ -137,6 +143,12 @@ describe('Test prune storage CLI', function () { const originalVideoFilesCount = await server.servers.countFiles(join('original-video-files')) expect(originalVideoFilesCount).to.equal(3) + const storyboardsCount = await server.servers.countFiles(join('storyboards')) + expect(storyboardsCount).to.equal(3) + + const captionsCount = await server.servers.countFiles(join('captions')) + expect(captionsCount).to.equal(1) + const userExportFilesCount = await server.servers.countFiles(join('tmp-persistent')) expect(userExportFilesCount).to.equal(1) } @@ -175,32 +187,8 @@ describe('Test prune storage CLI', function () { badNames['torrents'] = [ n1, n2 ] } - { - const base = servers[0].servers.buildDirectory('thumbnails') - - const n1 = buildUUID() + '.jpg' - const n2 = buildUUID() + '.jpg' - - await createFile(join(base, n1)) - await createFile(join(base, n2)) - - badNames['thumbnails'] = [ n1, n2 ] - } - - { - const base = servers[0].servers.buildDirectory('previews') - - const n1 = buildUUID() + '.jpg' - const n2 = buildUUID() + '.jpg' - - await createFile(join(base, n1)) - await createFile(join(base, n2)) - - badNames['previews'] = [ n1, n2 ] - } - - { - const base = servers[0].servers.buildDirectory('avatars') + for (const name of [ 'thumbnails', 'previews', 'avatars', 'storyboards' ]) { + const base = servers[0].servers.buildDirectory(name) const n1 = buildUUID() + '.png' const n2 = buildUUID() + '.jpg' @@ -208,7 +196,7 @@ describe('Test prune storage CLI', function () { await createFile(join(base, n1)) await createFile(join(base, n2)) - badNames['avatars'] = [ n1, n2 ] + badNames[name] = [ n1, n2 ] } { @@ -231,6 +219,18 @@ describe('Test prune storage CLI', function () { badNames['original-video-files'] = [ n1 ] } + { + const base = servers[0].servers.buildDirectory('captions') + + const n1 = buildUUID() + '.vtt' + const n2 = buildUUID() + '.srt' + + await createFile(join(base, n1)) + await createFile(join(base, n2)) + + badNames['captions'] = [ n1, n2 ] + } + { const base = servers[0].servers.buildDirectory('tmp-persistent') diff --git a/server/core/lib/files-cache/avatar-permanent-file-cache.ts b/server/core/lib/files-cache/avatar-permanent-file-cache.ts index 7103e0c7f..cfeed8d6f 100644 --- a/server/core/lib/files-cache/avatar-permanent-file-cache.ts +++ b/server/core/lib/files-cache/avatar-permanent-file-cache.ts @@ -11,7 +11,7 @@ export class AvatarPermanentFileCache extends AbstractPermanentFileCache { // --------------------------------------------------------------------------- - static loadByName (filename: string) { + static loadByFilename (filename: string) { const query = { where: { filename diff --git a/server/scripts/prune-storage.ts b/server/scripts/prune-storage.ts index c3dafcc69..9356be5be 100755 --- a/server/scripts/prune-storage.ts +++ b/server/scripts/prune-storage.ts @@ -3,6 +3,8 @@ import { FileStorage, ThumbnailType, ThumbnailType_Type } from '@peertube/peertu import { DIRECTORIES, USER_EXPORT_FILE_PREFIX } from '@server/initializers/constants.js' import { listKeysOfPrefix, removeObjectByFullKey } from '@server/lib/object-storage/object-storage-helpers.js' import { UserExportModel } from '@server/models/user/user-export.js' +import { StoryboardModel } from '@server/models/video/storyboard.js' +import { VideoCaptionModel } from '@server/models/video/video-caption.js' import { VideoFileModel } from '@server/models/video/video-file.js' import { VideoSourceModel } from '@server/models/video/video-source.js' import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist.js' @@ -170,6 +172,10 @@ class FSPruner { await this.findFilesToDelete(CONFIG.STORAGE.PREVIEWS_DIR, this.doesThumbnailExistFactory(true, ThumbnailType.PREVIEW)) await this.findFilesToDelete(CONFIG.STORAGE.THUMBNAILS_DIR, this.doesThumbnailExistFactory(false, ThumbnailType.MINIATURE)) + await this.findFilesToDelete(CONFIG.STORAGE.CAPTIONS_DIR, this.doesCaptionExistFactory()) + + await this.findFilesToDelete(CONFIG.STORAGE.STORYBOARDS_DIR, this.doesStoryboardExistFactory()) + await this.findFilesToDelete(CONFIG.STORAGE.ACTOR_IMAGES_DIR, this.doesActorImageExistFactory()) await this.findFilesToDelete(CONFIG.STORAGE.TMP_PERSISTENT_DIR, this.doesUserExportExistFactory()) @@ -256,12 +262,28 @@ class FSPruner { private doesActorImageExistFactory () { return async (filePath: string) => { - const image = await ActorImageModel.loadByName(basename(filePath)) + const image = await ActorImageModel.loadByFilename(basename(filePath)) return !!image } } + private doesStoryboardExistFactory () { + return async (filePath: string) => { + const storyboard = await StoryboardModel.loadByFilename(basename(filePath)) + + return !!storyboard + } + } + + private doesCaptionExistFactory () { + return async (filePath: string) => { + const caption = await VideoCaptionModel.loadWithVideoByFilename(basename(filePath)) + + return !!caption + } + } + private doesRedundancyExistFactory () { return async (filePath: string) => { const isPlaylist = (await stat(filePath)).isDirectory()