summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-05-04 15:07:02 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-05-04 15:07:02 +0900
commitbcf28282f6d1e0cba35c4dda2c15c0f8fe6fb6ad (patch)
tree3ee5b4f6a07a8be55cf7f8dbf1bb22869bc512d0 /cli
parent:v: (diff)
downloadsharkey-bcf28282f6d1e0cba35c4dda2c15c0f8fe6fb6ad.tar.gz
sharkey-bcf28282f6d1e0cba35c4dda2c15c0f8fe6fb6ad.tar.bz2
sharkey-bcf28282f6d1e0cba35c4dda2c15c0f8fe6fb6ad.zip
:v:
Diffstat (limited to 'cli')
-rw-r--r--cli/clean-drive.js34
1 files changed, 19 insertions, 15 deletions
diff --git a/cli/clean-drive.js b/cli/clean-drive.js
index 14eb002795..35766f9a34 100644
--- a/cli/clean-drive.js
+++ b/cli/clean-drive.js
@@ -16,19 +16,23 @@ async function main() {
for (let i = 0; i < count; i++) {
promiseGens.push(() => {
const promise = new Promise(async (res, rej) => {
+ function skip() {
+ res([i, file, false]);
+ }
+
const file = await DriveFile.findOne(prev ? {
- _id: { $gt: prev._id }
+ _id: { $lt: prev._id }
} : {}, {
sort: {
- _id: 1
+ _id: -1
}
});
prev = file;
- if (file == null) return res();
+ if (file == null) return skip();
- log(chalk`scanning: {bold ${file._id}} ...`);
+ log(chalk`{gray ${i}} scanning: {bold ${file._id}} ...`);
const attachingUsersCount = await User.count({
$or: [{
@@ -37,28 +41,28 @@ async function main() {
bannerId: file._id
}]
}, { limit: 1 });
- if (attachingUsersCount !== 0) return res();
+ if (attachingUsersCount !== 0) return skip();
const attachingNotesCount = await Note.count({
mediaIds: file._id
}, { limit: 1 });
- if (attachingNotesCount !== 0) return res();
+ if (attachingNotesCount !== 0) return skip();
const attachingMessagesCount = await MessagingMessage.count({
fileId: file._id
}, { limit: 1 });
- if (attachingMessagesCount !== 0) return res();
+ if (attachingMessagesCount !== 0) return skip();
- deleteDriveFile(file).then(res).catch(rej);
+ deleteDriveFile(file).then(() => {
+ res([i, file, true]);
+ }).catch(rej);
});
- promise.then(x => {
- if (prev) {
- if (x == null) {
- log(chalk`{green skipped: {bold ${prev._id}}}`);
- } else {
- log(chalk`{red deleted: {bold ${prev._id}}}`);
- }
+ promise.then(([i, file, deleted]) => {
+ if (deleted) {
+ log(chalk`{gray ${i}} {red deleted: {bold ${file._id}}}`);
+ } else {
+ log(chalk`{gray ${i}} {green skipped: {bold ${file._id}}}`);
}
log.clear();
console.log();