mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-09 03:43:08 +02:00
Refactor admin/security to use Composition API (#8652)
* refactor(client): refactor admin/security to use Composition API * Apply review suggestions from @Johann150 Co-authored-by: Johann150 <johann@qwertqwefsday.eu> Co-authored-by: Johann150 <johann@qwertqwefsday.eu>
This commit is contained in:
parent
9f07bd8f46
commit
5de77405ea
2 changed files with 59 additions and 101 deletions
|
@ -43,8 +43,8 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineAsyncComponent, defineComponent } from 'vue';
|
import { defineAsyncComponent } from 'vue';
|
||||||
import FormRadios from '@/components/form/radios.vue';
|
import FormRadios from '@/components/form/radios.vue';
|
||||||
import FormInput from '@/components/form/input.vue';
|
import FormInput from '@/components/form/input.vue';
|
||||||
import FormButton from '@/components/ui/button.vue';
|
import FormButton from '@/components/ui/button.vue';
|
||||||
|
@ -54,64 +54,39 @@ import * as os from '@/os';
|
||||||
import * as symbols from '@/symbols';
|
import * as symbols from '@/symbols';
|
||||||
import { fetchInstance } from '@/instance';
|
import { fetchInstance } from '@/instance';
|
||||||
|
|
||||||
export default defineComponent({
|
const MkCaptcha = defineAsyncComponent(() => import('@/components/captcha.vue'));
|
||||||
components: {
|
|
||||||
FormRadios,
|
|
||||||
FormInput,
|
|
||||||
FormButton,
|
|
||||||
FormSuspense,
|
|
||||||
FormSlot,
|
|
||||||
MkCaptcha: defineAsyncComponent(() => import('@/components/captcha.vue')),
|
|
||||||
},
|
|
||||||
|
|
||||||
emits: ['info'],
|
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);
|
||||||
|
|
||||||
data() {
|
const enableHcaptcha = $computed(() => provider === 'hcaptcha');
|
||||||
return {
|
const enableRecaptcha = $computed(() => provider === 'recaptcha');
|
||||||
[symbols.PAGE_INFO]: {
|
|
||||||
title: this.$ts.botProtection,
|
|
||||||
icon: 'fas fa-shield-alt'
|
|
||||||
},
|
|
||||||
provider: null,
|
|
||||||
enableHcaptcha: false,
|
|
||||||
hcaptchaSiteKey: null,
|
|
||||||
hcaptchaSecretKey: null,
|
|
||||||
enableRecaptcha: false,
|
|
||||||
recaptchaSiteKey: null,
|
|
||||||
recaptchaSecretKey: null,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
async function init() {
|
||||||
async init() {
|
|
||||||
const meta = await os.api('admin/meta');
|
const meta = await os.api('admin/meta');
|
||||||
this.enableHcaptcha = meta.enableHcaptcha;
|
enableHcaptcha = meta.enableHcaptcha;
|
||||||
this.hcaptchaSiteKey = meta.hcaptchaSiteKey;
|
hcaptchaSiteKey = meta.hcaptchaSiteKey;
|
||||||
this.hcaptchaSecretKey = meta.hcaptchaSecretKey;
|
hcaptchaSecretKey = meta.hcaptchaSecretKey;
|
||||||
this.enableRecaptcha = meta.enableRecaptcha;
|
enableRecaptcha = meta.enableRecaptcha;
|
||||||
this.recaptchaSiteKey = meta.recaptchaSiteKey;
|
recaptchaSiteKey = meta.recaptchaSiteKey;
|
||||||
this.recaptchaSecretKey = meta.recaptchaSecretKey;
|
recaptchaSecretKey = meta.recaptchaSecretKey;
|
||||||
|
|
||||||
this.provider = this.enableHcaptcha ? 'hcaptcha' : this.enableRecaptcha ? 'recaptcha' : null;
|
provider = enableHcaptcha ? 'hcaptcha' : enableRecaptcha ? 'recaptcha' : null;
|
||||||
|
}
|
||||||
|
|
||||||
this.$watch(() => this.provider, () => {
|
function save() {
|
||||||
this.enableHcaptcha = this.provider === 'hcaptcha';
|
|
||||||
this.enableRecaptcha = this.provider === 'recaptcha';
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
save() {
|
|
||||||
os.apiWithDialog('admin/update-meta', {
|
os.apiWithDialog('admin/update-meta', {
|
||||||
enableHcaptcha: this.enableHcaptcha,
|
enableHcaptcha,
|
||||||
hcaptchaSiteKey: this.hcaptchaSiteKey,
|
hcaptchaSiteKey,
|
||||||
hcaptchaSecretKey: this.hcaptchaSecretKey,
|
hcaptchaSecretKey,
|
||||||
enableRecaptcha: this.enableRecaptcha,
|
enableRecaptcha,
|
||||||
recaptchaSiteKey: this.recaptchaSiteKey,
|
recaptchaSiteKey,
|
||||||
recaptchaSecretKey: this.recaptchaSecretKey,
|
recaptchaSecretKey,
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
fetchInstance();
|
fetchInstance();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -4,10 +4,10 @@
|
||||||
<div class="_formRoot">
|
<div class="_formRoot">
|
||||||
<FormFolder class="_formBlock">
|
<FormFolder class="_formBlock">
|
||||||
<template #icon><i class="fas fa-shield-alt"></i></template>
|
<template #icon><i class="fas fa-shield-alt"></i></template>
|
||||||
<template #label>{{ $ts.botProtection }}</template>
|
<template #label>{{ i18n.ts.botProtection }}</template>
|
||||||
<template v-if="enableHcaptcha" #suffix>hCaptcha</template>
|
<template v-if="enableHcaptcha" #suffix>hCaptcha</template>
|
||||||
<template v-else-if="enableRecaptcha" #suffix>reCAPTCHA</template>
|
<template v-else-if="enableRecaptcha" #suffix>reCAPTCHA</template>
|
||||||
<template v-else #suffix>{{ $ts.none }} ({{ $ts.notRecommended }})</template>
|
<template v-else #suffix>{{ i18n.ts.none }} ({{ i18n.ts.notRecommended }})</template>
|
||||||
|
|
||||||
<XBotProtection/>
|
<XBotProtection/>
|
||||||
</FormFolder>
|
</FormFolder>
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
<template #label>Summaly Proxy URL</template>
|
<template #label>Summaly Proxy URL</template>
|
||||||
</FormInput>
|
</FormInput>
|
||||||
|
|
||||||
<FormButton primary class="_formBlock" @click="save"><i class="fas fa-save"></i> {{ $ts.save }}</FormButton>
|
<FormButton primary class="_formBlock" @click="save"><i class="fas fa-save"></i> {{ i18n.ts.save }}</FormButton>
|
||||||
</div>
|
</div>
|
||||||
</FormFolder>
|
</FormFolder>
|
||||||
</div>
|
</div>
|
||||||
|
@ -29,8 +29,8 @@
|
||||||
</MkSpacer>
|
</MkSpacer>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineAsyncComponent, defineComponent } from 'vue';
|
import { } from 'vue';
|
||||||
import FormFolder from '@/components/form/folder.vue';
|
import FormFolder from '@/components/form/folder.vue';
|
||||||
import FormSwitch from '@/components/form/switch.vue';
|
import FormSwitch from '@/components/form/switch.vue';
|
||||||
import FormInfo from '@/components/ui/info.vue';
|
import FormInfo from '@/components/ui/info.vue';
|
||||||
|
@ -42,49 +42,32 @@ import XBotProtection from './bot-protection.vue';
|
||||||
import * as os from '@/os';
|
import * as os from '@/os';
|
||||||
import * as symbols from '@/symbols';
|
import * as symbols from '@/symbols';
|
||||||
import { fetchInstance } from '@/instance';
|
import { fetchInstance } from '@/instance';
|
||||||
|
import { i18n } from '@/i18n';
|
||||||
|
|
||||||
export default defineComponent({
|
let summalyProxy: string = $ref('');
|
||||||
components: {
|
let enableHcaptcha: boolean = $ref(false);
|
||||||
FormFolder,
|
let enableRecaptcha: boolean = $ref(false);
|
||||||
FormSwitch,
|
|
||||||
FormInfo,
|
|
||||||
FormSection,
|
|
||||||
FormSuspense,
|
|
||||||
FormButton,
|
|
||||||
FormInput,
|
|
||||||
XBotProtection,
|
|
||||||
},
|
|
||||||
|
|
||||||
emits: ['info'],
|
async function init() {
|
||||||
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
[symbols.PAGE_INFO]: {
|
|
||||||
title: this.$ts.security,
|
|
||||||
icon: 'fas fa-lock',
|
|
||||||
bg: 'var(--bg)',
|
|
||||||
},
|
|
||||||
summalyProxy: '',
|
|
||||||
enableHcaptcha: false,
|
|
||||||
enableRecaptcha: false,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
async init() {
|
|
||||||
const meta = await os.api('admin/meta');
|
const meta = await os.api('admin/meta');
|
||||||
this.summalyProxy = meta.summalyProxy;
|
summalyProxy = meta.summalyProxy;
|
||||||
this.enableHcaptcha = meta.enableHcaptcha;
|
enableHcaptcha = meta.enableHcaptcha;
|
||||||
this.enableRecaptcha = meta.enableRecaptcha;
|
enableRecaptcha = meta.enableRecaptcha;
|
||||||
},
|
}
|
||||||
|
|
||||||
save() {
|
function save() {
|
||||||
os.apiWithDialog('admin/update-meta', {
|
os.apiWithDialog('admin/update-meta', {
|
||||||
summalyProxy: this.summalyProxy,
|
summalyProxy,
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
fetchInstance();
|
fetchInstance();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
[symbols.PAGE_INFO]: {
|
||||||
|
title: i18n.ts.security,
|
||||||
|
icon: 'fas fa-lock',
|
||||||
|
bg: 'var(--bg)',
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue