1 files changed, 6 insertions, 12 deletions
diff --git a/src/util/ipAddress.ts b/src/util/ipAddress.ts
index 4467caef..f2c8fd4d 100644
--- a/src/util/ipAddress.ts
+++ b/src/util/ipAddress.ts
@@ -1,13 +1,7 @@
+import { Config } from "@fosscord/server-util";
import { Request } from "express";
-import { Config } from "../../../server-util/dist";
// use ipdata package instead of simple fetch because of integrated caching
-import IPData, { LookupResponse } from "ipdata";
-
-var ipdata: IPData;
-const cacheConfig = {
- max: 1000, // max size
- maxAge: 1000 * 60 * 60 * 24 // max age in ms (i.e. one day)
-};
+import fetch from "node-fetch";
const exampleData = {
ip: "",
@@ -66,15 +60,15 @@ const exampleData = {
status: 200
};
-export async function IPAnalysis(ip: string): Promise<LookupResponse> {
+export async function IPAnalysis(ip: string): Promise<typeof exampleData> {
const { ipdataApiKey } = Config.get().security;
if (!ipdataApiKey) return { ...exampleData, ip };
- if (!ipdata) ipdata = new IPData(ipdataApiKey, cacheConfig);
- return await ipdata.lookup(ip);
+ return (await fetch(`https://api.ipdata.co/${ip}?api-key=${ipdataApiKey}`)).json();
}
-export function isProxy(data: LookupResponse) {
+export function isProxy(data: typeof exampleData) {
+ if (!data || !data.asn || !data.threat) return false;
if (data.asn.type !== "isp") return true;
if (Object.values(data.threat).some((x) => x)) return true;
|