1
0
forked from mirror/misskey
This commit is contained in:
syuilo 2021-04-26 12:47:54 +09:00
parent 4b205aee91
commit 77ccf3b929

View File

@ -6,7 +6,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent, PropType } from 'vue';
type Captcha = { type Captcha = {
render(container: string | Node, options: { render(container: string | Node, options: {
@ -32,7 +32,7 @@ declare global {
export default defineComponent({ export default defineComponent({
props: { props: {
provider: { provider: {
type: String, type: String as PropType<CaptchaProvider>,
required: true, required: true,
}, },
sitekey: { sitekey: {
@ -51,19 +51,25 @@ export default defineComponent({
}, },
computed: { computed: {
loaded() { variable(): string {
return !!window[this.provider as CaptchaProvider]; switch (this.provider) {
case 'hcaptcha': return 'hcaptcha';
case 'recaptcha': return 'grecaptcha';
}
}, },
src() { loaded(): boolean {
return !!window[this.variable];
},
src(): string {
const endpoint = ({ const endpoint = ({
hcaptcha: 'https://hcaptcha.com/1', hcaptcha: 'https://hcaptcha.com/1',
recaptcha: 'https://www.recaptcha.net/recaptcha', recaptcha: 'https://www.recaptcha.net/recaptcha',
} as Record<PropertyKey, unknown>)[this.provider]; } as Record<CaptchaProvider, string>)[this.provider];
return `${typeof endpoint == 'string' ? endpoint : 'about:invalid'}/api.js?render=explicit`; return `${typeof endpoint === 'string' ? endpoint : 'about:invalid'}/api.js?render=explicit`;
}, },
captcha() { captcha(): Captcha {
return window[this.provider as CaptchaProvider] || {} as unknown as Captcha; return window[this.variable] || {} as unknown as Captcha;
}, },
}, },
@ -94,7 +100,7 @@ export default defineComponent({
methods: { methods: {
reset() { reset() {
this.captcha?.reset(); if (this.captcha?.reset) this.captcha.reset();
}, },
requestRender() { requestRender() {
if (this.captcha.render && this.$refs.captcha instanceof Element) { if (this.captcha.render && this.$refs.captcha instanceof Element) {