summary refs log tree commit diff
path: root/src/api/util/utility
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-12-02 16:46:08 +0100
committerRory& <root@rory.gay>2025-12-02 16:46:08 +0100
commit8b10d85d296253375bf4ddad7c97350ca0883853 (patch)
treec61d5f15cea79bef0d55326b407080539b2db1a8 /src/api/util/utility
parentDont export classes as default (diff)
downloadserver-ts-8b10d85d296253375bf4ddad7c97350ca0883853.tar.xz
Use IpDataClient in places
Diffstat (limited to 'src/api/util/utility')
-rw-r--r--src/api/util/utility/ipAddress.ts76
1 files changed, 0 insertions, 76 deletions
diff --git a/src/api/util/utility/ipAddress.ts b/src/api/util/utility/ipAddress.ts

index 2609dae1..e5acc89d 100644 --- a/src/api/util/utility/ipAddress.ts +++ b/src/api/util/utility/ipAddress.ts
@@ -18,82 +18,6 @@ import { Config } from "@spacebar/util"; import { Request } from "express"; -// use ipdata package instead of simple fetch because of integrated caching - -const exampleData = { - ip: "", - is_eu: true, - city: "", - region: "", - region_code: "", - country_name: "", - country_code: "", - continent_name: "", - continent_code: "", - latitude: 0, - longitude: 0, - postal: "", - calling_code: "", - flag: "", - emoji_flag: "", - emoji_unicode: "", - asn: { - asn: "", - name: "", - domain: "", - route: "", - type: "isp", - }, - languages: [ - { - name: "", - native: "", - }, - ], - currency: { - name: "", - code: "", - symbol: "", - native: "", - plural: "", - }, - time_zone: { - name: "", - abbr: "", - offset: "", - is_dst: true, - current_time: "", - }, - threat: { - is_tor: false, - is_proxy: false, - is_anonymous: false, - is_known_attacker: false, - is_known_abuser: false, - is_threat: false, - is_bogon: false, - }, - count: 0, - status: 200, -}; - -//TODO add function that support both ip and domain names -export async function IPAnalysis(ip: string): Promise<typeof exampleData> { - const { ipdataApiKey } = Config.get().security; - if (!ipdataApiKey) return { ...exampleData, ip }; - - return ( - await fetch(`https://api.ipdata.co/${ip}?api-key=${ipdataApiKey}`) - ).json() as Promise<typeof exampleData>; -} - -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; - - return false; -} export function getIpAdress(req: Request): string { // TODO: express can do this (trustProxies: true)?