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.
26 lines
719 B
26 lines
719 B
5 years ago
|
'use strict';
|
||
|
|
||
|
const { stat, remove, readdir } = require('fs-extra')
|
||
|
, uploadDirectory = require(__dirname+'/../files/uploadDirectory.js')
|
||
|
, msTime = require(__dirname+'/../mstime.js')
|
||
|
|
||
|
module.exports = async () => {
|
||
|
const files = await readdir(`${uploadDirectory}captcha/`);
|
||
|
if (files.length > 0) {
|
||
|
files.forEach(async (file) => {
|
||
|
try {
|
||
|
const filePath = `${uploadDirectory}captcha/${file}`;
|
||
|
const stats = await stat(filePath);
|
||
|
const now = Date.now();
|
||
|
const expiry = new Date(stats.ctime).getTime() + msTime.minute*5;
|
||
|
if (now > expiry) {
|
||
|
await remove(filePath);
|
||
|
console.log(`Deleted expired captcha ${filePath}`)
|
||
|
}
|
||
|
} catch (e) {
|
||
|
console.error(e);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|