X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=scripts%2Fprune-storage.ts;h=9df80d5035154cb2eb8d1a6f257eed26f90a6d79;hb=188aa7740c603fe333cb2fa15494605d1f16a168;hp=5b029d215a703de61bfad4fe6cee4d9894394692;hpb=421ff4618da64f0849353383f690a014024c40da;p=github%2FChocobozzz%2FPeerTube.git diff --git a/scripts/prune-storage.ts b/scripts/prune-storage.ts index 5b029d215..9df80d503 100755 --- a/scripts/prune-storage.ts +++ b/scripts/prune-storage.ts @@ -1,20 +1,21 @@ import { registerTSPaths } from '../server/helpers/register-ts-paths' registerTSPaths() -import * as prompt from 'prompt' +import { start, get } from 'prompt' import { join, basename } from 'path' 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 { VideoRedundancyModel } from '../server/models/redundancy/video-redundancy' -import * as Bluebird from 'bluebird' +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 { HLS_REDUNDANCY_DIRECTORY } from '@server/initializers/constants' run() .then(() => process.exit(0)) @@ -78,7 +79,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) { @@ -121,6 +122,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 +145,7 @@ async function doesRedundancyExist (filePath: string) { async function askConfirmation () { return new Promise((res, rej) => { - prompt.start() + start() const schema = { properties: { confirm: { @@ -154,7 +158,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)