misskey/packages/frontend/src/pages/admin/bot-protection.vue

110 lines
4.0 KiB
Vue
Raw Normal View History

<template>
2022-01-04 12:16:41 +00:00
<div>
<FormSuspense :p="init">
2023-01-05 12:04:56 +00:00
<div class="_autoGap">
<FormRadios v-model="provider">
2022-07-20 13:24:26 +00:00
<option :value="null">{{ i18n.ts.none }} ({{ i18n.ts.notRecommended }})</option>
2022-01-04 12:16:41 +00:00
<option value="hcaptcha">hCaptcha</option>
<option value="recaptcha">reCAPTCHA</option>
<option value="turnstile">Turnstile</option>
2022-01-04 12:16:41 +00:00
</FormRadios>
2022-01-04 12:16:41 +00:00
<template v-if="provider === 'hcaptcha'">
2023-01-05 12:04:56 +00:00
<FormInput v-model="hcaptchaSiteKey">
<template #prefix><i class="ti ti-key"></i></template>
2022-07-20 13:24:26 +00:00
<template #label>{{ i18n.ts.hcaptchaSiteKey }}</template>
2022-01-04 12:16:41 +00:00
</FormInput>
2023-01-05 12:04:56 +00:00
<FormInput v-model="hcaptchaSecretKey">
<template #prefix><i class="ti ti-key"></i></template>
2022-07-20 13:24:26 +00:00
<template #label>{{ i18n.ts.hcaptchaSecretKey }}</template>
2022-01-04 12:16:41 +00:00
</FormInput>
2023-01-05 12:04:56 +00:00
<FormSlot>
2022-07-20 13:24:26 +00:00
<template #label>{{ i18n.ts.preview }}</template>
<MkCaptcha provider="hcaptcha" :sitekey="hcaptchaSiteKey || '10000000-ffff-ffff-ffff-000000000001'"/>
2022-01-04 12:16:41 +00:00
</FormSlot>
</template>
<template v-else-if="provider === 'recaptcha'">
2023-01-05 12:04:56 +00:00
<FormInput v-model="recaptchaSiteKey">
<template #prefix><i class="ti ti-key"></i></template>
2022-07-20 13:24:26 +00:00
<template #label>{{ i18n.ts.recaptchaSiteKey }}</template>
2022-01-04 12:16:41 +00:00
</FormInput>
2023-01-05 12:04:56 +00:00
<FormInput v-model="recaptchaSecretKey">
<template #prefix><i class="ti ti-key"></i></template>
2022-07-20 13:24:26 +00:00
<template #label>{{ i18n.ts.recaptchaSecretKey }}</template>
2022-01-04 12:16:41 +00:00
</FormInput>
2023-01-05 12:04:56 +00:00
<FormSlot v-if="recaptchaSiteKey">
2022-07-20 13:24:26 +00:00
<template #label>{{ i18n.ts.preview }}</template>
<MkCaptcha provider="recaptcha" :sitekey="recaptchaSiteKey"/>
2022-01-04 12:16:41 +00:00
</FormSlot>
</template>
<template v-else-if="provider === 'turnstile'">
2023-01-05 12:04:56 +00:00
<FormInput v-model="turnstileSiteKey">
<template #prefix><i class="ti ti-key"></i></template>
<template #label>{{ i18n.ts.turnstileSiteKey }}</template>
</FormInput>
2023-01-05 12:04:56 +00:00
<FormInput v-model="turnstileSecretKey">
<template #prefix><i class="ti ti-key"></i></template>
<template #label>{{ i18n.ts.turnstileSecretKey }}</template>
</FormInput>
2023-01-05 12:04:56 +00:00
<FormSlot>
<template #label>{{ i18n.ts.preview }}</template>
<MkCaptcha provider="turnstile" :sitekey="turnstileSiteKey || '1x00000000000000000000AA'"/>
</FormSlot>
</template>
<FormButton primary @click="save"><i class="ti ti-device-floppy"></i> {{ i18n.ts.save }}</FormButton>
2022-01-04 12:16:41 +00:00
</div>
</FormSuspense>
2022-01-04 12:16:41 +00:00
</div>
</template>
<script lang="ts" setup>
import { defineAsyncComponent } from 'vue';
2022-01-04 12:16:41 +00:00
import FormRadios from '@/components/form/radios.vue';
import FormInput from '@/components/form/input.vue';
import FormButton from '@/components/MkButton.vue';
2022-01-04 12:16:41 +00:00
import FormSuspense from '@/components/form/suspense.vue';
import FormSlot from '@/components/form/slot.vue';
2021-11-11 17:02:25 +00:00
import * as os from '@/os';
import { fetchInstance } from '@/instance';
2022-07-20 13:24:26 +00:00
import { i18n } from '@/i18n';
const MkCaptcha = defineAsyncComponent(() => import('@/components/MkCaptcha.vue'));
let provider = $ref(null);
let hcaptchaSiteKey: string | null = $ref(null);
let hcaptchaSecretKey: string | null = $ref(null);
let recaptchaSiteKey: string | null = $ref(null);
let recaptchaSecretKey: string | null = $ref(null);
let turnstileSiteKey: string | null = $ref(null);
let turnstileSecretKey: string | null = $ref(null);
async function init() {
const meta = await os.api('admin/meta');
hcaptchaSiteKey = meta.hcaptchaSiteKey;
hcaptchaSecretKey = meta.hcaptchaSecretKey;
recaptchaSiteKey = meta.recaptchaSiteKey;
recaptchaSecretKey = meta.recaptchaSecretKey;
turnstileSiteKey = meta.turnstileSiteKey;
turnstileSecretKey = meta.turnstileSecretKey;
provider = meta.enableHcaptcha ? 'hcaptcha' : meta.enableRecaptcha ? 'recaptcha' : meta.enableTurnstile ? 'turnstile' : null;
}
function save() {
os.apiWithDialog('admin/update-meta', {
enableHcaptcha: provider === 'hcaptcha',
hcaptchaSiteKey,
hcaptchaSecretKey,
enableRecaptcha: provider === 'recaptcha',
recaptchaSiteKey,
recaptchaSecretKey,
enableTurnstile: provider === 'turnstile',
turnstileSiteKey,
turnstileSecretKey,
}).then(() => {
fetchInstance();
});
}
</script>