feat(platform): add Discord onboarding and Velocity gate
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { isIP } from "node:net";
|
||||
|
||||
export type IpClassification = "unknown" | "clear" | "vpn" | "proxy" | "hosting" | "tor";
|
||||
|
||||
export interface IpIntelligenceResult {
|
||||
classification: IpClassification;
|
||||
provider: string | null;
|
||||
rawResponse?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface IpIntelligenceProvider {
|
||||
classify(ipAddress: string): Promise<IpIntelligenceResult>;
|
||||
}
|
||||
|
||||
export class NoopIpIntelligenceProvider implements IpIntelligenceProvider {
|
||||
async classify(_ipAddress: string): Promise<IpIntelligenceResult> {
|
||||
return { classification: "unknown", provider: null };
|
||||
}
|
||||
}
|
||||
|
||||
export function getClientIp(headers: Headers, trustProxy: boolean) {
|
||||
if (!trustProxy) return null;
|
||||
|
||||
const candidate =
|
||||
headers.get("x-forwarded-for")?.split(",")[0]?.trim() ||
|
||||
headers.get("x-real-ip")?.trim() ||
|
||||
null;
|
||||
|
||||
return candidate && isIP(candidate) ? candidate : null;
|
||||
}
|
||||
Reference in New Issue
Block a user