Skip to content

Commit c4c7021

Browse files
committed
Code Improvements
1 parent a942956 commit c4c7021

22 files changed

+56
-59
lines changed

.env.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ ALLOWED_DOMAINS=""
66
BING_MAP_API_KEY=""
77
GOOGLE_MAP_API_KEY=""
88
IPINFO_API_TOKEN=""
9-
KEYCDN_USER_AGENT=""
109
CLOUDFLARE_API=""
1110
IPAPIIS_API_KEY=""
11+
IP2LOCATION_API_KEY=""
1212
IPCHECKING_API_KEY=""
1313
MAC_LOOKUP_API_KEY=""
1414
IPCHECKING_API_ENDPOINT=""

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ You can use the program without adding any environment variables, but if you wan
106106
| `IPCHECKING_API_KEY` | No | `""` | API Key for IPCheck.ing, used to obtain accurate IP geolocation information |
107107
| `IPINFO_API_TOKEN` | No | `""` | API Token for IPInfo.io, used to obtain IP geolocation information through IPInfo.io |
108108
| `IPAPIIS_API_KEY` | No | `""` | API Key for IPAPI.is, used to obtain IP geolocation information through IPAPI.is |
109-
| `KEYCDN_USER_AGENT` | No | `""` | The domain name when using KeyCDN, must contain https prefix. Used to obtain IP address information through KeyCDN |
109+
| `IP2LOCATION_API_KEY` | No | `""` | API Key for IP2Location.io, used to obtain IP geolocation information through IP2Location.io |
110110
| `CLOUDFLARE_API` | No | `""` | API Key for Cloudflare, used to obtain AS system information through Cloudflare |
111111
| `MAC_LOOKUP_API_KEY` | No | `""` | API Key for MAC Lookup, used to obtain MAC address information |
112112
| `IPCHECKING_API_ENDPOINT` | **Yes** | `""` | IPCheck.ing API endpoint |

README_FR.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Vous pouvez utiliser le programme sans ajouter de variables d'environnement, mai
106106
| `IPCHECKING_API_KEY` | Non | `""` | Clé API pour IPCheck.ing, utilisée pour obtenir des informations de géolocalisation précises sur l'adresse IP |
107107
| `IPINFO_API_TOKEN` | Non | `""` | Jeton API pour IPInfo.io, utilisé pour obtenir des informations de géolocalisation sur l'adresse IP via IPInfo.io |
108108
| `IPAPIIS_API_KEY` | Non | `""` | Clé API pour IPAPI.is, utilisée pour obtenir des informations de géolocalisation sur l'adresse IP via IPAPI.is |
109-
| `KEYCDN_USER_AGENT` | Non | `""` | Le nom de domaine lorsque vous utilisez KeyCDN, doit contenir le préfixe https. Utilisé pour obtenir des informations sur l'adresse IP via KeyCDN |
109+
| `IP2LOCATION_API_KEY` | Non | `""` | Clé API pour IP2Location.io, utilisée pour obtenir des informations de géolocalisation sur l'adresse IP via IP2Location.io |
110110
| `CLOUDFLARE_API` | Non | `""` | Clé API pour Cloudflare, utilisée pour obtenir des informations sur le système AS via Cloudflare |
111111
| `MAC_LOOKUP_API_KEY` | Non | `""` | Clé API pour MAC Lookup, utilisée pour obtenir des informations sur l'adresse MAC via MAC Lookup |
112112
| `IPCHECKING_API_ENDPOINT` | **Oui** | `""` | URL de l'API IPCheck.ing |

README_ZH.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ docker run -d -p 18966:18966 --name myip --restart always jason5ng32/myip:latest
106106
| `IPCHECKING_API_KEY` || `""` | IPCheck.ing 的 API Key,用于获取精准的 IP 归属地信息 |
107107
| `IPINFO_API_TOKEN` || `""` | IPInfo.io 的 API Token,用于通过 IPInfo.io 获取 IP 归属地信息 |
108108
| `IPAPIIS_API_KEY` || `""` | IPAPI.is 的 API Key,用于通过 IPAPI.is 获取 IP 归属地信息 |
109-
| `KEYCDN_USER_AGENT` || `""` | 使用 KeyCDN 时的域名,需包含 https 前缀。用于通过 KeyCDN 获取 IP 归属地信息 |
109+
| `IP2LOCATION_API_KEY` || `""` | IP2Location.io 的 API Key,用于通过 IP2Location.io 获取 IP 归属地信息 |
110110
| `CLOUDFLARE_API` || `""` | Cloudflare 的 API Key,用于通过 Cloudflare 获取 AS 系统的信息 |
111111
| `MAC_LOOKUP_API_KEY` || `""` | MAC 查询的 API Key,用于通过 MAC Lookup 获取 MAC 地址的归属信息 |
112112
| `IPCHECKING_API_ENDPOINT` | **** | `""` | IPCheck.ing 的 API 端点 URL |

api/cfradar.js api/cf-radar.js

