aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/prune-storage.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-10-12 16:09:02 +0200
committerChocobozzz <chocobozzz@cpy.re>2022-10-24 14:48:24 +0200
commit3545e72c686ff1725bbdfd8d16d693e2f4aa75a3 (patch)
treee7f1d12ef5dae1e1142c3a8d0b681c1dbbb0de10 /scripts/prune-storage.ts
parent38a3ccc7f8ad0ea94362b58c732af7c387ab46be (diff)
downloadPeerTube-3545e72c686ff1725bbdfd8d16d693e2f4aa75a3.tar.gz
PeerTube-3545e72c686ff1725bbdfd8d16d693e2f4aa75a3.tar.zst
PeerTube-3545e72c686ff1725bbdfd8d16d693e2f4aa75a3.zip
Put private videos under a specific subdirectory
Diffstat (limited to 'scripts/prune-storage.ts')
-rwxr-xr-xscripts/prune-storage.ts28
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'
2import { readdir, remove, stat } from 'fs-extra' 2import { readdir, remove, stat } from 'fs-extra'
3import { basename, join } from 'path' 3import { basename, join } from 'path'
4import { get, start } from 'prompt' 4import { get, start } from 'prompt'
5import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants' 5import { DIRECTORIES } from '@server/initializers/constants'
6import { VideoFileModel } from '@server/models/video/video-file' 6import { VideoFileModel } from '@server/models/video/video-file'
7import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' 7import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist'
8import { uniqify } from '@shared/core-utils' 8import { 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
78type ExistFun = (file: string) => Promise<boolean> 80type ExistFun = (file: string) => Promise<boolean> | boolean
79async function pruneDirectory (directory: string, existFun: ExistFun) { 81async 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
94function doesWebTorrentFileExist () { 96function 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
98function doesHLSPlaylistExist () { 105function 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
102function doesTorrentFileExist () { 114function 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)