diff options
Diffstat (limited to 'scripts/prune-storage.ts')
-rwxr-xr-x | scripts/prune-storage.ts | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/scripts/prune-storage.ts b/scripts/prune-storage.ts index 3012bdb94..d19594a60 100755 --- a/scripts/prune-storage.ts +++ b/scripts/prune-storage.ts | |||
@@ -2,7 +2,7 @@ import { map } from 'bluebird' | |||
2 | import { readdir, remove, stat } from 'fs-extra' | 2 | import { readdir, remove, stat } from 'fs-extra' |
3 | import { basename, join } from 'path' | 3 | import { basename, join } from 'path' |
4 | import { get, start } from 'prompt' | 4 | import { get, start } from 'prompt' |
5 | import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants' | 5 | import { DIRECTORIES } from '@server/initializers/constants' |
6 | import { VideoFileModel } from '@server/models/video/video-file' | 6 | import { VideoFileModel } from '@server/models/video/video-file' |
7 | import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' | 7 | import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' |
8 | import { uniqify } from '@shared/core-utils' | 8 | import { uniqify } from '@shared/core-utils' |
@@ -37,9 +37,11 @@ async function run () { | |||
37 | console.log('Detecting files to remove, it could take a while...') | 37 | console.log('Detecting files to remove, it could take a while...') |
38 | 38 | ||
39 | toDelete = toDelete.concat( | 39 | toDelete = toDelete.concat( |
40 | await pruneDirectory(CONFIG.STORAGE.VIDEOS_DIR, doesWebTorrentFileExist()), | 40 | await pruneDirectory(DIRECTORIES.VIDEOS.PUBLIC, doesWebTorrentFileExist()), |
41 | await pruneDirectory(DIRECTORIES.VIDEOS.PRIVATE, doesWebTorrentFileExist()), | ||
41 | 42 | ||
42 | await pruneDirectory(HLS_STREAMING_PLAYLIST_DIRECTORY, doesHLSPlaylistExist()), | 43 | await pruneDirectory(DIRECTORIES.HLS_STREAMING_PLAYLIST.PRIVATE, doesHLSPlaylistExist()), |
44 | await pruneDirectory(DIRECTORIES.HLS_STREAMING_PLAYLIST.PUBLIC, doesHLSPlaylistExist()), | ||
43 | 45 | ||
44 | await pruneDirectory(CONFIG.STORAGE.TORRENTS_DIR, doesTorrentFileExist()), | 46 | await pruneDirectory(CONFIG.STORAGE.TORRENTS_DIR, doesTorrentFileExist()), |
45 | 47 | ||
@@ -75,7 +77,7 @@ async function run () { | |||
75 | } | 77 | } |
76 | } | 78 | } |
77 | 79 | ||
78 | type ExistFun = (file: string) => Promise<boolean> | 80 | type ExistFun = (file: string) => Promise<boolean> | boolean |
79 | async function pruneDirectory (directory: string, existFun: ExistFun) { | 81 | async function pruneDirectory (directory: string, existFun: ExistFun) { |
80 | const files = await readdir(directory) | 82 | const files = await readdir(directory) |
81 | 83 | ||
@@ -92,11 +94,21 @@ async function pruneDirectory (directory: string, existFun: ExistFun) { | |||
92 | } | 94 | } |
93 | 95 | ||
94 | function doesWebTorrentFileExist () { | 96 | function doesWebTorrentFileExist () { |
95 | return (filePath: string) => VideoFileModel.doesOwnedWebTorrentVideoFileExist(basename(filePath)) | 97 | return (filePath: string) => { |
98 | // Don't delete private directory | ||
99 | if (filePath === DIRECTORIES.VIDEOS.PRIVATE) return true | ||
100 | |||
101 | return VideoFileModel.doesOwnedWebTorrentVideoFileExist(basename(filePath)) | ||
102 | } | ||
96 | } | 103 | } |
97 | 104 | ||
98 | function doesHLSPlaylistExist () { | 105 | function doesHLSPlaylistExist () { |
99 | return (hlsPath: string) => VideoStreamingPlaylistModel.doesOwnedHLSPlaylistExist(basename(hlsPath)) | 106 | return (hlsPath: string) => { |
107 | // Don't delete private directory | ||
108 | if (hlsPath === DIRECTORIES.HLS_STREAMING_PLAYLIST.PRIVATE) return true | ||
109 | |||
110 | return VideoStreamingPlaylistModel.doesOwnedHLSPlaylistExist(basename(hlsPath)) | ||
111 | } | ||
100 | } | 112 | } |
101 | 113 | ||
102 | function doesTorrentFileExist () { | 114 | function doesTorrentFileExist () { |
@@ -127,8 +139,8 @@ async function doesRedundancyExist (filePath: string) { | |||
127 | const isPlaylist = (await stat(filePath)).isDirectory() | 139 | const isPlaylist = (await stat(filePath)).isDirectory() |
128 | 140 | ||
129 | if (isPlaylist) { | 141 | if (isPlaylist) { |
130 | // Don't delete HLS directory | 142 | // Don't delete HLS redundancy directory |
131 | if (filePath === HLS_REDUNDANCY_DIRECTORY) return true | 143 | if (filePath === DIRECTORIES.HLS_REDUNDANCY) return true |
132 | 144 | ||
133 | const uuid = getUUIDFromFilename(filePath) | 145 | const uuid = getUUIDFromFilename(filePath) |
134 | const video = await VideoModel.loadWithFiles(uuid) | 146 | const video = await VideoModel.loadWithFiles(uuid) |