From 8f38cf94d8decb2f31299f11c4474a8994880b08 Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Thu, 12 Dec 2024 00:45:04 +0800 Subject: [PATCH] fix: get file --- lib/GetIPInfo.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/GetIPInfo.ts b/lib/GetIPInfo.ts index 1ce71e3..ea526d4 100644 --- a/lib/GetIPInfo.ts +++ b/lib/GetIPInfo.ts @@ -2,6 +2,7 @@ import maxmind, { CityResponse, AsnResponse } from 'maxmind'; import { GetServerIP } from './serverFetch'; +import path from 'path'; type IPInfo = { city: CityResponse; @@ -9,11 +10,14 @@ type IPInfo = { } export default async function GetIPInfo({ server_id }: { server_id: string }): Promise { - const ip = await GetServerIP({ server_id: Number(server_id) }) + + // 使用 path.join 获取正确的文件路径 + const cityDbPath = path.join(process.cwd(), 'lib', 'GeoLite2-City.mmdb'); + const asnDbPath = path.join(process.cwd(), 'lib', 'GeoLite2-ASN.mmdb'); - const cityLookup = await maxmind.open('./lib/GeoLite2-City.mmdb') - const asnLookup = await maxmind.open('./lib/GeoLite2-ASN.mmdb') + const cityLookup = await maxmind.open(cityDbPath) + const asnLookup = await maxmind.open(asnDbPath) return { city: cityLookup.get(ip) as CityResponse,