Skip to content

Commit a3e4ed9

Browse files
committed
fix: use ipinfo.io to allow https
1 parent 03f99d6 commit a3e4ed9

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

components.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ declare module '@vue/runtime-core' {
137137
MenuLayout: typeof import('./src/components/MenuLayout.vue')['default']
138138
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
139139
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
140+
NA: typeof import('naive-ui')['NA']
140141
NAlert: typeof import('naive-ui')['NAlert']
141142
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
142143
NCheckbox: typeof import('naive-ui')['NCheckbox']
@@ -163,6 +164,7 @@ declare module '@vue/runtime-core' {
163164
NLayout: typeof import('naive-ui')['NLayout']
164165
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
165166
NMenu: typeof import('naive-ui')['NMenu']
167+
NP: typeof import('naive-ui')['NP']
166168
NProgress: typeof import('naive-ui')['NProgress']
167169
NScrollbar: typeof import('naive-ui')['NScrollbar']
168170
NSlider: typeof import('naive-ui')['NSlider']

src/tools/ip-geo-location/ip-geo-location.vue

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,25 @@
11
<script setup lang="ts">
22
import type { CKeyValueListItems } from '@/ui/c-key-value-list/c-key-value-list.types';
33
4-
const ipOrDomain = ref('8.8.8.8');
4+
const ip = ref('8.8.8.8');
55
const errorMessage = ref('');
66
77
const fields: Array<{ field: string; name: string }> = [
8-
{ field: 'message', name: 'Message' },
9-
{ field: 'continent', name: 'Continent Name' },
10-
{ field: 'continentCode', name: 'Continent code' },
11-
{ field: 'country', name: 'Country Name' },
12-
{ field: 'countryCode', name: 'Country Code' },
8+
{ field: 'ip', name: 'IP' },
9+
{ field: 'hostname', name: 'Host Name' },
10+
{ field: 'country', name: 'Country Code' },
1311
{ field: 'region', name: 'Region/state Code' },
14-
{ field: 'regionName', name: 'Region/state Name' },
1512
{ field: 'city', name: 'City' },
16-
{ field: 'district', name: 'District' },
17-
{ field: 'zip', name: 'Zip Code' },
18-
{ field: 'lat', name: 'Latitude' },
19-
{ field: 'lon', name: 'Longitude' },
13+
{ field: 'postal', name: 'Postal Code' },
14+
{ field: 'loc', name: 'Latitude/Longitude' },
2015
{ field: 'timezone', name: 'Timezone' },
21-
{ field: 'offset', name: 'Timezone UTC DST offset (in seconds)' },
22-
{ field: 'currency', name: 'National Currency' },
23-
{ field: 'isp', name: 'ISP Name' },
2416
{ field: 'org', name: 'Organization Name' },
25-
{ field: 'as', name: 'AS Number and Organization' },
26-
{ field: 'asname', name: 'AS name (RIR)' },
27-
{ field: 'reverse', name: 'Reverse DNS of the IP' },
28-
{ field: 'mobile', name: 'Mobile (cellular) connection' },
29-
{ field: 'proxy', name: 'Proxy, VPN or Tor exit address' },
30-
{ field: 'hosting', name: 'Hosting, colocated or data center' },
31-
{ field: 'query', name: 'IP used for the query' },
3217
];
3318
3419
const geoInfos = ref<CKeyValueListItems>([]);
3520
const geoInfosData = ref<any>({});
3621
const status = ref<'pending' | 'error' | 'success'>('pending');
22+
const token = useStorage('ip-geoloc:token', '');
3723
3824
const openStreetMapUrl = computed(
3925
() => {
@@ -47,7 +33,10 @@ async function onGetInfos() {
4733
try {
4834
status.value = 'pending';
4935
50-
const geoInfoQueryResponse = await fetch(`http://ip-api.com/json/${ipOrDomain.value}`);
36+
const geoInfoQueryResponse = await fetch(
37+
token.value !== ''
38+
? `https://ipinfo.io/${ip.value}/json?token=${token.value}`
39+
: `https://ipinfo.io/${ip.value}/json`);
5140
if (!geoInfoQueryResponse.ok) {
5241
throw geoInfoQueryResponse.statusText;
5342
}
@@ -80,15 +69,29 @@ async function onGetInfos() {
8069
<div>
8170
<div flex items-center gap-2>
8271
<c-input-text
83-
v-model:value="ipOrDomain"
84-
placeholder="Enter an IPv4/6 or a domain name"
72+
v-model:value="ip"
73+
placeholder="Enter an IPv4/6"
8574
@update:value="() => { status = 'pending' }"
8675
/>
8776
<c-button align-center @click="onGetInfos">
8877
Get GEO Location Infos
8978
</c-button>
9079
</div>
9180

81+
<details mt-2>
82+
<summary>Optional ipinfo.io token</summary>
83+
<c-input-text
84+
v-model:value="token"
85+
placeholder="Optional ipinfo.io token"
86+
@update:value="() => { status = 'pending' }"
87+
/>
88+
<n-p>
89+
<n-a href="https://ipinfo.io/">
90+
Signup for a free token
91+
</n-a>
92+
</n-p>
93+
</details>
94+
9295
<n-divider />
9396

9497
<c-card v-if="status === 'pending'" mt-5>

0 commit comments

Comments
 (0)