add cleanup for ratelimit table

This commit is contained in:
Go Johansson (neku) 2023-11-10 21:00:10 +01:00
parent 0206604aec
commit f195c753f5
4 changed files with 12 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{
"name": "uguu",
"version": "1.8.1",
"version": "1.8.2",
"description": "Uguu is a simple lightweight temporary file host with support for drop, paste, click and API uploading.",
"homepage": "https://uguu.se",
"repository": {

View File

@ -37,6 +37,15 @@ class expireChecker
}
}
public function cleanRateLimitDB(): void {
$query = match ($this->dbType) {
'pgsql' => 'DELETE FROM ratelimit WHERE time < EXTRACT(epoch from NOW() - INTERVAL \'24 HOURS\')',
default => 'DELETE FROM ratelimit WHERE time <= strftime(\'%s\', datetime(\'now\', \'-24 HOURS\'));'
};
$q = $this->DB->prepare($query);
$q->execute();
$q->closeCursor();
}
public function deleteFiles(array $filenames): void {
foreach ($filenames as $filename) {
unlink($this->CONFIG['FILES_ROOT'] . $filename);

View File

@ -1,6 +1,6 @@
{
"dest": "dist",
"pkgVersion": "1.8.1",
"pkgVersion": "1.8.2",
"pages": [
"index.ejs",
"faq.ejs",

View File

@ -24,7 +24,7 @@ use Pomf\Uguu\Classes\expireChecker;
$check = new expireChecker();
$dbResult = $check->checkDB();
$check->cleanRateLimitDB();
if(empty($dbResult['ids'])){
echo "No file(s) expired, nothing to do.";
} else {