fix(storage): 存储管理 S3 存储功能修复 (#5)

1、S3存储管理功能及文件上传回显测试通过
2、修复S3协议存储无法编辑
3、对S3私钥配置信息脱密
This commit is contained in:
kils
2024-04-23 20:21:07 +08:00
committed by GitHub
parent 2987d3eb4d
commit fa7705fd76
2 changed files with 22 additions and 5 deletions

View File

@@ -16,13 +16,18 @@
<a-input v-model.trim="form.code" placeholder="请输入编码" :disabled="isUpdate" /> <a-input v-model.trim="form.code" placeholder="请输入编码" :disabled="isUpdate" />
</a-form-item> </a-form-item>
<a-form-item label="类型" field="type"> <a-form-item label="类型" field="type">
<a-select v-model.trim="form.type" :options="storage_type_enum" placeholder="请选择类型" /> <a-select v-model.trim="form.type" :options="storage_type_enum" placeholder="请选择类型" :disabled="isUpdate" />
</a-form-item> </a-form-item>
<a-form-item v-if="form.type === 1" label="访问密钥" field="accessKey"> <a-form-item v-if="form.type === 1" label="访问密钥" field="accessKey">
<a-input v-model.trim="form.accessKey" placeholder="请输入访问密钥" /> <a-input v-model.trim="form.accessKey" placeholder="请输入访问密钥" :max-length="255" />
</a-form-item> </a-form-item>
<a-form-item v-if="form.type === 1" label="私有密钥" field="secretKey"> <a-form-item v-if="form.type === 1" label="私有密钥" field="secretKey">
<a-input v-model.trim="form.secretKey" placeholder="请输入私有密钥" /> <a-input
v-model.trim="form.secretKey"
placeholder="请输入私有密钥"
: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">
<a-input v-model.trim="form.endpoint" placeholder="请输入终端节点" /> <a-input v-model.trim="form.endpoint" placeholder="请输入终端节点" />
@@ -89,11 +94,13 @@ import { Message, type FormInstance } from '@arco-design/web-vue'
import { useForm } from '@/hooks' import { useForm } from '@/hooks'
import { useDict } from '@/hooks/app' import { useDict } from '@/hooks/app'
import { useWindowSize } from '@vueuse/core' import { useWindowSize } from '@vueuse/core'
import { encryptByRsa } from '@/utils/encrypt'
const { width } = useWindowSize() const { width } = useWindowSize()
const { storage_type_enum } = useDict('storage_type_enum') const { storage_type_enum } = useDict('storage_type_enum')
const dataId = ref('') const dataId = ref('')
const updatedSecretKey = ref(false)
const isUpdate = computed(() => !!dataId.value) const isUpdate = computed(() => !!dataId.value)
const title = computed(() => (isUpdate.value ? '修改存储' : '新增存储')) const title = computed(() => (isUpdate.value ? '修改存储' : '新增存储'))
const formRef = ref<FormInstance>() const formRef = ref<FormInstance>()
@@ -113,6 +120,7 @@ const { form, resetForm } = useForm<StorageReq>({
code: '', code: '',
type: 2, type: 2,
accessKey: undefined, accessKey: undefined,
secretKeyEncrypted: undefined,
secretKey: undefined, secretKey: undefined,
endpoint: undefined, endpoint: undefined,
bucketName: undefined, bucketName: undefined,
@@ -146,16 +154,24 @@ const onUpdate = async (id: string) => {
visible.value = true visible.value = true
} }
const updateSecretKey = () => {
updatedSecretKey.value = true
}
// 保存 // 保存
const save = async () => { const save = async () => {
try { try {
const isInvalid = await formRef.value?.validate() const isInvalid = await formRef.value?.validate()
if (isInvalid) return false if (isInvalid) return false
const data = Object.assign({}, form)
if (data.type === 1) {
data.secretKey = updatedSecretKey.value ? encryptByRsa(form.secretKey) : form.secretKeyEncrypted
}
if (isUpdate.value) { if (isUpdate.value) {
await updateStorage(form, dataId.value) await updateStorage(data, dataId.value)
Message.success('修改成功') Message.success('修改成功')
} else { } else {
await addStorage(form) await addStorage(data)
Message.success('新增成功') Message.success('新增成功')
} }
emit('save-success') emit('save-success')

View File

@@ -4,6 +4,7 @@ export interface StorageReq {
type: number type: number
accessKey: string accessKey: string
secretKey: string secretKey: string
secretKeyEncrypted: string
endpoint: string endpoint: string
bucketName: string bucketName: string
domain: string domain: string