mirror of
https://github.com/spacebarchat/server.git
synced 2026-04-25 14:02:08 +00:00
25 lines
687 B
TypeScript
25 lines
687 B
TypeScript
import { Config } from "@fosscord/util";
|
|
import fetch from "node-fetch";
|
|
|
|
export interface hcaptchaResponse {
|
|
success: boolean;
|
|
challenge_ts: string;
|
|
hostname: string;
|
|
credit: boolean;
|
|
"error-codes": string[];
|
|
score: number; // enterprise only
|
|
score_reason: string[]; // enterprise only
|
|
}
|
|
|
|
export async function verifyHcaptcha(response: string, ip?: string) {
|
|
const { security } = Config.get();
|
|
const { secret, sitekey } = security.captcha;
|
|
|
|
const res = await fetch("https://hcaptcha.com/siteverify", {
|
|
method: "POST",
|
|
body: `response=${response}&secret=${secret}&remoteip=${ip}&sitekey=${sitekey}`,
|
|
})
|
|
|
|
const json = await res.json() as hcaptchaResponse;
|
|
return json;
|
|
} |