From ecf674fe3da09c977f33c4b7a2de5f0d067df112 Mon Sep 17 00:00:00 2001 From: gravel Date: Tue, 23 May 2023 12:05:18 +0000 Subject: [PATCH] Re-fetch QR codes after 12 hours --- php/utils/room-icons.php | 2 +- php/utils/room-invites.php | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/php/utils/room-icons.php b/php/utils/room-icons.php index 9181284..9f135dc 100644 --- a/php/utils/room-icons.php +++ b/php/utils/room-icons.php @@ -58,7 +58,7 @@ log_debug("Fetching icon for $room_id."); $icon = file_get_contents($icon_url); if (empty($icon)) { - log_info("$room_id returned empty icon."); + log_info("$room_id returned an empty icon."); } // Never overwrite with an empty file. if (!(file_exists($icon_cached) && filesize($icon_cached) > 0 && empty($icon))) { diff --git a/php/utils/room-invites.php b/php/utils/room-invites.php index 9cbbfa1..e813a40 100644 --- a/php/utils/room-invites.php +++ b/php/utils/room-invites.php @@ -26,15 +26,20 @@ function room_qr_code($room): string { $room_id = $room->get_room_identifier(); $png_cached = room_qr_code_path($room_id); - if (file_exists($png_cached)) { + $image_expired = file_exists($png_cached) && + filemtime($png_cached) < strtotime("-12 hour"); + if (file_exists($png_cached) && !$image_expired) { return room_qr_code_path_relative($room_id); } log_debug("Fetching QR code for $room_id."); $png = file_get_contents($room->get_invite_url()); if (empty($png)) { - log_warning("$room_id returned empty QR code."); + log_warning("$room_id returned an empty QR code."); + } + // Never overwrite with an empty file. + if (!(file_exists($png_cached) && filesize($png_cached) > 0 && empty($png))) { + file_put_contents($png_cached, $png); } - file_put_contents($png_cached, $png); return room_qr_code_path_relative($room_id); }