This commit is contained in:
Lukian LEIZOUR 2024-03-14 19:14:23 +01:00
parent 9341181f99
commit 236ca371bb
39 changed files with 659 additions and 1531 deletions

26
src/libs/quotaReset.ts Normal file
View file

@ -0,0 +1,26 @@
import * as fs from "fs";
import { connectToDb, resetQuota } from "./mysql";
function getLastResetDate(): number {
const data: string = fs.readFileSync("../data/lastreset.txt", "utf8");
return parseInt(data);
}
export async function checkReset() {
const lastResetDate = getLastResetDate();
const now = Date.now() / 1000;
if (now - lastResetDate > 1000 * 60 * 60 * 24 * 30) {
fs.writeFileSync("../data/lastreset.txt", now.toString());
const connection = await connectToDb();
await resetQuota(connection);
connection.end();
return;
} else {
return false;
}
}