File renamed without changes.

api/configs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default (req, res) => {
2121
map: process.env.GOOGLE_MAP_API_KEY,
2222
ipInfo: process.env.IPINFO_API_TOKEN,
2323
ipChecking: process.env.IPCHECKING_API_KEY,
24-
keyCDN: process.env.KEYCDN_USER_AGENT,
24+
ip2location: process.env.IP2LOCATION_API_KEY,
2525
originalSite,
2626
cloudFlare: process.env.CLOUDFLARE_API,
2727
ipapiis: process.env.IPAPIIS_API_KEY,
File renamed without changes.
File renamed without changes.

api/whois.js api/get-whois.js

File renamed without changes.

api/map.js api/google-map.js

File renamed without changes.
File renamed without changes.

api/ipsb.js api/ip-sb.js

File renamed without changes.

api/keycdn.js api/ip2location-io.js

+20-27
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,17 @@ export default (req, res) => {
2121
return res.status(400).json({ error: 'Invalid IP address' });
2222
}
2323

24-
// 构建请求 keycdn.com 的 URL
25-
const url = new URL(`https://tools.keycdn.com/geo.json?host=${ipAddress}`);
24+
const keys = (process.env.IP2LOCATION_API_KEY).split(',');
25+
const key = keys[Math.floor(Math.random() * keys.length)];
26+
const url = `https://api.ip2location.io/?ip=${ipAddress}&key=${key}`;
2627

27-
// 设置请求选项,包括 User-Agent
28-
const options = {
29-
hostname: url.hostname,
30-
path: url.pathname + url.search,
31-
headers: {
32-
'User-Agent': 'keycdn-tools:' + process.env.KEYCDN_USER_AGENT
33-
}
34-
};
35-
36-
get(options, apiRes => {
28+
get(url, apiRes => {
3729
let data = '';
3830
apiRes.on('data', chunk => data += chunk);
3931
apiRes.on('end', () => {
4032
try {
4133
const originalJson = JSON.parse(data);
42-
const modifiedJson = modifyJsonForKeyCDN(originalJson);
34+
const modifiedJson = modifyJsonForIPAPI(originalJson);
4335
res.json(modifiedJson);
4436
} catch (e) {
4537
res.status(500).json({ error: 'Error parsing JSON' });
@@ -48,21 +40,22 @@ export default (req, res) => {
4840
}).on('error', (e) => {
4941
res.status(500).json({ error: e.message });
5042
});
51-
}
43+
};
5244

53-
function modifyJsonForKeyCDN(json) {
54-
const { data: { geo: { ip, city, region_name, country_name, country_code, latitude, longitude, isp, asn } } } = json;
45+
function modifyJsonForIPAPI(json) {
46+
let asn = json.asn || {};
47+
const { ip, country_code, country_name, region_name, city_name, latitude, longitude, as } = json;
5548

5649
return {
57-
ip,
58-
city,
59-
region: region_name ? region_name : city,
60-
country: country_code,
61-
country_name,
62-
country_code,
63-
latitude,
64-
longitude,
65-
asn: "AS" + asn,
66-
org: isp
50+
ip: ip,
51+
city: city_name || 'N/A',
52+
region: region_name || 'N/A',
53+
country: country_code || 'N/A',
54+
country_name: country_name || 'N/A',
55+
country_code: country_code || 'N/A',
56+
latitude: latitude || 'N/A',
57+
longitude: longitude || 'N/A',
58+
asn: asn === undefined || asn === null ? 'N/A' : 'AS' + asn,
59+
org: as || 'N/A',
6760
};
68-
}
61+
}

api/ipapicom.js api/ipapi-com.js

File renamed without changes.

api/ipapiis.js api/ipapi-is.js

File renamed without changes.
File renamed without changes.

api/ipinfo.js api/ipinfo-io.js

File renamed without changes.
File renamed without changes.
File renamed without changes.

backend-server.js

+25-20
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,29 @@ import express from 'express';
33
import path from 'path';
44
import fs from 'fs';
55
import { fileURLToPath } from 'url';
6-
import mapHandler from './api/map.js';
7-
import ipinfoHandler from './api/ipinfo.js';
8-
import ipapicomHandler from './api/ipapicom.js';
9-
import keycdnHandler from './api/keycdn.js';
10-
import ipCheckingHandler from './api/ipchecking.js';
11-
import ipsbHandler from './api/ipsb.js';
12-
import cfHander from './api/cfradar.js';
13-
import validateConfigs from './api/configs.js';
14-
import dnsResolver from './api/dnsresolver.js';
15-
import rateLimit from 'express-rate-limit';
166
import { slowDown } from 'express-slow-down'
17-
import whois from './api/whois.js';
18-
import ipapiisHandler from './api/ipapiis.js';
19-
import invisibilitytestHandler from './api/invisibilitytest.js';
20-
import macChecker from './api/macchecker.js';
7+
import rateLimit from 'express-rate-limit';
8+
9+
// Backend APIs
10+
import mapHandler from './api/google-map.js';
11+
// IP Info
12+
import ipinfoHandler from './api/ipinfo-io.js';
13+
import ipapicomHandler from './api/ipapi-com.js';
14+
import ipCheckingHandler from './api/ipcheck-ing.js';
15+
import ipapiisHandler from './api/ipapi-is.js';
16+
import ip2locationHandler from './api/ip2location-io.js';
17+
import ipsbHandler from './api/ip-sb.js';
2118
import maxmindHandler from './api/maxmind.js';
22-
import getuserinfo from './api/getuserinfo.js';
23-
import updateuserachievement from './api/updateuserachievement.js';
19+
// Others
20+
import cfHander from './api/cf-radar.js';
21+
import dnsResolver from './api/dns-resolver.js';
22+
import getWhois from './api/get-whois.js';
23+
import invisibilitytestHandler from './api/invisibility-test.js';
24+
import macChecker from './api/mac-checker.js';
25+
// User
26+
import validateConfigs from './api/configs.js';
27+
import getUserinfo from './api/get-user-info.js';
28+
import updateUserAchievement from './api/update-user-achievement.js';
2429

2530
dotenv.config();
2631

@@ -132,18 +137,18 @@ app.use(express.json());
132137
app.get('/api/map', mapHandler);
133138
app.get('/api/ipinfo', ipinfoHandler);
134139
app.get('/api/ipapicom', ipapicomHandler);
135-
app.get('/api/keycdn', keycdnHandler);
136140
app.get('/api/ipchecking', ipCheckingHandler);
137141
app.get('/api/ipsb', ipsbHandler);
138142
app.get('/api/cfradar', cfHander);
139143
app.get('/api/dnsresolver', dnsResolver);
140-
app.get('/api/whois', whois);
144+
app.get('/api/whois', getWhois);
141145
app.get('/api/ipapiis', ipapiisHandler);
146+
app.get('/api/ip2location', ip2locationHandler);
142147
app.get('/api/invisibility', invisibilitytestHandler);
143148
app.get('/api/macchecker', macChecker);
144149
app.get('/api/maxmind', maxmindHandler);
145-
app.get('/api/getuserinfo', getuserinfo);
146-
app.put('/api/updateuserachievement', updateuserachievement);
150+
app.get('/api/getuserinfo', getUserinfo);
151+
app.put('/api/updateuserachievement', updateUserAchievement);
147152

148153
// 使用查询参数处理所有配置请求
149154
app.get('/api/configs', validateConfigs);

frontend/components/widgets/Preferences.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ const updateIPDBs = () => {
256256
if (configs.value && Object.keys(configs.value).length > 0) {
257257
store.updateIPDBs({ id: 0, enabled: configs.value.ipChecking });
258258
store.updateIPDBs({ id: 1, enabled: configs.value.ipInfo });
259-
store.updateIPDBs({ id: 4, enabled: configs.value.keyCDN });
260-
store.updateIPDBs({ id: 6, enabled: configs.value.ipapiis });
259+
store.updateIPDBs({ id: 3, enabled: configs.value.ipapiis });
260+
store.updateIPDBs({ id: 4, enabled: configs.value.ip2location });
261261
}
262262
};
263263

frontend/store.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,10 @@ export const useMainStore = defineStore('main', {
8080
{ id: 0, text: 'IPCheck.ing', url: '/api/ipchecking?ip={{ip}}&lang={{lang}}', enabled: true },
8181
{ id: 1, text: 'IPinfo.io', url: '/api/ipinfo?ip={{ip}}', enabled: true },
8282
{ id: 2, text: 'IP-API.com', url: '/api/ipapicom?ip={{ip}}&lang={{lang}}', enabled: true },
83-
{ id: 3, text: 'IPAPI.co', url: 'https://ipapi.co/{{ip}}/json/', enabled: true },
84-
{ id: 4, text: 'KeyCDN', url: '/api/keycdn?ip={{ip}}', enabled: true },
85-
{ id: 5, text: 'IP.SB', url: '/api/ipsb?ip={{ip}}', enabled: true },
86-
{ id: 6, text: 'IPAPI.is', url: '/api/ipapiis?ip={{ip}}', enabled: true },
87-
{ id: 7, text: 'MaxMind', url: '/api/maxmind?ip={{ip}}&lang={{lang}}', enabled: true },
83+
{ id: 3, text: 'IPAPI.is', url: '/api/ipapiis?ip={{ip}}', enabled: true },
84+
{ id: 4, text: 'IP2Location.io', url: '/api/ip2location?ip={{ip}}', enabled: true },
85+
{ id: 5, text: 'IP.sb', url: '/api/ipsb?ip={{ip}}', enabled: true },
86+
{ id: 6, text: 'MaxMind', url: '/api/maxmind?ip={{ip}}&lang={{lang}}', enabled: true },
8887
],
8988
}),
9089

0 commit comments

Comments
 (0)