fix: what the flip ipapi

This commit is contained in:
not-nullptr 2025-10-05 15:50:37 +01:00
parent dbeb0eee79
commit a8366b3cb3
1 changed files with 43 additions and 10 deletions

View File

@ -31,17 +31,50 @@ export interface IpInfo {
} }
export const ip = async (): Promise<IpInfo> => { export const ip = async (): Promise<IpInfo> => {
if (browser) { try {
const item = localStorage.getItem("ipinfo"); if (browser) {
if (item) { const item = localStorage.getItem("ipinfo");
return JSON.parse(item); if (item) {
return JSON.parse(item);
}
} }
}
const res = await fetch("https://ipapi.co/json/").then((r) => r.json()); const res = await fetch("https://ipapi.co/json/").then((r) => r.json());
if (browser) { if (browser) {
localStorage.setItem("ipinfo", JSON.stringify(res)); localStorage.setItem("ipinfo", JSON.stringify(res));
} }
return res; return res;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (_) {
return {
ip: "127.0.0.1",
asn: "AS0",
city: "Localhost",
continent_code: "NA",
country: "US",
country_calling_code: "+1",
country_capital: "Washington",
country_code: "US",
country_code_iso3: "USA",
country_name: "United States",
country_population: 0,
currency: "USD",
currency_name: "Dollar",
languages: "en-US,es-US,haw,fr",
latitude: 0,
longitude: 0,
network: "Unknown",
postal: "00000",
region: "Local",
region_code: "LOC",
country_area: 0,
timezone: "America/New_York",
utc_offset: "-0500",
version: "IPv4",
in_eu: false,
org: "Localhost",
country_tld: ".us",
};
}
}; };