From efc522a0c6a08e60de5efce0e076d61445fd9627 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Thu, 1 Jul 2021 09:33:54 +0200 Subject: :construction: rate limit --- src/util/ipAddress.ts | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'src/util') diff --git a/src/util/ipAddress.ts b/src/util/ipAddress.ts index 74090d61..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"; // 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,14 @@ const exampleData = { status: 200 }; -export async function IPAnalysis(ip: string): Promise { +export async function IPAnalysis(ip: string): Promise { 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; -- cgit 1.5.1