Implement lazy-cleanup for expired invoices with deadline-based deletion

This commit is contained in:
Alexander Schmidt
2026-03-26 11:01:32 +01:00
parent c4e3f3cd15
commit ee0d0d4124
5 changed files with 50 additions and 8 deletions

View File

@@ -24,6 +24,7 @@ $dbFile = __DIR__ . '/../data/urls.json';
$rawInput = file_get_contents('php://input');
$input = is_string($rawInput) ? json_decode($rawInput, true) : null;
$hash = is_array($input) && isset($input['hash']) && is_string($input['hash']) ? $input['hash'] : '';
$expiryTs = is_array($input) && isset($input['expiry_ts']) ? intval($input['expiry_ts']) : 0;
if (empty($hash) || strlen($hash) > 500 || !preg_match('/^[a-zA-Z0-9%+_=&.-]{1,500}$/', $hash)) {
http_response_code(400);
@@ -69,6 +70,9 @@ while (isset($urls[$code])) {
$signature = hash_hmac('sha256', $hash, $secret);
$urls[$code] = ['h' => $hash, 's' => $signature];
if ($expiryTs > 0) {
$urls[$code]['e'] = $expiryTs;
}
write_json_locked($fp, $urls);