Skip to content

armgit / VERT

Public Imported from GitHub
0

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

fix: what the flip ipapi

not-nullptra8366b3cb387
diff --git a/src/lib/ip.ts b/src/lib/ip.ts
index ccf62d4..602f553 100644
--- a/src/lib/ip.ts
+++ b/src/lib/ip.ts
@@ -31,17 +31,50 @@ export interface IpInfo {
}
export const ip = async (): Promise<IpInfo> => {
- if (browser) {
- const item = localStorage.getItem("ipinfo");
- if (item) {
- return JSON.parse(item);
+ try {
+ 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));
- }
+ const res = await fetch("https://ipapi.co/json/").then((r) => r.json());
+ if (browser) {
+ 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",
+ };
+ }
};