X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=scripts%2Fprune-storage.ts;h=bb1e8e024041e74c4df41d72988db9bf040ea033;hb=10d2be9e64c9dce2ac181487ee8134a5b0b4cde3;hp=5b029d215a703de61bfad4fe6cee4d9894394692;hpb=421ff4618da64f0849353383f690a014024c40da;p=github%2FChocobozzz%2FPeerTube.git diff --git a/scripts/prune-storage.ts b/scripts/prune-storage.ts index 5b029d215..bb1e8e024 100755 --- a/scripts/prune-storage.ts +++ b/scripts/prune-storage.ts @@ -1,20 +1,19 @@ -import { registerTSPaths } from '../server/helpers/register-ts-paths' -registerTSPaths() - -import * as prompt from 'prompt' -import { join, basename } from 'path' +import { map } from 'bluebird' +import { readdir, remove, stat } from 'fs-extra' +import { uniq, values } from 'lodash' +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 { 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 * as Bluebird 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)) @@ -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), @@ -78,7 +80,7 @@ async function pruneDirectory (directory: string, existFun: ExistFun) { const files = await readdir(directory) const toDelete: string[] = [] - await Bluebird.map(files, async file => { + await map(files, async file => { const filePath = join(directory, file) if (await existFun(filePath) !== true) { @@ -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 @@ -141,7 +150,7 @@ async function doesRedundancyExist (filePath: string) { async function askConfirmation () { return new Promise((res, rej) => { - prompt.start() + start() const schema = { properties: { confirm: { @@ -154,7 +163,7 @@ async function askConfirmation () { } } } - prompt.get(schema, function (err, result) { + get(schema, function (err, result) { if (err) return rej(err) return res(result.confirm?.match(/y/) !== null)