mirror of
https://github.com/continew-org/continew-admin-ui.git
synced 2025-09-09 20:57:17 +08:00
feat: 存储管理S3存储配置填充默认域名 (#21)
This commit is contained in:
@@ -8,3 +8,9 @@ export const isExternal = (path: string) => {
|
|||||||
export function isHttp(url: string) {
|
export function isHttp(url: string) {
|
||||||
return url.includes('http://') || url.includes('https://')
|
return url.includes('http://') || url.includes('https://')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 判断 字符串 是否是 ipv4 */
|
||||||
|
export function isIPv4(ip: string): boolean {
|
||||||
|
const ipv4Pattern = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
|
||||||
|
return ipv4Pattern.test(ip)
|
||||||
|
}
|
||||||
|
@@ -26,7 +26,6 @@
|
|||||||
v-model.trim="form.secretKey"
|
v-model.trim="form.secretKey"
|
||||||
placeholder="请输入私有密钥"
|
placeholder="请输入私有密钥"
|
||||||
:max-length="255"
|
:max-length="255"
|
||||||
@input="updateSecretKey"
|
|
||||||
/>
|
/>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item v-if="form.type === 1" label="终端节点" field="endpoint">
|
<a-form-item v-if="form.type === 1" label="终端节点" field="endpoint">
|
||||||
@@ -37,6 +36,11 @@
|
|||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item v-if="form.type === 1" label="域名" field="domain">
|
<a-form-item v-if="form.type === 1" label="域名" field="domain">
|
||||||
<a-input v-model.trim="form.domain" placeholder="请输入域名" />
|
<a-input v-model.trim="form.domain" placeholder="请输入域名" />
|
||||||
|
<template #extra>
|
||||||
|
<div v-if="defaultDomain">
|
||||||
|
<span>留空默认域名:{{ defaultDomain }}</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item
|
<a-form-item
|
||||||
v-if="form.type === 2"
|
v-if="form.type === 2"
|
||||||
@@ -94,6 +98,7 @@ import { addStorage, getStorage, updateStorage } from '@/apis'
|
|||||||
import { useForm } from '@/hooks'
|
import { useForm } from '@/hooks'
|
||||||
import { useDict } from '@/hooks/app'
|
import { useDict } from '@/hooks/app'
|
||||||
import { encryptByRsa } from '@/utils/encrypt'
|
import { encryptByRsa } from '@/utils/encrypt'
|
||||||
|
import { isIPv4 } from '@/utils/validate'
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
(e: 'save-success'): void
|
(e: 'save-success'): void
|
||||||
@@ -122,6 +127,24 @@ const { form, resetForm } = useForm({
|
|||||||
sort: 999,
|
sort: 999,
|
||||||
status: 1
|
status: 1
|
||||||
})
|
})
|
||||||
|
/** 获取url的protocol和endpoint */
|
||||||
|
const stripProtocol = (url: string): { endpoint: string, protocol: string } => {
|
||||||
|
if (url.startsWith('http://')) {
|
||||||
|
return { endpoint: url.substring(7), protocol: 'http://' }
|
||||||
|
} else if (url.startsWith('https://')) {
|
||||||
|
return { endpoint: url.substring(8), protocol: 'https://' }
|
||||||
|
}
|
||||||
|
return { endpoint: url, protocol: 'http://' }
|
||||||
|
}
|
||||||
|
/** 按规则拼接当前默认domain */
|
||||||
|
const defaultDomain = computed(() => {
|
||||||
|
const { endpoint: initialEndpoint, bucketName, domain, type } = form
|
||||||
|
if (domain || type !== 1 || !initialEndpoint || !bucketName) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const { endpoint, protocol } = stripProtocol(initialEndpoint)
|
||||||
|
return isIPv4(endpoint) ? `${protocol}${endpoint}/${bucketName}/` : `${protocol}${bucketName}.${endpoint}/`
|
||||||
|
})
|
||||||
|
|
||||||
// 重置
|
// 重置
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
@@ -153,7 +176,8 @@ const save = async () => {
|
|||||||
if (isInvalid) return false
|
if (isInvalid) return false
|
||||||
const data = {
|
const data = {
|
||||||
...form,
|
...form,
|
||||||
secretKey: form.type === 1 && !form.secretKey.includes('*') ? encryptByRsa(form.secretKey) : null
|
secretKey: form.type === 1 && !form.secretKey.includes('*') ? encryptByRsa(form.secretKey) : null,
|
||||||
|
domain: form.domain || defaultDomain.value
|
||||||
}
|
}
|
||||||
if (isUpdate.value) {
|
if (isUpdate.value) {
|
||||||
await updateStorage(data, dataId.value)
|
await updateStorage(data, dataId.value)
|
||||||
|
Reference in New Issue
Block a user