Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions hiddifypanel/admin_v2/src/core/api/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ export interface DashboardNodeStats {
name: string
mode: string
panel_url?: string | null
/** The server's country (ISO code) from its address; '' when unknown. */
country?: string
ok: boolean
error?: string | null
error_code?: string | null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import { countryFlag, countryName } from '@/shared/utils/country'
import { computed, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import Tag from 'primevue/tag'
Expand Down Expand Up @@ -31,11 +32,16 @@ const visibleNodes = computed(() =>
const multiNode = computed(() => visibleNodes.value.length > 1)

const nodeTitle = (node: DashboardNodeStats) => (node.id === 0 ? t('dashboard.thisServer') : node.name)
/** The node's country, by its address: the flag before its name, as on the Nodes page. */
const nodeFlag = (node: DashboardNodeStats) => countryFlag(node.country)
const nodeCountry = (node: DashboardNodeStats) => (node.country ? countryName(node.country, locale.value) : '')

const tableRows = computed(() =>
visibleNodes.value.map((node) => ({
id: node.id,
title: nodeTitle(node),
flag: nodeFlag(node),
country: nodeCountry(node),
color: nodeColor(node.id),
panelUrl: node.panel_url ?? null,
ok: node.ok,
Expand Down Expand Up @@ -225,6 +231,7 @@ const largestFolder = computed(() => diskDetail.value?.top_folders[0]?.size_gb ?
<div v-if="multiNode" class="node-health__legend">
<span v-for="node in tableRows" :key="node.id" class="node-health__legend-item">
<span class="node-health__dot" :style="{ background: node.color }" />
<span v-if="node.flag" class="node-flag" :title="node.country" :aria-label="node.country">{{ node.flag }}</span>
{{ node.title }}
</span>
</div>
Expand Down Expand Up @@ -301,11 +308,11 @@ const largestFolder = computed(() => diskDetail.value?.top_folders[0]?.size_gb ?
<template #body="{ data }">
<span class="node-cell__dot" :style="{ background: data.color }" />
<a v-if="data.panelUrl" :href="data.panelUrl" target="_blank" rel="noopener" class="min-w-0 node-cell__title node-cell__link">
<strong>{{ data.title }} <i class="pi pi-external-link" /></strong>
<strong><span v-if="data.flag" class="node-flag" :title="data.country" :aria-label="data.country">{{ data.flag }}</span>{{ data.title }} <i class="pi pi-external-link" /></strong>
<p v-if="data.hostname" class="node-cell__host">{{ data.hostname }}</p>
</a>
<div v-else class="min-w-0 node-cell__title">
<strong>{{ data.title }}</strong>
<strong><span v-if="data.flag" class="node-flag" :title="data.country" :aria-label="data.country">{{ data.flag }}</span>{{ data.title }}</strong>
<p v-if="data.hostname" class="node-cell__host">{{ data.hostname }}</p>
</div>
<Tag v-if="!data.ok" :value="t('dashboard.nodeOffline')" severity="danger" class="node-cell__tag" />
Expand Down Expand Up @@ -347,11 +354,11 @@ const largestFolder = computed(() => diskDetail.value?.top_folders[0]?.size_gb ?
<div class="node-list__head">
<span class="node-cell__dot" :style="{ background: data.color }" />
<a v-if="data.panelUrl" :href="data.panelUrl" target="_blank" rel="noopener" class="min-w-0 node-cell__title node-cell__link">
<strong>{{ data.title }} <i class="pi pi-external-link" /></strong>
<strong><span v-if="data.flag" class="node-flag" :title="data.country" :aria-label="data.country">{{ data.flag }}</span>{{ data.title }} <i class="pi pi-external-link" /></strong>
<p v-if="data.hostname" class="node-cell__host">{{ data.hostname }}</p>
</a>
<div v-else class="min-w-0 node-cell__title">
<strong>{{ data.title }}</strong>
<strong><span v-if="data.flag" class="node-flag" :title="data.country" :aria-label="data.country">{{ data.flag }}</span>{{ data.title }}</strong>
<p v-if="data.hostname" class="node-cell__host">{{ data.hostname }}</p>
</div>
<Tag v-if="!data.ok" :value="t('dashboard.nodeOffline')" severity="danger" class="node-cell__tag" />
Expand Down Expand Up @@ -437,6 +444,14 @@ const largestFolder = computed(() => diskDetail.value?.top_folders[0]?.size_gb ?
</template>

<style scoped>
/* The node's country flag before its name; colour emoji fonts first, so the flag shows, not its two letters */
.node-flag {
display: inline-block;
margin-inline-end: 0.35rem;
font-size: 1.1em;
line-height: 1;
font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
}
.node-health__legend {
display: flex;
flex-wrap: wrap;
Expand Down
16 changes: 3 additions & 13 deletions hiddifypanel/admin_v2/src/features/nodes/views/NodesView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@
</template>

<script setup lang="ts">
import { countryFlag, countryName as countryNameIn } from '@/shared/utils/country'
import { computed, nextTick, onBeforeUnmount, onMounted, onUpdated, reactive, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useToast } from 'primevue/usetoast'
Expand Down Expand Up @@ -455,19 +456,8 @@ async function saveName(node: PanelNode) {
}
}

/** The flag emoji of a country code (two regional indicator letters); '' when there is none. */
function flag(code: string | undefined): string {
const c = (code ?? '').toUpperCase()
if (!/^[A-Z]{2}$/.test(c)) return ''
return String.fromCodePoint(...[...c].map((ch) => 0x1f1e6 + ch.charCodeAt(0) - 65))
}
function countryName(code: string): string {
try {
return new Intl.DisplayNames([locale.value], { type: 'region' }).of(code.toUpperCase()) ?? code
} catch {
return code
}
}
const flag = countryFlag
const countryName = (code: string) => countryNameIn(code, locale.value)

function versionTitle(version?: string): string {
if (!version) return ''
Expand Down
15 changes: 15 additions & 0 deletions hiddifypanel/admin_v2/src/shared/utils/country.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/** The flag emoji of a country code (two regional indicator letters); '' when there is none. */
export function countryFlag(code: string | null | undefined): string {
const c = (code ?? '').toUpperCase()
if (!/^[A-Z]{2}$/.test(c)) return ''
return String.fromCodePoint(...[...c].map((ch) => 0x1f1e6 + ch.charCodeAt(0) - 65))
}

/** A country code's name in the given language ("DE" → "Germany"); the code itself when unknown. */
export function countryName(code: string, locale: string): string {
try {
return new Intl.DisplayNames([locale], { type: 'region' }).of(code.toUpperCase()) ?? code
} catch {
return code
}
}
19 changes: 19 additions & 0 deletions hiddifypanel/hutils/node_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,25 @@ def attach_panel_urls(node_stats: list[DashboardNodeStats], account_uuid: str, a
row.panel_url = f"{base}/{account_uuid}/" if base else hurl_for('flask.node.edit_view', id=row.id)


def attach_countries(node_stats: list[DashboardNodeStats]) -> None:
"""Each node's country from its address, as on the Nodes page (cached a day); this server's from its own public IP."""
from hiddifypanel.panel.commercial.restapi.v2.admin.nodes_api import node_country

remote_ids = [row.id for row in node_stats if row.id != 0 and not is_debug_node(row.id)]
hosts = {}
if remote_ids:
for child in Child.query.filter(Child.id.in_(remote_ids)).all():
base = (child.node_base_url or "").strip()
hosts[child.id] = base.split("://", 1)[-1].split("/", 1)[0] if base else ""
own = ""
if any(row.id == 0 or is_debug_node(row.id) for row in node_stats):
# The known public addresses, without waiting for the network on a dashboard poll.
own = next((str(ip) for ip in hutils.network.get_ips_lazy() if ip.is_global), "")
for row in node_stats:
host = own if row.id == 0 or is_debug_node(row.id) else hosts.get(row.id, "")
row.country = node_country(host) if host else ""


def collect_system_stats(child_id: int | None, process_limit: int = 8, debug_nodes: bool = False) -> NodeSystemCollection:
"""Local + every remote node, in parallel.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def get(self) -> DashboardOutputSchema:
live = node_system.collect_system_stats(child_id, process_limit=_process_limit(), debug_nodes=debug_nodes)
admin_base = hiddify.get_account_panel_link(g.account, request.host, prefere_path_only=True) + "admin/"
node_system.attach_panel_urls(live.node_stats, g.account.uuid, admin_base)
node_system.attach_countries(live.node_stats)

dto = DashboardOutputSchema(
generated_at=datetime.datetime.now(datetime.UTC).isoformat(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ class DashboardNodeStats(ApiModel):
mode: str
# Admin panel of the node for the current account; None for this server.
panel_url: str | None = None
# The server's country (ISO code, e.g. "DE") from its address; "" when unknown.
country: str = ""
ok: bool = True
error: str | None = None
# Why the node could not be asked (hutils.node.contact_error): the Nodes page explains it and how to fix it.
Expand Down
Loading