From feef4a933ebf2d353faee27ea276220fb7d5b519 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 16 Oct 2018 20:10:46 +0900 Subject: [PATCH] Update src/tools/clean-remote-files.ts --- src/tools/clean-remote-files.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/tools/clean-remote-files.ts diff --git a/src/tools/clean-remote-files.ts b/src/tools/clean-remote-files.ts new file mode 100644 index 000000000..28c76345c --- /dev/null +++ b/src/tools/clean-remote-files.ts @@ -0,0 +1,30 @@ +import * as promiseLimit from 'promise-limit'; +import DriveFile, { IDriveFile } from '../models/drive-file'; +import del from '../services/drive/delete-file'; + +const limit = promiseLimit(16); + +DriveFile.find({ + 'metadata._user.host': { + $ne: null + }, + 'metadata.deletedAt': { $exists: false } +}, { + fields: { + _id: true + } +}).then(async files => { + console.log(`there is ${files.length} files`); + + await Promise.all(files.map(file => limit(() => job(file)))); + + console.log('ALL DONE'); +}); + +async function job(file: IDriveFile): Promise { + file = await DriveFile.findOne({ _id: file._id }); + + await del(file, true); + + console.log('done', file._id); +}