mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-23 06:43:08 +02:00
✌️
This commit is contained in:
parent
97b7567770
commit
06c453c3bc
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,41 +31,62 @@ 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();
|
||||||
await DriveFileChunk.remove({
|
|
||||||
files_id: file._id
|
|
||||||
});
|
|
||||||
|
|
||||||
await DriveFile.update({ _id: file._id }, {
|
log(chalk`{gray ${i}} scanning {bold ${file._id}} ${file.filename} ...`);
|
||||||
$set: {
|
|
||||||
'metadata.deletedAt': new Date(),
|
|
||||||
'metadata.isExpired': true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
res([i, file]);
|
const attachingUsersCount = await User.count({
|
||||||
|
$or: [{
|
||||||
|
avatarId: file._id
|
||||||
|
}, {
|
||||||
|
bannerId: file._id
|
||||||
|
}]
|
||||||
|
}, { limit: 1 });
|
||||||
|
if (attachingUsersCount !== 0) return skip();
|
||||||
|
|
||||||
//#region サムネイルもあれば削除
|
Promise.all([
|
||||||
const thumbnail = await DriveFileThumbnail.findOne({
|
// チャンクをすべて削除
|
||||||
'metadata.originalId': file._id
|
DriveFileChunk.remove({
|
||||||
});
|
files_id: file._id
|
||||||
|
}),
|
||||||
|
|
||||||
if (thumbnail) {
|
DriveFile.update({ _id: file._id }, {
|
||||||
DriveFileThumbnailChunk.remove({
|
$set: {
|
||||||
files_id: thumbnail._id
|
'metadata.deletedAt': new Date(),
|
||||||
|
'metadata.isExpired': true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
]).then(() => {
|
||||||
|
res([i, file, true]);
|
||||||
|
|
||||||
|
//#region サムネイルもあれば削除
|
||||||
|
const thumbnail = await DriveFileThumbnail.findOne({
|
||||||
|
'metadata.originalId': file._id
|
||||||
});
|
});
|
||||||
|
|
||||||
DriveFileThumbnail.remove({ _id: thumbnail._id });
|
if (thumbnail) {
|
||||||
}
|
DriveFileThumbnailChunk.remove({
|
||||||
//#endregion
|
files_id: thumbnail._id
|
||||||
|
});
|
||||||
|
|
||||||
|
DriveFileThumbnail.remove({ _id: thumbnail._id });
|
||||||
|
}
|
||||||
|
//#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