fix: ipapi 429

This commit is contained in:
not-nullptr 2025-10-05 15:48:13 +01:00
parent 82a63929b4
commit dbeb0eee79
1 changed files with 15 additions and 1 deletions

View File

@ -1,3 +1,5 @@
import { browser } from "$app/environment";
export interface IpInfo {
ip: string;
network: string;
@ -29,5 +31,17 @@ export interface IpInfo {
}
export const ip = async (): Promise<IpInfo> => {
return await fetch("https://ipapi.co/json/").then((r) => r.json());
if (browser) {
const item = localStorage.getItem("ipinfo");
if (item) {
return JSON.parse(item);
}
}
const res = await fetch("https://ipapi.co/json/").then((r) => r.json());
if (browser) {
localStorage.setItem("ipinfo", JSON.stringify(res));
}
return res;
};