From 1bb4c9ab2e8b3b3022351b33a82a5e527fa5d4d7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 29 Jul 2022 14:50:41 +0200 Subject: Add ability to delete a specific video file --- server/models/video/video-streaming-playlist.ts | 36 ++++++++++++++++++++++--- server/models/video/video.ts | 10 ++++--- 2 files changed, 40 insertions(+), 6 deletions(-) (limited to 'server/models/video') diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts index 2c4dbd8ec..f587989dc 100644 --- a/server/models/video/video-streaming-playlist.ts +++ b/server/models/video/video-streaming-playlist.ts @@ -16,8 +16,9 @@ import { UpdatedAt } from 'sequelize-typescript' import { getHLSPublicFileUrl } from '@server/lib/object-storage' +import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename } from '@server/lib/paths' import { VideoFileModel } from '@server/models/video/video-file' -import { MStreamingPlaylist, MVideo } from '@server/types/models' +import { MStreamingPlaylist, MStreamingPlaylistFilesVideo, MVideo } from '@server/types/models' import { sha1 } from '@shared/extra-utils' import { VideoStorage } from '@shared/models' import { AttributesOnly } from '@shared/typescript-utils' @@ -167,6 +168,22 @@ export class VideoStreamingPlaylistModel extends Model(id, options) + } + static loadWithVideo (id: number) { const options = { include: [ @@ -194,9 +211,22 @@ export class VideoStreamingPlaylistModel extends Model>> { // Remove physical files and torrents instance.VideoFiles.forEach(file => { - tasks.push(instance.removeWebTorrentFileAndTorrent(file)) + tasks.push(instance.removeWebTorrentFile(file)) }) // Remove playlists file @@ -1783,7 +1783,7 @@ export class VideoModel extends Model>> { .concat(toAdd) } - removeWebTorrentFileAndTorrent (videoFile: MVideoFile, isRedundancy = false) { + removeWebTorrentFile (videoFile: MVideoFile, isRedundancy = false) { const filePath = isRedundancy ? VideoPathManager.Instance.getFSRedundancyVideoFilePath(this, videoFile) : VideoPathManager.Instance.getFSVideoFileOutputPath(this, videoFile) @@ -1829,8 +1829,12 @@ export class VideoModel extends Model>> { await videoFile.removeTorrent() await remove(filePath) + const resolutionFilename = getHlsResolutionPlaylistFilename(videoFile.filename) + await remove(VideoPathManager.Instance.getFSHLSOutputPath(this, resolutionFilename)) + if (videoFile.storage === VideoStorage.OBJECT_STORAGE) { await removeHLSFileObjectStorage(streamingPlaylist.withVideo(this), videoFile.filename) + await removeHLSFileObjectStorage(streamingPlaylist.withVideo(this), resolutionFilename) } } -- cgit v1.2.3