This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"version": "0.8.2",
|
||||
"version": "0.9.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<section class="px-6 py-20 md:px-12 max-w-7xl mx-auto">
|
||||
<h2 class="text-3xl md:text-4xl font-bold text-center mb-14">
|
||||
🌍 Статус серверов
|
||||
Статус серверов
|
||||
</h2>
|
||||
|
||||
<div v-if="loading" class="flex justify-center py-12">
|
||||
@@ -12,49 +12,41 @@
|
||||
|
||||
<div v-else class="space-y-3 max-w-3xl mx-auto">
|
||||
<div
|
||||
v-for="node in nodes"
|
||||
:key="node.name"
|
||||
v-for="host in hosts"
|
||||
:key="host.address"
|
||||
class="flex items-center justify-between bg-white dark:bg-gray-900 rounded-xl px-4 py-3 border transition hover:shadow-md"
|
||||
:class="node.isOnline ? 'border-green-500/30' : 'border-red-500/30 opacity-60'"
|
||||
:class="host.isOnline ? 'border-green-500/30' : 'border-red-500/30 opacity-60'"
|
||||
>
|
||||
<div class="flex items-center gap-3">
|
||||
<img
|
||||
v-if="getCountryCode(node.country_code)"
|
||||
:src="`https://cdn.jsdelivr.net/npm/flag-icons@7.2.3/flags/4x3/${getCountryCode(node.country_code)}.svg`"
|
||||
v-if="host.countryCode"
|
||||
:src="`https://cdn.jsdelivr.net/npm/flag-icons@7.2.3/flags/4x3/${host.countryCode}.svg`"
|
||||
class="h-5 w-auto rounded-sm"
|
||||
/>
|
||||
<span class="font-semibold text-gray-800 dark:text-white">{{ node.name }}</span>
|
||||
<span class="font-semibold text-gray-800 dark:text-white">{{ host.cleanName }}</span>
|
||||
<span
|
||||
class="text-[10px] px-2 py-0.5 rounded-full font-medium"
|
||||
:class="node.isOnline ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-700'"
|
||||
:class="host.isOnline ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-700'"
|
||||
>
|
||||
{{ node.isOnline ? 'online' : 'offline' }}
|
||||
{{ host.isOnline ? 'online' : 'offline' }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-4 text-sm text-gray-500 dark:text-gray-400">
|
||||
<span class="flex items-center gap-1">
|
||||
<Users :size="14" />
|
||||
{{ node.users_online }}
|
||||
</span>
|
||||
<span class="flex items-center gap-1">
|
||||
<Clock :size="14" />
|
||||
{{ formatUptime(node.uptime) }}
|
||||
</span>
|
||||
<span
|
||||
v-if="node.ping !== undefined && node.ping !== null"
|
||||
v-if="host.ping !== undefined && host.ping !== null"
|
||||
class="font-mono font-semibold flex items-center gap-1"
|
||||
:class="{
|
||||
'text-green-600': node.ping < 50,
|
||||
'text-yellow-600': node.ping >= 50 && node.ping < 150,
|
||||
'text-orange-600': node.ping >= 150 && node.ping < 300,
|
||||
'text-red-600': node.ping >= 300,
|
||||
'text-green-600': host.ping < 50,
|
||||
'text-yellow-600': host.ping >= 50 && host.ping < 150,
|
||||
'text-orange-600': host.ping >= 150 && host.ping < 300,
|
||||
'text-red-600': host.ping >= 300,
|
||||
}"
|
||||
>
|
||||
<Wifi :size="14" />
|
||||
{{ node.ping }}ms
|
||||
{{ host.ping }}ms
|
||||
</span>
|
||||
<span v-else class="text-gray-300">⏳</span>
|
||||
<span v-else class="text-gray-300">—</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -63,51 +55,78 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, onUnmounted } from 'vue'
|
||||
import { Users, Clock, Wifi } from '@lucide/vue'
|
||||
import { Wifi } from '@lucide/vue'
|
||||
import { getAllCountries } from '@tw-labs/countries'
|
||||
|
||||
const nodes = ref([])
|
||||
const hosts = ref([])
|
||||
const loading = ref(true)
|
||||
const error = ref(null)
|
||||
let interval = null
|
||||
|
||||
const countryMap = { RU:'ru', FI:'fi', SE:'se', US:'us', PL:'pl', LV:'lv', NL:'nl', DE:'de' }
|
||||
const getCountryCode = (c) => countryMap[c] || null
|
||||
const countriesList = getAllCountries()
|
||||
|
||||
const formatUptime = (s) => {
|
||||
if (!s) return '0м'
|
||||
const d = Math.floor(s / 86400)
|
||||
const h = Math.floor((s % 86400) / 3600)
|
||||
const m = Math.floor((s % 3600) / 60)
|
||||
return d > 0 ? `${d}д ${h}ч` : h > 0 ? `${h}ч ${m}м` : `${m}м`
|
||||
// Поиск страны по названию (из IpSecurity.vue)
|
||||
const findCountryByName = (countryName) => {
|
||||
if (!countryName) return null
|
||||
const found = countriesList.find(c => c.label.toLowerCase() === countryName.toLowerCase())
|
||||
if (found) return found
|
||||
const partial = countriesList.find(c =>
|
||||
countryName.toLowerCase().includes(c.label.toLowerCase()) ||
|
||||
c.label.toLowerCase().includes(countryName.toLowerCase())
|
||||
)
|
||||
return partial || null
|
||||
}
|
||||
|
||||
// --- Новый метод пинга через HTTP HEAD ---
|
||||
const pingNode = async (node) => {
|
||||
// Очистка имени от эмодзи и лишних символов
|
||||
const cleanName = (name) => {
|
||||
return name.replace(/^[🇷🇺🇫🇮🇸🇪🇺🇸🇵🇱🇱🇻🇳🇱🇩🇪]\s*/, '').replace(/[🚀⭐🔥]/g, '').trim()
|
||||
}
|
||||
|
||||
// Извлечение названия страны из name (удаляем эмодзи)
|
||||
const extractCountryName = (name) => {
|
||||
const cleaned = cleanName(name)
|
||||
return cleaned.replace(/\s*\d+$/, '').trim() // убираем цифры в конце (например "Finland 2" -> "Finland")
|
||||
}
|
||||
|
||||
// Пинг через fetch (работает даже с невалидным сертификатом)
|
||||
const pingHost = async (host) => {
|
||||
const url = `https://${host.address}:${host.port}`
|
||||
const start = performance.now()
|
||||
const url = `https://${node.ip}:${node.port}`
|
||||
|
||||
try {
|
||||
await fetch(url, {
|
||||
method: 'HEAD',
|
||||
mode: 'no-cors',
|
||||
cache: 'no-cache',
|
||||
signal: AbortSignal.timeout(3000),
|
||||
signal: AbortSignal.timeout(5000),
|
||||
})
|
||||
return Math.round(performance.now() - start)
|
||||
} catch {
|
||||
return null
|
||||
return Math.round(performance.now() - start)
|
||||
}
|
||||
}
|
||||
|
||||
const fetchNodes = async () => {
|
||||
const fetchHosts = async () => {
|
||||
try {
|
||||
const res = await fetch('/api/v1/nodes')
|
||||
const res = await fetch('/api/v1/hosts')
|
||||
if (!res.ok) throw new Error()
|
||||
const data = await res.json()
|
||||
nodes.value = data.map((n) => ({ ...n, isOnline: true, ping: null }))
|
||||
|
||||
const pings = await Promise.all(nodes.value.map((n) => pingNode(n)))
|
||||
nodes.value.forEach((n, i) => (n.ping = pings[i]))
|
||||
hosts.value = data.map((h) => {
|
||||
const countryName = extractCountryName(h.name)
|
||||
const country = findCountryByName(countryName)
|
||||
|
||||
return {
|
||||
...h,
|
||||
cleanName: cleanName(h.name),
|
||||
countryCode: 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 = 'Ошибка загрузки'
|
||||
} finally {
|
||||
@@ -116,8 +135,8 @@ const fetchNodes = async () => {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchNodes()
|
||||
interval = setInterval(fetchNodes, 30000)
|
||||
fetchHosts()
|
||||
interval = setInterval(fetchHosts, 30000)
|
||||
})
|
||||
onUnmounted(() => clearInterval(interval))
|
||||
</script>
|
||||
Reference in New Issue
Block a user