X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=scripts%2Fprune-storage.ts;h=788d97997d2c1eadc971e1e6638c7ed912be386d;hb=a8b1b40485145ac1eae513a661d7dd6e0986ce96;hp=fa3d817446754cb50413dcb94ea8bdfbd12b914f;hpb=d7a25329f9e607894d29ab342b9cb66638b56dc0;p=github%2FChocobozzz%2FPeerTube.git diff --git a/scripts/prune-storage.ts b/scripts/prune-storage.ts index fa3d81744..788d97997 100755 --- a/scripts/prune-storage.ts +++ b/scripts/prune-storage.ts @@ -5,7 +5,7 @@ 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' @@ -13,6 +13,7 @@ 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' +import { ThumbnailType } from '@shared/models' run() .then(() => process.exit(0)) @@ -39,8 +40,8 @@ async function run () { await pruneDirectory(CONFIG.STORAGE.REDUNDANCY_DIR, doesRedundancyExist), - await pruneDirectory(CONFIG.STORAGE.PREVIEWS_DIR, doesThumbnailExist(true)), - await pruneDirectory(CONFIG.STORAGE.THUMBNAILS_DIR, doesThumbnailExist(false)), + await pruneDirectory(CONFIG.STORAGE.PREVIEWS_DIR, doesThumbnailExist(true, ThumbnailType.PREVIEW)), + await pruneDirectory(CONFIG.STORAGE.THUMBNAILS_DIR, doesThumbnailExist(false, ThumbnailType.MINIATURE)), await pruneDirectory(CONFIG.STORAGE.AVATARS_DIR, doesAvatarExist) ) @@ -92,9 +93,9 @@ function doesVideoExist (keepOnlyOwned: boolean) { } } -function doesThumbnailExist (keepOnlyOwned: boolean) { +function doesThumbnailExist (keepOnlyOwned: boolean, type: ThumbnailType) { return async (file: string) => { - const thumbnail = await ThumbnailModel.loadByName(file) + const thumbnail = await ThumbnailModel.loadWithVideoByName(file, type) if (!thumbnail) return false if (keepOnlyOwned) { @@ -161,7 +162,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) }) }) }