mirror of https://gitgud.io/fatchan/jschan.git
merge-requests/208/head
parent
a7cf529a89
commit
5ce2b42a0e
3 changed files with 29 additions and 29 deletions
@ -0,0 +1,25 @@ |
||||
'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); |
||||
} |
||||
}); |
||||
} |
||||
} |
Loading…
Reference in new issue