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.
47 lines
1.2 KiB
47 lines
1.2 KiB
5 years ago
|
'use strict';
|
||
|
|
||
|
const util = require('util')
|
||
|
, fs = require('fs')
|
||
|
, unlink = util.promisify(fs.unlink)
|
||
|
, stat = util.promisify(fs.stat)
|
||
|
, readdir = util.promisify(fs.readdir)
|
||
5 years ago
|
, uploadDirectory = require(__dirname+'/helpers/files/uploadDirectory.js')
|
||
|
, msTime = require(__dirname+'/helpers/mstime.js')
|
||
|
, Mongo = require(__dirname+'/db/db.js')
|
||
5 years ago
|
|
||
|
async function deleteCaptchas() {
|
||
|
|
||
|
try {
|
||
|
const files = await readdir(`${uploadDirectory}captcha/`);
|
||
|
if (files.length > 0) {
|
||
5 years ago
|
files.forEach(async (file) => {
|
||
5 years ago
|
const filePath = `${uploadDirectory}captcha/${file}`;
|
||
5 years ago
|
const stats = await stat(filePath).catch(e => console.error);
|
||
|
if (!stats) {
|
||
5 years ago
|
return;
|
||
5 years ago
|
}
|
||
|
const now = Date.now();
|
||
|
const expiry = new Date(stats.ctime).getTime() + 6*1000*60; //6 minutes ahead
|
||
|
if (now > expiry) {
|
||
|
await unlink(filePath).catch(e => console.error);
|
||
|
}
|
||
5 years ago
|
});
|
||
|
}
|
||
|
} catch (err) {
|
||
|
console.error(err);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
5 years ago
|
(async () => {
|
||
|
|
||
|
await Mongo.connect();
|
||
|
const { buildHomepage } = require(__dirname+'/helpers/build.js');
|
||
|
buildHomepage();
|
||
|
setInterval(buildHomepage, msTime.hour); //hourly rebuild homepage for posts/day
|
||
|
|
||
|
deleteCaptchas();
|
||
|
setInterval(deleteCaptchas, msTime.minute*6); //delete files for expired captchas
|
||
|
|
||
|
})();
|