You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by sh...@apache.org on 2024/04/09 10:36:38 UTC
(incubator-answer-plugins) branch feat/captcha updated: fix: captcha params changed
This is an automated email from the ASF dual-hosted git repository.
shuai pushed a commit to branch feat/captcha
in repository https://gitbox.apache.org/repos/asf/incubator-answer-plugins.git
The following commit(s) were added to refs/heads/feat/captcha by this push:
new 2abe1d6 fix: captcha params changed
2abe1d6 is described below
commit 2abe1d6dd69dfd4756f1a52812df3d0943c010bb
Author: shuai <li...@sifou.com>
AuthorDate: Tue Apr 9 18:36:29 2024 +0800
fix: captcha params changed
---
captcha-basic/useCaptcha.tsx | 25 +++++++++++++++++++++----
captcha-google-v2/useCaptcha.tsx | 26 ++++++++++++++++++++++----
2 files changed, 43 insertions(+), 8 deletions(-)
diff --git a/captcha-basic/useCaptcha.tsx b/captcha-basic/useCaptcha.tsx
index 152d333..fa48cb9 100644
--- a/captcha-basic/useCaptcha.tsx
+++ b/captcha-basic/useCaptcha.tsx
@@ -30,10 +30,21 @@ import type {
FieldError,
ImgCodeReq,
} from './interface';
+interface Props {
+ captchaKey: CaptchaKey;
+ commonProps?: any;
+}
-const checkImgCode = (key: CaptchaKey) => {
+const checkImgCode = ({
+ captchaKey,
+ commonProps,
+}: Props) => {
return new Promise<ImgCodeRes>((resolve) => {
- fetch(`/answer/api/v1/user/action/record?action=${key}`)
+ fetch(`/answer/api/v1/user/action/record?action=${captchaKey}`, {
+ headers: {
+ ...commonProps?.headers
+ }
+ })
.then((resp) => {
return resp.json();
})
@@ -48,7 +59,10 @@ type SubmitCallback = {
(): void;
};
-const Index = (captchaKey: CaptchaKey) => {
+const Index = ({
+ captchaKey,
+ commonProps,
+}: Props) => {
const refRoot = useRef<ReactDOM.Root | null>(null);
if (refRoot.current === null) {
refRoot.current = ReactDOM.createRoot(document.createElement('div'));
@@ -78,7 +92,10 @@ const Index = (captchaKey: CaptchaKey) => {
const fetchCaptchaData = () => {
pending.current = true;
- checkImgCode(refKey.current)
+ checkImgCode({
+ captchaKey: refKey.current,
+ commonProps,
+ })
.then((resp) => {
setCaptcha(resp);
})
diff --git a/captcha-google-v2/useCaptcha.tsx b/captcha-google-v2/useCaptcha.tsx
index d188c9a..469b34d 100644
--- a/captcha-google-v2/useCaptcha.tsx
+++ b/captcha-google-v2/useCaptcha.tsx
@@ -33,9 +33,21 @@ import type {
ImgCodeReq,
} from './interface';
-const checkImgCode = (key: CaptchaKey) => {
+interface Props {
+ captchaKey: CaptchaKey;
+ commonProps?: any;
+}
+
+const checkImgCode = ({
+ captchaKey,
+ commonProps,
+}: Props) => {
return new Promise<ImgCodeRes>((resolve) => {
- fetch(`/answer/api/v1/user/action/record?action=${key}`)
+ fetch(`/answer/api/v1/user/action/record?action=${captchaKey}`, {
+ headers: {
+ ...commonProps?.headers
+ }
+ })
.then((resp) => {
return resp.json();
})
@@ -50,7 +62,10 @@ type SubmitCallback = {
(): void;
};
-const Index = (captchaKey: CaptchaKey) => {
+const Index = ({
+ captchaKey = '',
+ commonProps,
+}: Props) => {
const refRoot = useRef<ReactDOM.Root | null>(null);
if (refRoot.current === null) {
@@ -94,7 +109,10 @@ const Index = (captchaKey: CaptchaKey) => {
const fetchCaptchaData = () => {
pending.current = true;
- checkImgCode(refKey.current)
+ checkImgCode({
+ captchaKey: refKey.current,
+ commonProps,
+ })
.then((resp) => {
setCaptcha(resp);
})