Added support for IP2Location.io API

This commit is contained in:
IP2Location 2024-07-31 11:13:16 +08:00
parent 33b4343dd4
commit d8d55d7d94
4 changed files with 17 additions and 6 deletions

View File

@ -118,9 +118,10 @@ Dashy supports [Widgets](/docs/widgets.md) for displaying dynamic content. Below
- [OWM Privacy Policy](https://openweather.co.uk/privacy-policy)
- **[RSS Feed](/docs/widgets.md#rss-feed)**: `https://api.rss2json.com/v1/api.json`
- [Rss2Json Privacy Policy](https://rss2json.com/privacy-policy)
- **[IP Address](/docs/widgets.md#public-ip)**: `https://ipapi.co/json` or `http://ip-api.com/json`
- **[IP Address](/docs/widgets.md#public-ip)**: `https://ipapi.co/json` or `http://ip-api.com/json` or `https://api.ip2location.io/`
- [IPGeoLocation Privacy Policy](https://ipgeolocation.io/privacy.html)
- [IP-API Privacy Policy](https://ip-api.com/docs/legal)
- [IP2Location.io Privacy Policy](https://ip2location.io/privacy-policy)
- **[IP Blacklist](/docs/widgets.md#ip-blacklist)**: `https://api.blacklistchecker.com`
- [Blacklist Checker Privacy Policy](https://blacklistchecker.com/privacy)
- **[Domain Monitor](/docs/widgets.md#domain-monitor)**: `http://api.whoapi.com`

View File

@ -287,7 +287,7 @@ Unless image fetched from remote source, no external data request is made.
### Public IP
Often find yourself searching "What's my IP", just so you can check your VPN is still connected? This widget displays your public IP address, along with ISP name and approx location. Data can be fetched from either [IpApi.co](https://ipapi.co/), [IP-API.com](https://ip-api.com/) or [IpGeolocation.io](https://ipgeolocation.io/).
Often find yourself searching "What's my IP", just so you can check your VPN is still connected? This widget displays your public IP address, along with ISP name and approx location. Data can be fetched from either [IpApi.co](https://ipapi.co/), [IP-API.com](https://ip-api.com/), [IpGeolocation.io](https://ipgeolocation.io/) or [IP2Location.io](https://ip2location.io/).
<p align="center"><img width="400" src="https://i.ibb.co/vc3c8zN/public-ip.png" /></p>
@ -297,8 +297,8 @@ _All fields are optional._
**Field** | **Type** | **Required** | **Description**
--- | --- | --- | ---
**`provider`** | `string` | _Optional_ | The name of the service to fetch IP address from. Can be either `ipapi.co`, `ip-api` or `ipgeolocation`. Defaults to `ipapi.co`. Note, `ip-api` doesn't work on HTTPS, and if you set to `ipgeolocation` then you must also provide an API key
**`apiKey`** | `string` | _Optional_ | Only required if provider is set to `ipgeolocation`. You can get a free API key [here](https://ipgeolocation.io/signup.html)
**`provider`** | `string` | _Optional_ | The name of the service to fetch IP address from. Can be either `ipapi.co`, `ip-api`, `ipgeolocation` or `ip2location.io`. Defaults to `ipapi.co`. Note, `ip-api` doesn't work on HTTPS, and if you set to `ipgeolocation` or `ip2location.io` then you must also provide an API key
**`apiKey`** | `string` | _Optional_ | Only required if provider is set to `ipgeolocation` or `ip2location.io`. You can get a free IPGeolocation API key [here](https://ipgeolocation.io/signup.html) or a free IP2Location.io API key [here](https://ip2location.io/pricing)
#### Example
@ -321,7 +321,7 @@ Or
- **Auth**: 🟠 Optional
- **Price**: 🟢 Free
- **Host**: Managed Instance Only
- **Privacy**: _See [IPGeoLocation Privacy Policy](https://ipgeolocation.io/privacy.html) or [IP-API Privacy Policy](https://ip-api.com/docs/legal)_
- **Privacy**: _See [IPGeoLocation Privacy Policy](https://ipgeolocation.io/privacy.html) or [IP-API Privacy Policy](https://ip-api.com/docs/legal) or [IP2Location.io Privacy Policy](https://ip2location.io/privacy-policy)
---

View File

@ -24,6 +24,8 @@ export default {
endpoint() {
if (this.provider === 'ipgeolocation') {
return `${widgetApiEndpoints.publicIp2}?apiKey=${this.apiKey}`;
} else if (this.provider === 'ip2location.io') {
return `${widgetApiEndpoints.publicIp4}?key=${this.apiKey}`;
} else if (this.provider === 'ipapi') {
return widgetApiEndpoints.publicIp3;
}
@ -31,10 +33,11 @@ export default {
},
apiKey() {
if (this.provider === 'ipgeolocation' && !this.options.apiKey) this.error('Missing API Key');
if (this.provider === 'ip2location.io' && !this.options.apiKey) this.error('Missing API Key');
return this.options.apiKey;
},
provider() {
// Can be either `ip-api`, `ipapi.co` or `ipgeolocation`
// Can be either `ip-api`, `ipapi.co`, `ipgeolocation` or `ip2location.io`
return this.parseAsEnvVar(this.options.provider) || 'ipapi.co';
},
},
@ -72,6 +75,12 @@ export default {
this.location = `${ipInfo.city}, ${ipInfo.regionName}`;
this.flagImg = getCountryFlag(ipInfo.countryCode);
this.mapsUrl = getMapUrl({ lat: ipInfo.lat, lon: ipInfo.lon });
} else if (this.provider === 'ip2location.io') {
this.ipAddr = ipInfo.ip;
this.ispName = ipInfo.isp || 'IP2Location.io Starter plan or higher required.';
this.location = `${ipInfo.city_name}, ${ipInfo.region_name}`;
this.flagImg = getCountryFlag(ipInfo.country_code);
this.mapsUrl = getMapUrl({ lat: ipInfo.latitude, lon: ipInfo.longitude });
} else {
this.error('Unknown API provider fo IP address');
}

View File

@ -244,6 +244,7 @@ module.exports = {
publicIp: 'https://ipapi.co/json',
publicIp2: 'https://api.ipgeolocation.io/ipgeo',
publicIp3: 'http://ip-api.com/json',
publicIp4: 'https://api.ip2location.io/',
readMeStats: 'https://github-readme-stats.vercel.app/api',
rescueTime: 'https://www.rescuetime.com/anapi/data',
rssToJson: 'https://api.rss2json.com/v1/api.json',