]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - scripts/prune-storage.ts
Fix old DB enum names
[github/Chocobozzz/PeerTube.git] / scripts / prune-storage.ts
index 00141fec1a47add675581e8ebb6abe56a7d3bf28..3012bdb94836ec6f343f9c05a29c3b35dae5b10d 100755 (executable)
@@ -1,20 +1,19 @@
-import { registerTSPaths } from '../server/helpers/register-ts-paths'
-registerTSPaths()
-
-import { start, get } from 'prompt'
-import { join, basename } from 'path'
+import { map } from 'bluebird'
+import { readdir, remove, stat } from 'fs-extra'
+import { basename, join } from 'path'
+import { get, start } from 'prompt'
+import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants'
+import { VideoFileModel } from '@server/models/video/video-file'
+import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist'
+import { uniqify } from '@shared/core-utils'
+import { ThumbnailType } from '@shared/models'
+import { getUUIDFromFilename } from '../server/helpers/utils'
 import { CONFIG } from '../server/initializers/config'
-import { VideoModel } from '../server/models/video/video'
 import { initDatabaseModels } from '../server/initializers/database'
-import { readdir, remove, stat } from 'fs-extra'
+import { ActorImageModel } from '../server/models/actor/actor-image'
 import { VideoRedundancyModel } from '../server/models/redundancy/video-redundancy'
-import { map } from 'bluebird'
-import { getUUIDFromFilename } from '../server/helpers/utils'
 import { ThumbnailModel } from '../server/models/video/thumbnail'
-import { ActorImageModel } from '../server/models/actor/actor-image'
-import { uniq, values } from 'lodash'
-import { ThumbnailType } from '@shared/models'
-import { VideoFileModel } from '@server/models/video/video-file'
+import { VideoModel } from '../server/models/video/video'
 
 run()
   .then(() => process.exit(0))
@@ -24,9 +23,9 @@ run()
   })
 
 async function run () {
-  const dirs = values(CONFIG.STORAGE)
+  const dirs = Object.values(CONFIG.STORAGE)
 
-  if (uniq(dirs).length !== dirs.length) {
+  if (uniqify(dirs).length !== dirs.length) {
     console.error('Cannot prune storage because you put multiple storage keys in the same directory.')
     process.exit(0)
   }
@@ -39,6 +38,9 @@ async function run () {
 
   toDelete = toDelete.concat(
     await pruneDirectory(CONFIG.STORAGE.VIDEOS_DIR, doesWebTorrentFileExist()),
+
+    await pruneDirectory(HLS_STREAMING_PLAYLIST_DIRECTORY, doesHLSPlaylistExist()),
+
     await pruneDirectory(CONFIG.STORAGE.TORRENTS_DIR, doesTorrentFileExist()),
 
     await pruneDirectory(CONFIG.STORAGE.REDUNDANCY_DIR, doesRedundancyExist),
@@ -93,6 +95,10 @@ function doesWebTorrentFileExist () {
   return (filePath: string) => VideoFileModel.doesOwnedWebTorrentVideoFileExist(basename(filePath))
 }
 
+function doesHLSPlaylistExist () {
+  return (hlsPath: string) => VideoStreamingPlaylistModel.doesOwnedHLSPlaylistExist(basename(hlsPath))
+}
+
 function doesTorrentFileExist () {
   return (filePath: string) => VideoFileModel.doesOwnedTorrentFileExist(basename(filePath))
 }
@@ -121,6 +127,9 @@ async function doesRedundancyExist (filePath: string) {
   const isPlaylist = (await stat(filePath)).isDirectory()
 
   if (isPlaylist) {
+    // Don't delete HLS directory
+    if (filePath === HLS_REDUNDANCY_DIRECTORY) return true
+
     const uuid = getUUIDFromFilename(filePath)
     const video = await VideoModel.loadWithFiles(uuid)
     if (!video) return false