From a6a0cb928ab4967413bd2f4fa0a2fb20a3ea29da Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 27 May 2024 10:27:18 +0200 Subject: [PATCH] fix: force load services from cdn on reload list --- app/Livewire/Project/New/Select.php | 2 +- bootstrap/helpers/shared.php | 35 ++++++++++++++--------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/Livewire/Project/New/Select.php b/app/Livewire/Project/New/Select.php index c56290a06..2b5ef9eca 100644 --- a/app/Livewire/Project/New/Select.php +++ b/app/Livewire/Project/New/Select.php @@ -91,7 +91,7 @@ public function loadServices(bool $force = false) }); } else { $this->search = null; - $this->allServices = get_service_templates(); + $this->allServices = get_service_templates($force); $this->services = $this->allServices->filter(function ($service, $key) { return str_contains(strtolower($key), strtolower($this->search)); }); diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index ee5a52d56..c8c8ee4e9 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -465,25 +465,24 @@ function sslip(Server $server) return "http://{$server->ip}.sslip.io"; } -function get_service_templates() +function get_service_templates(bool $force = false): Collection { - // if (isDev()) { - // $services = File::get(base_path('templates/service-templates.json')); - // $services = collect(json_decode($services))->sortKeys(); - // } else { - // try { - // $response = Http::retry(3, 50)->get(config('constants.services.official')); - // if ($response->failed()) { - // return collect([]); - // } - // $services = $response->json(); - // $services = collect($services)->sortKeys(); - // } catch (\Throwable $e) { - // $services = collect([]); - // } - // } - $services = File::get(base_path('templates/service-templates.json')); - return collect(json_decode($services))->sortKeys(); + if ($force) { + try { + $response = Http::retry(3, 50)->get(config('constants.services.official')); + if ($response->failed()) { + return collect([]); + } + $services = $response->json(); + return collect($services); + } catch (\Throwable $e) { + $services = File::get(base_path('templates/service-templates.json')); + return collect(json_decode($services))->sortKeys(); + } + } else { + $services = File::get(base_path('templates/service-templates.json')); + return collect(json_decode($services))->sortKeys(); + } } function getResourceByUuid(string $uuid, ?int $teamId = null)