Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a38b3f7fa | ||
|
|
b69cc4bc4b |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "frontend",
|
"name": "frontend",
|
||||||
"version": "0.9.0",
|
"version": "0.9.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -4,17 +4,28 @@
|
|||||||
Статус серверов
|
Статус серверов
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<div v-if="loading" class="flex justify-center py-12">
|
<div class="flex justify-end mb-4">
|
||||||
|
<button
|
||||||
|
@click="refreshData"
|
||||||
|
:disabled="loading"
|
||||||
|
class="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg text-sm font-medium transition disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2"
|
||||||
|
>
|
||||||
|
<RefreshCw :size="16" :class="{ 'animate-spin': loading }" />
|
||||||
|
{{ loading ? 'Обновление...' : 'Обновить все' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="loading && !hosts.length" class="flex justify-center py-12">
|
||||||
<div class="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"></div>
|
<div class="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p v-else-if="error" class="text-center text-red-500 py-12">{{ error }}</p>
|
<p v-else-if="error" class="text-center text-red-500 py-12">{{ error }}</p>
|
||||||
|
|
||||||
<div v-else class="space-y-3 max-w-3xl mx-auto">
|
<div v-else class="space-y-2 max-w-3xl mx-auto">
|
||||||
<div
|
<div
|
||||||
v-for="host in hosts"
|
v-for="host in sortedHosts"
|
||||||
:key="host.address"
|
: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="flex items-center justify-between bg-white dark:bg-gray-900 rounded-xl px-4 py-2.5 border transition hover:shadow-md"
|
||||||
:class="host.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">
|
<div class="flex items-center gap-3">
|
||||||
@@ -23,7 +34,7 @@
|
|||||||
: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}.svg`"
|
||||||
class="h-5 w-auto rounded-sm"
|
class="h-5 w-auto rounded-sm"
|
||||||
/>
|
/>
|
||||||
<span class="font-semibold text-gray-800 dark:text-white">{{ host.cleanName }}</span>
|
<span class="font-semibold text-gray-800 dark:text-white">{{ host.name }}</span>
|
||||||
<span
|
<span
|
||||||
class="text-[10px] px-2 py-0.5 rounded-full font-medium"
|
class="text-[10px] px-2 py-0.5 rounded-full font-medium"
|
||||||
:class="host.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'"
|
||||||
@@ -32,21 +43,35 @@
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex items-center gap-4 text-sm text-gray-500 dark:text-gray-400">
|
<div class="flex items-center gap-4">
|
||||||
|
<!-- Пинг -->
|
||||||
<span
|
<span
|
||||||
v-if="host.ping !== undefined && host.ping !== null"
|
v-if="host.ping !== undefined && host.ping !== null"
|
||||||
class="font-mono font-semibold flex items-center gap-1"
|
class="font-mono font-semibold flex items-center gap-1 min-w-[60px] justify-end"
|
||||||
:class="{
|
:class="{
|
||||||
'text-green-600': host.ping < 50,
|
'text-green-600': host.ping < 200,
|
||||||
'text-yellow-600': host.ping >= 50 && host.ping < 150,
|
'text-yellow-600': host.ping >= 200 && host.ping < 500,
|
||||||
'text-orange-600': host.ping >= 150 && host.ping < 300,
|
'text-red-600': host.ping >= 500,
|
||||||
'text-red-600': host.ping >= 300,
|
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<Wifi :size="14" />
|
<Wifi :size="14" />
|
||||||
{{ host.ping }}ms
|
{{ host.ping }}ms
|
||||||
</span>
|
</span>
|
||||||
<span v-else class="text-gray-300">—</span>
|
<span v-else class="text-gray-300 min-w-[60px] text-right">—</span>
|
||||||
|
|
||||||
|
<!-- Кнопка пинга -->
|
||||||
|
<button
|
||||||
|
@click="pingSingleHost(host)"
|
||||||
|
:disabled="host.pinging"
|
||||||
|
class="text-xs px-3 py-1 rounded-lg transition font-medium"
|
||||||
|
:class="[
|
||||||
|
host.isOnline && !host.pinging
|
||||||
|
? 'bg-gray-200 dark:bg-gray-700 text-gray-700 dark:text-gray-300 hover:bg-gray-300 dark:hover:bg-gray-600'
|
||||||
|
: 'bg-gray-100 dark:bg-gray-800 text-gray-400 cursor-not-allowed'
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
{{ host.pinging ? '⏳' : 'Пинг' }}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -54,8 +79,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted, onUnmounted } from 'vue'
|
import { ref, computed, onMounted, onUnmounted } from 'vue'
|
||||||
import { Wifi } from '@lucide/vue'
|
import { Wifi, RefreshCw } from '@lucide/vue'
|
||||||
import { getAllCountries } from '@tw-labs/countries'
|
import { getAllCountries } from '@tw-labs/countries'
|
||||||
|
|
||||||
const hosts = ref([])
|
const hosts = ref([])
|
||||||
@@ -65,7 +90,6 @@ let interval = null
|
|||||||
|
|
||||||
const countriesList = getAllCountries()
|
const countriesList = getAllCountries()
|
||||||
|
|
||||||
// Поиск страны по названию (из IpSecurity.vue)
|
|
||||||
const findCountryByName = (countryName) => {
|
const findCountryByName = (countryName) => {
|
||||||
if (!countryName) return null
|
if (!countryName) return null
|
||||||
const found = countriesList.find(c => c.label.toLowerCase() === countryName.toLowerCase())
|
const found = countriesList.find(c => c.label.toLowerCase() === countryName.toLowerCase())
|
||||||
@@ -77,18 +101,29 @@ const findCountryByName = (countryName) => {
|
|||||||
return partial || null
|
return partial || null
|
||||||
}
|
}
|
||||||
|
|
||||||
// Очистка имени от эмодзи и лишних символов
|
// Сортировка по пингу (меньше -> выше)
|
||||||
const cleanName = (name) => {
|
const sortedHosts = computed(() => {
|
||||||
return name.replace(/^[🇷🇺🇫🇮🇸🇪🇺🇸🇵🇱🇱🇻🇳🇱🇩🇪]\s*/, '').replace(/[🚀⭐🔥]/g, '').trim()
|
return [...hosts.value].sort((a, b) => {
|
||||||
|
// Если пинг null -> в конец
|
||||||
|
if (a.ping === null && b.ping === null) return 0
|
||||||
|
if (a.ping === null) return 1
|
||||||
|
if (b.ping === null) return -1
|
||||||
|
return a.ping - b.ping
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// Пинг одного хоста
|
||||||
|
const pingSingleHost = async (host) => {
|
||||||
|
if (host.pinging || !host.isOnline) return
|
||||||
|
host.pinging = true
|
||||||
|
host.ping = null
|
||||||
|
|
||||||
|
const result = await pingHost(host)
|
||||||
|
host.ping = result
|
||||||
|
host.pinging = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Извлечение названия страны из name (удаляем эмодзи)
|
// Пинг через fetch
|
||||||
const extractCountryName = (name) => {
|
|
||||||
const cleaned = cleanName(name)
|
|
||||||
return cleaned.replace(/\s*\d+$/, '').trim() // убираем цифры в конце (например "Finland 2" -> "Finland")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Пинг через fetch (работает даже с невалидным сертификатом)
|
|
||||||
const pingHost = async (host) => {
|
const pingHost = async (host) => {
|
||||||
const url = `https://${host.address}:${host.port}`
|
const url = `https://${host.address}:${host.port}`
|
||||||
const start = performance.now()
|
const start = performance.now()
|
||||||
@@ -106,6 +141,19 @@ const pingHost = async (host) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Пинг всех хостов
|
||||||
|
const pingAllHosts = async () => {
|
||||||
|
const pings = await Promise.all(
|
||||||
|
hosts.value.map(async (h) => {
|
||||||
|
if (!h.isOnline) return null
|
||||||
|
return await pingHost(h)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
hosts.value.forEach((h, i) => {
|
||||||
|
if (h.isOnline) h.ping = pings[i]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const fetchHosts = async () => {
|
const fetchHosts = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/v1/hosts')
|
const res = await fetch('/api/v1/hosts')
|
||||||
@@ -113,20 +161,17 @@ const fetchHosts = async () => {
|
|||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
|
|
||||||
hosts.value = data.map((h) => {
|
hosts.value = data.map((h) => {
|
||||||
const countryName = extractCountryName(h.name)
|
const country = findCountryByName(h.name)
|
||||||
const country = findCountryByName(countryName)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...h,
|
...h,
|
||||||
cleanName: cleanName(h.name),
|
|
||||||
countryCode: country?.code?.toLowerCase() || null,
|
countryCode: country?.code?.toLowerCase() || null,
|
||||||
isOnline: true,
|
isOnline: true,
|
||||||
ping: null,
|
ping: null,
|
||||||
|
pinging: false,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const pings = await Promise.all(hosts.value.map((h) => pingHost(h)))
|
await pingAllHosts()
|
||||||
hosts.value.forEach((h, i) => (h.ping = pings[i]))
|
|
||||||
} catch {
|
} catch {
|
||||||
error.value = 'Ошибка загрузки'
|
error.value = 'Ошибка загрузки'
|
||||||
} finally {
|
} finally {
|
||||||
@@ -134,9 +179,15 @@ const fetchHosts = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const refreshData = async () => {
|
||||||
|
loading.value = true
|
||||||
|
await fetchHosts()
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchHosts()
|
fetchHosts()
|
||||||
interval = setInterval(fetchHosts, 30000)
|
interval = setInterval(refreshData, 30000)
|
||||||
})
|
})
|
||||||
onUnmounted(() => clearInterval(interval))
|
onUnmounted(() => clearInterval(interval))
|
||||||
</script>
|
</script>s
|
||||||
Reference in New Issue
Block a user