Skip to content

Commit

Permalink
Merge pull request jason5ng32#215 from jason5ng32/dev
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
jason5ng32 authored May 18, 2024
2 parents 4b89e4d + e307a03 commit 5e2e360
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 259 deletions.
13 changes: 5 additions & 8 deletions api/ipinfo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { get } from 'https';
import { isValidIP } from '../common/valid-ip.js';
import { refererCheck } from '../common/referer-check.js';
import { loadCountryCodes } from '../common/country-codes.js';
import countryLookup from 'country-code-lookup';

export default async (req, res) => {
// 限制只能从指定域名访问
Expand Down Expand Up @@ -35,10 +35,7 @@ export default async (req, res) => {
apiRes.on('end', async () => {
try {
const originalJson = JSON.parse(data);

// 动态导入国家代码
const countryCodes = await loadCountryCodes();
const modifiedJson = modifyJson(originalJson, countryCodes);
const modifiedJson = modifyJson(originalJson);

res.json(modifiedJson);
} catch (e) {
Expand All @@ -50,10 +47,10 @@ export default async (req, res) => {
});
};

function modifyJson(json, countryCodes) {
const { ip, city, region, country, loc, org, timezone } = json;
function modifyJson(json) {
const { ip, city, region, country, loc, org } = json;

const countryName = countryCodes[country] || 'Unknown Country';
const countryName = countryLookup.byIso(country).country || 'Unknown Country';

const [latitude, longitude] = loc.split(',').map(Number);
const [asn, ...orgName] = org.split(' ');
Expand Down
251 changes: 0 additions & 251 deletions common/country-codes.js

This file was deleted.

0 comments on commit 5e2e360

Please sign in to comment.