-async function checkVideoFilesWereRemoved (
- videoUUID: string,
- server: PeerTubeServer,
- directories = [
- 'redundancy',
- 'videos',
- 'thumbnails',
- 'torrents',
- 'previews',
- 'captions',
- join('playlists', 'hls'),
- join('redundancy', 'hls')
- ]
-) {
- for (const directory of directories) {
+async function checkVideoFilesWereRemoved (options: {
+ server: PeerTubeServer
+ video: VideoDetails
+ captions?: VideoCaption[]
+ onlyVideoFiles?: boolean // default false
+}) {
+ const { video, server, captions = [], onlyVideoFiles = false } = options
+
+ const webtorrentFiles = video.files || []
+ const hlsFiles = video.streamingPlaylists[0]?.files || []
+
+ const thumbnailName = basename(video.thumbnailPath)
+ const previewName = basename(video.previewPath)
+
+ const torrentNames = webtorrentFiles.concat(hlsFiles).map(f => basename(f.torrentUrl))
+
+ const captionNames = captions.map(c => basename(c.captionPath))
+
+ const webtorrentFilenames = webtorrentFiles.map(f => basename(f.fileUrl))
+ const hlsFilenames = hlsFiles.map(f => basename(f.fileUrl))
+
+ let directories: { [ directory: string ]: string[] } = {
+ videos: webtorrentFilenames,
+ redundancy: webtorrentFilenames,
+ [join('playlists', 'hls')]: hlsFilenames,
+ [join('redundancy', 'hls')]: hlsFilenames
+ }
+
+ if (onlyVideoFiles !== true) {
+ directories = {
+ ...directories,
+
+ thumbnails: [ thumbnailName ],
+ previews: [ previewName ],
+ torrents: torrentNames,
+ captions: captionNames
+ }
+ }
+
+ for (const directory of Object.keys(directories)) {