fix(global): use iso_a3_eh

This commit is contained in:
hamster1963 2024-11-26 17:50:49 +08:00
parent 269e2fcd13
commit 2c6dcdf53f
2 changed files with 10 additions and 8 deletions

View File

@ -7,14 +7,14 @@ import { InteractiveMap } from "./InteractiveMap";
export default async function ServerGlobal() { export default async function ServerGlobal() {
const nezhaServerList = await GetNezhaData(); const nezhaServerList = await GetNezhaData();
const countrytList: string[] = []; const countryList: string[] = [];
const serverCounts: { [key: string]: number } = {}; const serverCounts: { [key: string]: number } = {};
nezhaServerList.result.forEach((server) => { nezhaServerList.result.forEach((server) => {
if (server.host.CountryCode) { if (server.host.CountryCode) {
const countryCode = server.host.CountryCode.toUpperCase(); const countryCode = server.host.CountryCode.toUpperCase();
if (!countrytList.includes(countryCode)) { if (!countryList.includes(countryCode)) {
countrytList.push(countryCode); countryList.push(countryCode);
} }
serverCounts[countryCode] = (serverCounts[countryCode] || 0) + 1; serverCounts[countryCode] = (serverCounts[countryCode] || 0) + 1;
} }
@ -25,15 +25,15 @@ export default async function ServerGlobal() {
const geoJson = JSON.parse(geoJsonString); const geoJson = JSON.parse(geoJsonString);
const filteredFeatures = geoJson.features.filter( const filteredFeatures = geoJson.features.filter(
(feature: any) => feature.properties.iso_a3 !== "", (feature: any) => feature.properties.iso_a3_eh !== "",
); );
return ( return (
<section className="flex flex-col gap-4 mt-[3.2px]"> <section className="flex flex-col gap-4 mt-[3.2px]">
<GlobalInfo countries={countrytList} /> <GlobalInfo countries={countryList} />
<div className="w-full overflow-x-auto"> <div className="w-full overflow-x-auto">
<InteractiveMap <InteractiveMap
countries={countrytList} countries={countryList}
serverCounts={serverCounts} serverCounts={serverCounts}
width={width} width={width}
height={height} height={height}

View File

@ -57,11 +57,13 @@ export function InteractiveMap({
<g> <g>
{filteredFeatures.map((feature, index) => { {filteredFeatures.map((feature, index) => {
const isHighlighted = countries_alpha3.includes( const isHighlighted = countries_alpha3.includes(
feature.properties.iso_a3, feature.properties.iso_a3_eh,
); );
const countryCode = Object.entries(countryCodeMapping).find( const countryCode = Object.entries(countryCodeMapping).find(
([, alpha3]) => alpha3 === feature.properties.iso_a3, ([, alpha3]) => alpha3 === feature.properties.iso_a3_eh,
)?.[0]; )?.[0];
const serverCount = countryCode const serverCount = countryCode
? serverCounts[countryCode] || 0 ? serverCounts[countryCode] || 0
: 0; : 0;