X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=scripts%2Fprune-storage.ts;h=1def1d792f882d7098445c07f9420d15bbb4c02e;hb=aea53cc64919b3a3ecfdf78b6b15c6a4d6edeea1;hp=d6dff8247bc78a9849e0af63fb61b12e85e64431;hpb=e2600d8b261994abbbeb1ff921edaefd267fc122;p=github%2FChocobozzz%2FPeerTube.git diff --git a/scripts/prune-storage.ts b/scripts/prune-storage.ts index d6dff8247..1def1d792 100755 --- a/scripts/prune-storage.ts +++ b/scripts/prune-storage.ts @@ -1,14 +1,18 @@ +import { registerTSPaths } from '../server/helpers/register-ts-paths' +registerTSPaths() + import * as prompt from 'prompt' import { join } from 'path' import { CONFIG } from '../server/initializers/config' import { VideoModel } from '../server/models/video/video' -import { initDatabaseModels } from '../server/initializers' +import { initDatabaseModels } from '../server/initializers/database' import { readdir, remove } from 'fs-extra' 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 { AvatarModel } from '../server/models/avatar/avatar' +import { uniq, values } from 'lodash' run() .then(() => process.exit(0)) @@ -18,6 +22,13 @@ run() }) async function run () { + const dirs = values(CONFIG.STORAGE) + + if (uniq(dirs).length !== dirs.length) { + console.error('Cannot prune storage because you put multiple storage keys in the same directory.') + process.exit(0) + } + await initDatabaseModels(true) let toDelete: string[] = [] @@ -123,9 +134,9 @@ async function doesRedundancyExist (file: string) { return true } - const videoFile = video.getFile(resolution) + const videoFile = video.getWebTorrentFile(resolution) if (!videoFile) { - console.error('Cannot find file of video %s - %d', video.url, resolution) + console.error('Cannot find webtorrent file of video %s - %d', video.url, resolution) return true } @@ -150,7 +161,8 @@ async function askConfirmation () { } prompt.get(schema, function (err, result) { if (err) return rej(err) - return res(result.confirm && result.confirm.match(/y/) !== null) + + return res(result.confirm?.match(/y/) !== null) }) }) }