Skip to content

Commit

Permalink
add cleanup for ratelimit table
Browse files Browse the repository at this point in the history
  • Loading branch information
nokonoko committed Nov 10, 2023
1 parent 0206604 commit f195c75
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
9 changes: 9 additions & 0 deletions src/Classes/expireChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ public function checkDB(): bool | array {
}
}

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);
Expand Down
2 changes: 1 addition & 1 deletion src/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dest": "dist",
"pkgVersion": "1.8.1",
"pkgVersion": "1.8.2",
"pages": [
"index.ejs",
"faq.ejs",
Expand Down
2 changes: 1 addition & 1 deletion src/static/php/checkExpire.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

$check = new expireChecker();
$dbResult = $check->checkDB();

$check->cleanRateLimitDB();
if(empty($dbResult['ids'])){
echo "No file(s) expired, nothing to do.";
} else {
Expand Down

0 comments on commit f195c75

Please sign in to comment.