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.
53 lines
1.7 KiB
53 lines
1.7 KiB
const moment = require('moment')
|
|
const rimraf = require('rimraf');
|
|
const fs = require("fs");
|
|
const path = require("path")
|
|
|
|
let TEST = false
|
|
// TEST = true
|
|
|
|
module.exports = function (app, opts) {
|
|
const clearExpiredData = app.fs.scheduleInit(
|
|
{
|
|
interval: '42 24 4 */3 * *',
|
|
immediate: TEST,
|
|
proRun: !TEST,
|
|
},
|
|
async () => {
|
|
try {
|
|
const { models } = app.fs.dc
|
|
const now = moment().format('YYYY-MM-DD HH:mm:ss')
|
|
await models.UserToken.destroy({
|
|
where: {
|
|
expired: { $lt: now }
|
|
}
|
|
})
|
|
await models.PhoneValidateCode.destroy({
|
|
where: {
|
|
expired: { $lt: now }
|
|
}
|
|
})
|
|
fs.readdir(path.join(__dirname, `../../downloadFiles`), function (err, files) {
|
|
if (err) {
|
|
return;
|
|
}
|
|
files.forEach((file) => {
|
|
fs.stat(path.join(__dirname, `../../downloadFiles/${file}`), (err, stats) => {
|
|
if (err) {
|
|
//return;
|
|
} else {
|
|
rimraf.sync(path.join(__dirname, `../../downloadFiles/${file}`));
|
|
}
|
|
});
|
|
});
|
|
});
|
|
} catch (error) {
|
|
app.fs.logger.error(`sechedule: clearExpiredToken, error: ${error}`);
|
|
}
|
|
}
|
|
);
|
|
|
|
return {
|
|
clearExpiredData
|
|
}
|
|
}
|