mirror of https://gitgud.io/fatchan/jschan.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
750 B
32 lines
750 B
'use strict';
|
|
|
|
const Files = require(__dirname+'/../db/files.js')
|
|
, { remove } = require('fs-extra')
|
|
, uploadDirectory = require(__dirname+'/../helpers/files/uploadDirectory.js');
|
|
|
|
module.exports = async() => {
|
|
//todo: make this not a race condition, but it only happens daily so ¯\_(ツ)_/¯
|
|
const files = await Files.db.find({
|
|
'count': {
|
|
'$lt': 1
|
|
}
|
|
}, {
|
|
'projection': {
|
|
'count': 0,
|
|
'size': 0
|
|
}
|
|
}).toArray().then(res => {
|
|
return res.map(x => x._id);
|
|
});
|
|
await Files.db.removeMany({
|
|
'count': {
|
|
'$lte': 0
|
|
}
|
|
});
|
|
await Promise.all(files.map(async filename => {
|
|
return Promise.all([
|
|
remove(`${uploadDirectory}img/${filename}`),
|
|
remove(`${uploadDirectory}img/thumb-${filename.split('.')[0]}.jpg`)
|
|
])
|
|
}));
|
|
}
|
|
|