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

115 lines
4.3 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
2022-01-04 13:16:41 +01:00
<div>
<FormSuspense :p="init">
2023-01-06 05:40:17 +01:00
<div class="_gaps_m">
2023-01-07 07:09:46 +01:00
<MkRadios v-model="provider">
2022-07-20 15:24:26 +02:00
<option :value="null">{{ i18n.ts.none }} ({{ i18n.ts.notRecommended }})</option>
2022-01-04 13:16:41 +01:00
<option value="hcaptcha">hCaptcha</option>
<option value="recaptcha">reCAPTCHA</option>
<option value="turnstile">Turnstile</option>
2023-01-07 07:09:46 +01:00
</MkRadios>
2022-01-04 13:16:41 +01:00
<template v-if="provider === 'hcaptcha'">
2023-01-07 07:09:46 +01:00
<MkInput v-model="hcaptchaSiteKey">
2023-09-30 21:53:52 +02:00
<template #prefix><i class="ph-key ph-bold ph-lg"></i></template>
2022-07-20 15:24:26 +02:00
<template #label>{{ i18n.ts.hcaptchaSiteKey }}</template>
2023-01-07 07:09:46 +01:00
</MkInput>
<MkInput v-model="hcaptchaSecretKey">
2023-09-30 21:53:52 +02:00
<template #prefix><i class="ph-key ph-bold ph-lg"></i></template>
2022-07-20 15:24:26 +02:00
<template #label>{{ i18n.ts.hcaptchaSecretKey }}</template>
2023-01-07 07:09:46 +01:00
</MkInput>
2023-01-05 13:04:56 +01:00
<FormSlot>
2022-07-20 15:24:26 +02:00
<template #label>{{ i18n.ts.preview }}</template>
<MkCaptcha provider="hcaptcha" :sitekey="hcaptchaSiteKey || '10000000-ffff-ffff-ffff-000000000001'"/>
2022-01-04 13:16:41 +01:00
</FormSlot>
</template>
<template v-else-if="provider === 'recaptcha'">
2023-01-07 07:09:46 +01:00
<MkInput v-model="recaptchaSiteKey">
2023-09-30 21:53:52 +02:00
<template #prefix><i class="ph-key ph-bold ph-lg"></i></template>
2022-07-20 15:24:26 +02:00
<template #label>{{ i18n.ts.recaptchaSiteKey }}</template>
2023-01-07 07:09:46 +01:00
</MkInput>
<MkInput v-model="recaptchaSecretKey">
2023-09-30 21:53:52 +02:00
<template #prefix><i class="ph-key ph-bold ph-lg"></i></template>
2022-07-20 15:24:26 +02:00
<template #label>{{ i18n.ts.recaptchaSecretKey }}</template>
2023-01-07 07:09:46 +01:00
</MkInput>
2023-01-05 13:04:56 +01:00
<FormSlot v-if="recaptchaSiteKey">
2022-07-20 15:24:26 +02:00
<template #label>{{ i18n.ts.preview }}</template>
<MkCaptcha provider="recaptcha" :sitekey="recaptchaSiteKey"/>
2022-01-04 13:16:41 +01:00
</FormSlot>
</template>
<template v-else-if="provider === 'turnstile'">
2023-01-07 07:09:46 +01:00
<MkInput v-model="turnstileSiteKey">
2023-09-30 21:53:52 +02:00
<template #prefix><i class="ph-key ph-bold ph-lg"></i></template>
<template #label>{{ i18n.ts.turnstileSiteKey }}</template>
2023-01-07 07:09:46 +01:00
</MkInput>
<MkInput v-model="turnstileSecretKey">
2023-09-30 21:53:52 +02:00
<template #prefix><i class="ph-key ph-bold ph-lg"></i></template>
<template #label>{{ i18n.ts.turnstileSecretKey }}</template>
2023-01-07 07:09:46 +01:00
</MkInput>
2023-01-05 13:04:56 +01:00
<FormSlot>
<template #label>{{ i18n.ts.preview }}</template>
<MkCaptcha provider="turnstile" :sitekey="turnstileSiteKey || '1x00000000000000000000AA'"/>
</FormSlot>
</template>
<MkButton primary @click="save"><i class="ph-floppy-disk ph-bold ph-lg"></i> {{ i18n.ts.save }}</MkButton>
2022-01-04 13:16:41 +01:00
</div>
</FormSuspense>
2022-01-04 13:16:41 +01:00
</div>
</template>
<script lang="ts" setup>
import { defineAsyncComponent, ref } from 'vue';
2023-01-07 07:09:46 +01:00
import MkRadios from '@/components/MkRadios.vue';
import MkInput from '@/components/MkInput.vue';
2023-01-06 01:41:14 +01:00
import MkButton from '@/components/MkButton.vue';
2022-01-04 13:16:41 +01:00
import FormSuspense from '@/components/form/suspense.vue';
import FormSlot from '@/components/form/slot.vue';
2023-09-19 09:37:43 +02:00
import * as os from '@/os.js';
import { fetchInstance } from '@/instance.js';
import { i18n } from '@/i18n.js';
const MkCaptcha = defineAsyncComponent(() => import('@/components/MkCaptcha.vue'));
const provider = ref(null);
const hcaptchaSiteKey = ref<string | null>(null);
const hcaptchaSecretKey = ref<string | null>(null);
const recaptchaSiteKey = ref<string | null>(null);
const recaptchaSecretKey = ref<string | null>(null);
const turnstileSiteKey = ref<string | null>(null);
const turnstileSecretKey = ref<string | null>(null);
async function init() {
const meta = await os.api('admin/meta');
hcaptchaSiteKey.value = meta.hcaptchaSiteKey;
hcaptchaSecretKey.value = meta.hcaptchaSecretKey;
recaptchaSiteKey.value = meta.recaptchaSiteKey;
recaptchaSecretKey.value = meta.recaptchaSecretKey;
turnstileSiteKey.value = meta.turnstileSiteKey;
turnstileSecretKey.value = meta.turnstileSecretKey;
provider.value = meta.enableHcaptcha ? 'hcaptcha' : meta.enableRecaptcha ? 'recaptcha' : meta.enableTurnstile ? 'turnstile' : null;
}
function save() {
os.apiWithDialog('admin/update-meta', {
enableHcaptcha: provider.value === 'hcaptcha',
hcaptchaSiteKey: hcaptchaSiteKey.value,
hcaptchaSecretKey: hcaptchaSecretKey.value,
enableRecaptcha: provider.value === 'recaptcha',
recaptchaSiteKey: recaptchaSiteKey.value,
recaptchaSecretKey: recaptchaSecretKey.value,
enableTurnstile: provider.value === 'turnstile',
turnstileSiteKey: turnstileSiteKey.value,
turnstileSecretKey: turnstileSecretKey.value,
}).then(() => {
fetchInstance();
});
}
</script>