mirror of
https://github.com/jason5ng32/MyIP.git
synced 2026-11-04 08:55:47 +00:00
IpDetailPanel had grown to ~750 lines holding three independent regions. It is now the shell (metadata grid, inline Map / Country-traffic panels, dialogs) with unchanged props, emits and multi-root template, rendering IpAdvancedBlock (with ScoreDetailsPanel beside ScenarioFrictionPanel) and IpAsnBlock, which relay view-usage / open-tool through it. The inline /api/asn-history fetch becomes loadAsnHistoryInto in utils/ip/asn-history.js, matching the other ASN loaders, now with tests. Markup, copy, analytics and per-IP reset behaviour are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.5 KiB
JavaScript
33 lines
1.5 KiB
JavaScript
// Client for `/api/asn-connectivity` (CAIDA topology + neighbour lists),
|
|
// used by IpAsnBlock. Fills an owner's session cache keyed by the numeric ASN
|
|
// string: `{ graph }` on success, `{ error: true }` on failure — the shape
|
|
// ASNConnectivity.vue reads.
|
|
//
|
|
// Relative imports keep this file importable from the Node test runner.
|
|
import { fetchWithTimeout } from '../fetch-with-timeout.js';
|
|
|
|
// Cache-buster: bump on graph algorithm / schema changes. The route sits
|
|
// behind a 30-day max-age that caches in browsers too, where no purge reaches.
|
|
export const ASN_CONNECTIVITY_VERSION = 5;
|
|
|
|
export const asnConnectivityUrl = (asn) =>
|
|
`/api/asn-connectivity?asn=${encodeURIComponent(asn)}&v=${ASN_CONNECTIVITY_VERSION}`;
|
|
|
|
// Fetch `asn` ('13335') into `cache` unless already there; resolves to the
|
|
// cache entry. Failures are cached as `{ error: true }` — except a 503 (the
|
|
// backend's "data still loading" during boot), answered the same but not
|
|
// cached, so the next open retries.
|
|
export const loadAsnConnectivityInto = async (cache, asn) => {
|
|
if (cache[asn]) return cache[asn];
|
|
try {
|
|
// The backend is a sub-ms local lookup; a tight cap is fine.
|
|
const response = await fetchWithTimeout(asnConnectivityUrl(asn), { timeoutMs: 5000 });
|
|
if (response.status === 503) return { error: true };
|
|
cache[asn] = response.ok ? { graph: await response.json() } : { error: true };
|
|
} catch (error) {
|
|
console.error('Error fetching ASN connectivity:', error);
|
|
cache[asn] = { error: true };
|
|
}
|
|
return cache[asn];
|
|
};
|