mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-27 13:33:09 +02:00
Update src/tools/clean-remote-files.ts
This commit is contained in:
parent
468bc67569
commit
feef4a933e
1 changed files with 30 additions and 0 deletions
30
src/tools/clean-remote-files.ts
Normal file
30
src/tools/clean-remote-files.ts
Normal file
|
@ -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<any> {
|
||||||
|
file = await DriveFile.findOne({ _id: file._id });
|
||||||
|
|
||||||
|
await del(file, true);
|
||||||
|
|
||||||
|
console.log('done', file._id);
|
||||||
|
}
|
Loading…
Reference in a new issue