fix: force load services from cdn on reload list

This commit is contained in:
Andras Bacsai 2024-05-27 10:27:18 +02:00
parent 8bca988520
commit a6a0cb928a
2 changed files with 18 additions and 19 deletions

View File

@ -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));
});

View File

@ -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([]);
// }
// }
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)