feat: allow storage endpoint updates and deletion

This commit is contained in:
237899745
2026-07-25 16:41:31 +08:00
parent 0fe3d4ce8e
commit d29f43d2e3
5 changed files with 188 additions and 68 deletions

View File

@@ -40,8 +40,16 @@ const emptyForm = () => ({
})
const form = ref(emptyForm())
const editingEndpoint = computed(() => endpoints.value.find((endpoint) => endpoint.id === editingId.value))
const formTitle = computed(() => (editingId.value ? '编辑存储端点' : '新增存储端点'))
const submitLabel = computed(() => (editingId.value ? '保存并停用待测' : '保存端点'))
const submitLabel = computed(() => (editingId.value ? '测试并保存' : '保存端点'))
const formDescription = computed(() => {
if (!editingId.value) return '新增端点保存后保持停用,请执行全链路测试并手动启用。'
if (editingEndpoint.value?.is_active) {
return '保存前会测试候选配置和一个历史对象;全部通过后替换配置,并保持活动状态。'
}
return '保存前会测试候选配置和一个历史对象;全部通过后替换配置,端点保持停用。'
})
function errorText(err: unknown, fallback: string) {
if (err instanceof ApiError) return `[${err.code}] ${err.message}`
@@ -121,8 +129,10 @@ async function submitForm() {
if (form.value.secret_key.trim()) payload.secret_key = form.value.secret_key.trim()
if (editingId.value) {
await updateStorageEndpoint(auth.token, editingId.value, payload)
message.value = '端点已保存并停用,请重新测试后启用。'
const updated = await updateStorageEndpoint(auth.token, editingId.value, payload)
message.value = updated.is_active
? '配置已保存并通过全链路测试,端点保持活动。'
: '配置已保存并通过全链路测试,端点保持停用。'
} else {
if (!payload.access_key || !payload.secret_key) {
error.value = '新增端点必须填写 Access Key 和 Secret Key。'
@@ -183,7 +193,16 @@ async function activate(endpoint: AdminStorageEndpoint) {
async function removeEndpoint(endpoint: AdminStorageEndpoint) {
if (!auth.token) return
const confirmed = window.confirm(`确定删除“${endpoint.name}”吗?关联对象未清空时后端会拒绝删除。`)
const effects = [`确定删除“${endpoint.name}”吗?删除后端点将立即从管理列表移除。`]
if (endpoint.is_active) {
effects.push('这是当前活动端点;删除后新文件将回退到应用服务器本地,直到启用其他 S3。')
}
if (endpoint.object_count > 0) {
effects.push(
`现有 ${endpoint.object_count} 个历史对象仍可通过原配置下载,关联对象过期清理后凭据才会自动移除。`,
)
}
const confirmed = window.confirm(effects.join('\n\n'))
if (!confirmed) return
busy.value = `delete:${endpoint.id}`
@@ -305,9 +324,9 @@ onMounted(loadEndpoints)
<div class="flex flex-wrap gap-2">
<button
v-if="!endpoint.is_active && endpoint.object_count === 0"
class="rounded-md border border-slate-300 px-3 py-1.5 text-sm text-slate-700 hover:bg-white"
class="rounded-md border border-slate-300 px-3 py-1.5 text-sm text-slate-700 hover:bg-white disabled:opacity-50"
type="button"
:disabled="busy !== null"
@click="openEdit(endpoint)"
>
编辑
@@ -330,10 +349,9 @@ onMounted(loadEndpoints)
{{ busy === `activate:${endpoint.id}` ? '验证并启用...' : '验证并启用' }}
</button>
<button
v-if="!endpoint.is_active"
class="rounded-md px-3 py-1.5 text-sm text-rose-700 hover:bg-rose-50 disabled:opacity-50"
type="button"
:disabled="busy !== null || endpoint.object_count > 0"
:disabled="busy !== null"
@click="removeEndpoint(endpoint)"
>
删除
@@ -348,7 +366,7 @@ onMounted(loadEndpoints)
<div class="flex items-center justify-between gap-3">
<div>
<h3 class="font-semibold text-slate-900">{{ formTitle }}</h3>
<p class="mt-1 text-sm text-slate-500">编辑连接参数后端点会自动停用避免未经验证的配置接收新文件</p>
<p class="mt-1 text-sm text-slate-500">{{ formDescription }}</p>
</div>
<button type="button" class="text-sm text-slate-500 hover:text-slate-900" @click="closeForm">关闭</button>
</div>