|
|
|
@@ -1,7 +1,7 @@
|
|
|
|
|
<template>
|
|
|
|
|
<section class="px-6 py-20 md:px-12 max-w-7xl mx-auto">
|
|
|
|
|
<div class="mb-14">
|
|
|
|
|
<h2 class="text-3xl md:text-4xl font-bold text-center">
|
|
|
|
|
<div class="mb-10">
|
|
|
|
|
<h2 class="text-3xl md:text-4xl font-bold text-center mb-14">
|
|
|
|
|
Статус серверов
|
|
|
|
|
</h2>
|
|
|
|
|
<div class="flex justify-center mt-6">
|
|
|
|
@@ -26,25 +26,26 @@
|
|
|
|
|
<div
|
|
|
|
|
v-for="host in sortedHosts"
|
|
|
|
|
:key="host.address"
|
|
|
|
|
class="flex items-center justify-between bg-white dark:bg-gray-900 rounded-xl px-4 py-2.5 border transition hover:shadow-md"
|
|
|
|
|
class="flex items-center justify-between bg-white dark:bg-gray-900 rounded-xl px-4 py-2.5 border"
|
|
|
|
|
:class="host.isOnline ? 'border-green-500/30' : 'border-red-500/30 opacity-60'"
|
|
|
|
|
>
|
|
|
|
|
<div class="flex items-center gap-3">
|
|
|
|
|
<img
|
|
|
|
|
v-if="host.countryCode"
|
|
|
|
|
:src="`https://cdn.jsdelivr.net/npm/flag-icons@7.2.3/flags/4x3/${host.countryCode}.svg`"
|
|
|
|
|
: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"
|
|
|
|
|
/>
|
|
|
|
|
<span class="font-semibold text-gray-800 dark:text-white">{{ host.name }}</span>
|
|
|
|
|
|
|
|
|
|
<!-- Индикатор состояния (вместо online/offline) -->
|
|
|
|
|
<span class="relative flex h-3 w-3">
|
|
|
|
|
<!-- Индикатор состояния -->
|
|
|
|
|
<span class="relative flex h-2 w-2">
|
|
|
|
|
<span
|
|
|
|
|
class="animate-ping absolute inline-flex h-full w-full rounded-full opacity-75"
|
|
|
|
|
:class="host.isOnline ? 'bg-green-500' : 'bg-red-500'"
|
|
|
|
|
></span>
|
|
|
|
|
<span
|
|
|
|
|
class="relative inline-flex rounded-full h-3 w-3"
|
|
|
|
|
class="relative inline-flex rounded-full h-2 w-2"
|
|
|
|
|
:class="host.isOnline ? 'bg-green-600' : 'bg-red-600'"
|
|
|
|
|
></span>
|
|
|
|
|
</span>
|
|
|
|
@@ -73,58 +74,11 @@
|
|
|
|
|
<script setup>
|
|
|
|
|
import { ref, computed, onMounted } from 'vue'
|
|
|
|
|
import { Wifi, RefreshCw } from '@lucide/vue'
|
|
|
|
|
import { getAllCountries } from '@tw-labs/countries'
|
|
|
|
|
|
|
|
|
|
const hosts = ref([])
|
|
|
|
|
const loading = ref(true)
|
|
|
|
|
const error = ref(null)
|
|
|
|
|
|
|
|
|
|
const countriesList = getAllCountries()
|
|
|
|
|
|
|
|
|
|
// Ручной маппинг для проблемных стран
|
|
|
|
|
const countryOverrides = {
|
|
|
|
|
'United States': 'us',
|
|
|
|
|
'USA': 'us',
|
|
|
|
|
'U.S.A.': 'us',
|
|
|
|
|
'America': 'us',
|
|
|
|
|
'United Arab Emirates': 'ae',
|
|
|
|
|
'UAE': 'ae',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const findCountryByFirstWord = (name) => {
|
|
|
|
|
if (!name) return null
|
|
|
|
|
|
|
|
|
|
// 1. Проверяем ручные override
|
|
|
|
|
const override = countryOverrides[name]
|
|
|
|
|
if (override) {
|
|
|
|
|
return { code: override.toUpperCase() }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. Ищем по первому слову
|
|
|
|
|
const firstWord = name.split(' ')[0]
|
|
|
|
|
if (!firstWord) return null
|
|
|
|
|
|
|
|
|
|
// Точное совпадение
|
|
|
|
|
const exact = countriesList.find(c =>
|
|
|
|
|
c.label.toLowerCase() === firstWord.toLowerCase()
|
|
|
|
|
)
|
|
|
|
|
if (exact) return exact
|
|
|
|
|
|
|
|
|
|
// Частичное совпадение
|
|
|
|
|
const partial = countriesList.find(c =>
|
|
|
|
|
firstWord.toLowerCase().includes(c.label.toLowerCase()) ||
|
|
|
|
|
c.label.toLowerCase().includes(firstWord.toLowerCase())
|
|
|
|
|
)
|
|
|
|
|
if (partial) return partial
|
|
|
|
|
|
|
|
|
|
// 3. Пробуем найти по полному имени
|
|
|
|
|
const fullMatch = countriesList.find(c =>
|
|
|
|
|
name.toLowerCase().includes(c.label.toLowerCase()) ||
|
|
|
|
|
c.label.toLowerCase().includes(name.toLowerCase())
|
|
|
|
|
)
|
|
|
|
|
return fullMatch || null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const sortedHosts = computed(() => {
|
|
|
|
|
return [...hosts.value].sort((a, b) => {
|
|
|
|
|
if (a.ping === null && b.ping === null) return 0
|
|
|
|
@@ -157,17 +111,14 @@ const fetchHosts = async () => {
|
|
|
|
|
if (!res.ok) throw new Error()
|
|
|
|
|
const data = await res.json()
|
|
|
|
|
|
|
|
|
|
hosts.value = data.map((h) => {
|
|
|
|
|
const country = findCountryByFirstWord(h.name)
|
|
|
|
|
return {
|
|
|
|
|
hosts.value = data.map((h) => ({
|
|
|
|
|
...h,
|
|
|
|
|
countryCode: country?.code?.toLowerCase() || null,
|
|
|
|
|
countryCode: h.country_code ? h.country_code.toLowerCase() : null,
|
|
|
|
|
isOnline: true,
|
|
|
|
|
ping: null,
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}))
|
|
|
|
|
} catch {
|
|
|
|
|
error.value = 'Ошибка загрузки'
|
|
|
|
|
error.value = 'Ошибка загрузки данных'
|
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false
|
|
|
|
|
}
|
|
|
|
@@ -182,32 +133,28 @@ const refreshData = async () => {
|
|
|
|
|
if (!res.ok) throw new Error()
|
|
|
|
|
const data = await res.json()
|
|
|
|
|
|
|
|
|
|
hosts.value = data.map((h) => {
|
|
|
|
|
const country = findCountryByFirstWord(h.name)
|
|
|
|
|
return {
|
|
|
|
|
hosts.value = data.map((h) => ({
|
|
|
|
|
...h,
|
|
|
|
|
countryCode: country?.code?.toLowerCase() || null,
|
|
|
|
|
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) => {
|
|
|
|
|
if (h.isOnline) h.ping = pings[i]
|
|
|
|
|
h.ping = pings[i]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
} catch {
|
|
|
|
|
error.value = 'Ошибка обновления'
|
|
|
|
|
error.value = 'Ошибка обновления данных'
|
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// При первом открытии — загружаем и пингуем
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
await fetchHosts()
|
|
|
|
|
// Автоматический пинг только при первом открытии
|
|
|
|
|
await refreshData()
|
|
|
|
|
})
|
|
|
|
|
</script>
|