chore: 优化域名match

pull/229/head
xiaojunnuo 2024-10-25 18:32:47 +08:00
parent 1cc1d1c03c
commit 7aac1460c3
3 changed files with 70 additions and 6 deletions

View File

@ -26,21 +26,21 @@ function match(targetDomains: string | string[], inDomains: string[]) {
if (!inDomain.startsWith('*.')) {
//不可能匹配
break;
continue;
}
//子域名匹配通配符即可
if (targetDomain === inDomain.substring(2)) {
const firstDotIndex = targetDomain.indexOf('.');
const targetDomainSuffix = targetDomain.substring(firstDotIndex + 1);
if (targetDomainSuffix === inDomain.substring(2)) {
matched = true;
break;
}
}
//有一个没有匹配上,就失败
if (matched) {
//这个匹配上了,检查下一个
break;
} else {
if (!matched) {
return false;
}
//这个匹配上了,检查下一个
}
//没有提前return 全部匹配上了
return true;

View File

@ -0,0 +1,62 @@
<template>
<div class="api-test">
<div>
<fs-button :loading="loading" type="primary" text="测试" icon="ion:refresh-outline" @click="doTest"></fs-button>
</div>
<div class="helper" :class="{ error: hasError }">
{{ message }}
</div>
</div>
</template>
<script setup lang="ts">
import { ComponentPropsType, doRequest } from "/@/components/plugins/lib";
import { ref } from "vue";
defineOptions({
name: "ApiTest"
});
const props = defineProps<{} & ComponentPropsType>();
const emit = defineEmits<{
"update:value": any;
}>();
const message = ref("");
const hasError = ref(false);
const loading = ref(false);
const doTest = async () => {
if (loading.value) {
return;
}
message.value = "";
hasError.value = false;
loading.value = true;
try {
const res = await doRequest(
{
type: props.type,
typeName: props.typeName,
action: props.action,
input: props.form
},
{
onError(err: any) {
hasError.value = true;
message.value = `错误:${err.message}`;
},
showErrorNotify: false
}
);
if (res && res.length > 0) {
message.value = "测试请求成功";
}
} finally {
loading.value = false;
}
};
</script>
<style lang="less"></style>

View File

@ -6,6 +6,7 @@ import DnsProviderSelector from "/@/components/plugins/cert/dns-provider-selecto
import DomainsVerifyPlanEditor from "/@/components/plugins/cert/domains-verify-plan-editor/index.vue";
import AccessSelector from "/@/views/certd/access/access-selector/index.vue";
import InputPassword from "./common/input-password.vue";
import ApiTest from "./common/api-test.vue";
export * from "./cert/index.js";
export default {
install(app: any) {
@ -13,6 +14,7 @@ export default {
app.component("DnsProviderSelector", DnsProviderSelector);
app.component("DomainsVerifyPlanEditor", DomainsVerifyPlanEditor);
app.component("AccessSelector", AccessSelector);
app.component("ApiTest", ApiTest);
app.component("SynologyDeviceIdGetter", SynologyIdDeviceGetter);
app.component("RemoteSelect", RemoteSelect);