Skip to content

armgit / VERT

Public Imported from GitHub
0

The next-generation file converter. Open source, fully local* and free forever.

fix: ipapi 429

not-nullptrdbeb0eee7910
diff --git a/src/lib/ip.ts b/src/lib/ip.ts
index 7c37105..ccf62d4 100644
--- a/src/lib/ip.ts
+++ b/src/lib/ip.ts
@@ -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;
};