*/ function fetch_qr_code_coroutine(CommunityRoom $room): Generator { $room_id = $room->get_room_identifier(); $png_cached = room_qr_code_path($room_id); $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_response = yield from FetchingCoroutine::from_url($room->get_invite_url())->run(); $png = $png_response ? curl_multi_getcontent($png_response) : null; if (empty($png)) { log_warning("$room_id returned an empty QR code."); touch($png_cached); } // Never overwrite with an empty file. if (!(file_exists($png_cached) && filesize($png_cached) > 0 && empty($png))) { file_put_contents($png_cached, $png); } } /** * Fetch QR invite of the given room and return its relative path. * @param CommunityRoom $room * @return string */ function room_qr_code(CommunityRoom $room): string { $room_id = $room->get_room_identifier(); if (!file_exists(room_qr_code_path($room_id))) { log_warning("Missing QR code asset for $room_id."); return ""; } return room_qr_code_path_relative($room_id); } file_exists($QR_CODES) or mkdir($QR_CODES, 0755); ?>