From 0d5902ea1f129a3ce1e9ae27d6387235d4881683 Mon Sep 17 00:00:00 2001 From: austnv Date: Sat, 8 Aug 2026 01:27:01 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20src/components/NodesStatus.vue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/NodesStatus.vue | 55 ++++++++++++++++------------------ 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/src/components/NodesStatus.vue b/src/components/NodesStatus.vue index a5e4839..4a8e22c 100644 --- a/src/components/NodesStatus.vue +++ b/src/components/NodesStatus.vue @@ -25,7 +25,7 @@
@@ -35,10 +35,13 @@ :src="`https://cdn.jsdelivr.net/npm/flag-icons@7.2.3/flags/4x3/${host.countryCode.toLowerCase()}.svg`" class="h-5 w-auto rounded-sm" :alt="host.name" + @error="handleFlagError" /> +
+ 🌐 +
{{ host.name }} - {{ host.ping }} ms - +
@@ -88,6 +91,10 @@ const sortedHosts = computed(() => { }) }) +const handleFlagError = (e) => { + e.target.style.display = 'none' +} + const pingHost = async (host) => { const url = `https://${host.address}:${host.port}` const start = performance.now() @@ -105,22 +112,20 @@ const pingHost = async (host) => { } } -const fetchHosts = async () => { +const loadData = async () => { try { const res = await fetch('/api/v1/hosts') - if (!res.ok) throw new Error() + if (!res.ok) throw new Error(`HTTP ${res.status}`) const data = await res.json() - - hosts.value = data.map((h) => ({ + + return data.map((h) => ({ ...h, countryCode: h.country_code ? h.country_code.toLowerCase() : null, isOnline: true, - ping: null, + ping: null })) - } catch { - error.value = 'Ошибка загрузки данных' - } finally { - loading.value = false + } catch (err) { + throw new Error('Ошибка загрузки данных') } } @@ -129,32 +134,22 @@ const refreshData = async () => { error.value = null try { - const res = await fetch('/api/v1/hosts') - if (!res.ok) throw new Error() - const data = await res.json() + const data = await loadData() + hosts.value = data - hosts.value = data.map((h) => ({ - ...h, - countryCode: h.country_code ? h.country_code.toLowerCase() : null, - isOnline: true, - ping: null, - })) - - // Пингуем все хосты параллельно + // Пингуем все хосты const pings = await Promise.all(hosts.value.map(h => pingHost(h))) hosts.value.forEach((h, i) => { h.ping = pings[i] }) - - } catch { - error.value = 'Ошибка обновления данных' + } catch (err) { + error.value = err.message } finally { loading.value = false } } -onMounted(async () => { - await fetchHosts() - await refreshData() +onMounted(() => { + refreshData() }) \ No newline at end of file