mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-22 09:57:29 -07:00
✌️
This commit is contained in:
parent
479d76c0d4
commit
b6907c78e8
2 changed files with 50 additions and 31 deletions
|
@ -3,8 +3,6 @@ const log = require('single-line-log').stdout;
|
||||||
const sequential = require('promise-sequential');
|
const sequential = require('promise-sequential');
|
||||||
const { default: DriveFile, DriveFileChunk } = require('../built/models/drive-file');
|
const { default: DriveFile, DriveFileChunk } = require('../built/models/drive-file');
|
||||||
const { default: DriveFileThumbnail, DriveFileThumbnailChunk } = require('../built/models/drive-file-thumbnail');
|
const { default: DriveFileThumbnail, DriveFileThumbnailChunk } = require('../built/models/drive-file-thumbnail');
|
||||||
const { default: Note } = require('../built/models/note');
|
|
||||||
const { default: MessagingMessage } = require('../built/models/messaging-message');
|
|
||||||
const { default: User } = require('../built/models/user');
|
const { default: User } = require('../built/models/user');
|
||||||
|
|
||||||
const q = {
|
const q = {
|
||||||
|
@ -33,21 +31,37 @@ async function main() {
|
||||||
|
|
||||||
prev = file;
|
prev = file;
|
||||||
|
|
||||||
if (file == null) return res([i, null]);
|
function skip() {
|
||||||
|
res([i, file, false]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file == null) return skip();
|
||||||
|
|
||||||
|
log(chalk`{gray ${i}} scanning {bold ${file._id}} ${file.filename} ...`);
|
||||||
|
|
||||||
|
const attachingUsersCount = await User.count({
|
||||||
|
$or: [{
|
||||||
|
avatarId: file._id
|
||||||
|
}, {
|
||||||
|
bannerId: file._id
|
||||||
|
}]
|
||||||
|
}, { limit: 1 });
|
||||||
|
if (attachingUsersCount !== 0) return skip();
|
||||||
|
|
||||||
|
Promise.all([
|
||||||
// チャンクをすべて削除
|
// チャンクをすべて削除
|
||||||
await DriveFileChunk.remove({
|
DriveFileChunk.remove({
|
||||||
files_id: file._id
|
files_id: file._id
|
||||||
});
|
}),
|
||||||
|
|
||||||
await DriveFile.update({ _id: file._id }, {
|
DriveFile.update({ _id: file._id }, {
|
||||||
$set: {
|
$set: {
|
||||||
'metadata.deletedAt': new Date(),
|
'metadata.deletedAt': new Date(),
|
||||||
'metadata.isExpired': true
|
'metadata.isExpired': true
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
]).then(() => {
|
||||||
res([i, file]);
|
res([i, file, true]);
|
||||||
|
|
||||||
//#region サムネイルもあれば削除
|
//#region サムネイルもあれば削除
|
||||||
const thumbnail = await DriveFileThumbnail.findOne({
|
const thumbnail = await DriveFileThumbnail.findOne({
|
||||||
|
@ -63,11 +77,16 @@ async function main() {
|
||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
promise.then(([i, file]) => {
|
promise.then(([i, file, deleted]) => {
|
||||||
if (file) {
|
if (deleted) {
|
||||||
console.log(chalk`{gray ${i}} {green done: {bold ${file._id}} ${file.filename}}`);
|
log(chalk`{gray ${i}} {red deleted: {bold ${file._id}} ${file.filename}}`);
|
||||||
|
} else {
|
||||||
|
log(chalk`{gray ${i}} {green skipped: {bold ${file._id}} ${file.filename}}`);
|
||||||
}
|
}
|
||||||
|
log.clear();
|
||||||
|
console.log();
|
||||||
});
|
});
|
||||||
|
|
||||||
return promise;
|
return promise;
|
||||||
|
|
|
@ -16,10 +16,6 @@ async function main() {
|
||||||
for (let i = 0; i < count; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
promiseGens.push(() => {
|
promiseGens.push(() => {
|
||||||
const promise = new Promise(async (res, rej) => {
|
const promise = new Promise(async (res, rej) => {
|
||||||
function skip() {
|
|
||||||
res([i, file, false]);
|
|
||||||
}
|
|
||||||
|
|
||||||
const file = await DriveFile.findOne(prev ? {
|
const file = await DriveFile.findOne(prev ? {
|
||||||
_id: { $lt: prev._id }
|
_id: { $lt: prev._id }
|
||||||
} : {}, {
|
} : {}, {
|
||||||
|
@ -30,6 +26,10 @@ async function main() {
|
||||||
|
|
||||||
prev = file;
|
prev = file;
|
||||||
|
|
||||||
|
function skip() {
|
||||||
|
res([i, file, false]);
|
||||||
|
}
|
||||||
|
|
||||||
if (file == null) return skip();
|
if (file == null) return skip();
|
||||||
|
|
||||||
log(chalk`{gray ${i}} scanning {bold ${file._id}} ${file.filename} ...`);
|
log(chalk`{gray ${i}} scanning {bold ${file._id}} ${file.filename} ...`);
|
||||||
|
|
Loading…
Reference in a new issue