You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
842 B
24 lines
842 B
import svgCaptcha from "svg-captcha";
|
|
import { captchaCreate } from "./store";
|
|
import { env } from "env";
|
|
|
|
/** 易混淆字符已剔除,长度 5 */
|
|
const CHAR_PRESET = "abcdefghjkmnpqrstuvwxyz23456789";
|
|
|
|
export function createCaptchaChallenge(): { captchaId: string; imageSvg: string } {
|
|
if (env.E2E_TEST_MODE === "true" && env.E2E_FIXED_CAPTCHA) {
|
|
const { captchaId } = captchaCreate(env.E2E_FIXED_CAPTCHA);
|
|
return { captchaId, imageSvg: "<svg><!-- e2e fixed captcha --></svg>" };
|
|
}
|
|
|
|
const { data: imageSvg, text } = svgCaptcha.create({
|
|
size: 5,
|
|
noise: 2,
|
|
color: true,
|
|
charPreset: CHAR_PRESET,
|
|
background: "#f4f4f5",
|
|
});
|
|
const answerNormalized = text.toLowerCase();
|
|
const { captchaId } = captchaCreate(answerNormalized);
|
|
return { captchaId, imageSvg };
|
|
}
|
|
|