fix(altcha): update attribute from challengeurl to challenge in Altcha component and home template

This commit is contained in:
hamed
2026-07-10 12:06:03 +03:30
parent 3eee6c3886
commit 2cfc516e2c
2 changed files with 9 additions and 9 deletions
+7 -8
View File
@@ -12,13 +12,11 @@ interface AltchaProps {
} }
// altcha-widget یک custom element است؛ به JSX معرفی می‌شود (React 19: namespace زیر React.JSX). // altcha-widget یک custom element است؛ به JSX معرفی می‌شود (React 19: namespace زیر React.JSX).
// همه‌ی attributeها با setAttribute ست می‌شوند، نه JSX prop.
declare module 'react' { declare module 'react' {
namespace JSX { namespace JSX {
interface IntrinsicElements { interface IntrinsicElements {
'altcha-widget': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> & { 'altcha-widget': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;
challengeurl?: string;
strings?: string;
};
} }
} }
} }
@@ -41,9 +39,8 @@ export default function Altcha({ onVerified, challengeUrl = '/api/v1/altcha/chal
return () => { alive = false; }; return () => { alive = false; };
}, [onVerified]); }, [onVerified]);
// config (challengeurl/strings/auto) را با setAttribute ست می‌کنیم، نه JSX prop — // config (challenge/language/auto) را با setAttribute ست می‌کنیم، نه JSX prop —
// React ممکن است پراپ custom element را به‌صورت property ست کند و widget آن را // React ممکن است پراپ custom element را به‌صورت property ست کند و widget آن را نخواند.
// نخواند؛ نتیجه challengeurl خالی و fetch صفحه‌ی جاری (HTML) به‌جای JSON بود.
useEffect(() => { useEffect(() => {
if (enabled !== true) return; if (enabled !== true) return;
const el = ref.current; const el = ref.current;
@@ -56,7 +53,9 @@ export default function Altcha({ onVerified, challengeUrl = '/api/v1/altcha/chal
} }
}; };
el.setAttribute('challengeurl', challengeUrl); // widget v3 نام attribute را از challengeurl به challenge تغییر داده (docs v2)؛
// challengeurl را observe نمی‌کند و بدون URL، صفحه‌ی جاری (HTML) fetch می‌شد.
el.setAttribute('challenge', challengeUrl);
el.setAttribute('language', 'fa'); el.setAttribute('language', 'fa');
el.setAttribute('auto', 'onload'); el.setAttribute('auto', 'onload');
el.addEventListener('statechange', onStateChange); el.addEventListener('statechange', onStateChange);
+2 -1
View File
@@ -559,7 +559,8 @@
{% if altcha_enabled %} {% if altcha_enabled %}
<!-- ALTCHA captcha — proof-of-work در پس‌زمینه (بدون تعامل کاربر) --> <!-- ALTCHA captcha — proof-of-work در پس‌زمینه (بدون تعامل کاربر) -->
<altcha-widget id="regAltcha" challengeurl="/api/v1/altcha/challenge" auto="onload" language="fa" style="display:block;margin-top:16px"></altcha-widget> {# widget v3: attribute «challenge» (نه challengeurl قدیمی) #}
<altcha-widget id="regAltcha" challenge="/api/v1/altcha/challenge" auto="onload" language="fa" style="display:block;margin-top:16px"></altcha-widget>
{% endif %} {% endif %}
<!-- Error / Success --> <!-- Error / Success -->