完善证书任务取消超时与幂等处理

This commit is contained in:
xuans committed 2026-08-30 21:22:51 +08:00
1 parent 794734c1df
commit 8b1d1853e3
7 files changed
+307 -39

No files matched your search

+7 -1
View File
@@ -183,7 +183,13 @@ h2 {
border-radius: 11px;
background: #fbfcfe;
}
.record-row > div {
.record-row-actions {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 10px;
flex-wrap: wrap;
}.record-row > div {
display: grid;
gap: 5px;
min-width: 0;
+36 -5
View File
@@ -92,7 +92,13 @@ export function useDashboard() {
wildcard: "泛域名",
san: "SAN 多域名",
};
const domainStatusLabels = {
const taskStatusLabels = {
queued: "排队中",
running: "执行中",
success: "已完成",
failed: "失败",
cancelled: "已取消",
}; const domainStatusLabels = {
pending: "等待申请",
active: "正常",
error: "错误",
@@ -484,9 +490,12 @@ export function useDashboard() {
error.value = "";
notice.value = "";
try {
const response = await fetchAdmin(`/api/v1/domains/${item.id}/${action}`, {
method: "POST",
});
const options = { method: "POST" };
if (action === "issue") {
const suffix = crypto.randomUUID ? crypto.randomUUID() : createSSHKeyRandomSuffix();
options.headers = { "Idempotency-Key": `issue-${item.id}-${suffix}` };
}
const response = await fetchAdmin(`/api/v1/domains/${item.id}/${action}`, options);
const result = await response.json().catch(() => ({}));
if (!response.ok) throw new Error(result.error || "域名操作失败");
notice.value = successMessage;
@@ -495,7 +504,6 @@ export function useDashboard() {
error.value = err.message || "域名操作失败";
}
}
function issueDomain(item) {
return runDomainAction(item, "issue", `已提交 ${item.name} 的证书申请`);
}
@@ -508,6 +516,20 @@ export function useDashboard() {
return runDomainAction(item, "deploy", `已提交 ${item.name} 的证书部署`);
}
async function cancelTask(item) {
if (!window.confirm("确定取消这项正在执行的证书任务吗?")) return;
error.value = "";
notice.value = "";
try {
const response = await fetchAdmin(`/api/v1/tasks/${item.id}`, { method: "DELETE" });
const result = await response.json().catch(() => ({}));
if (!response.ok) throw new Error(result.error || "取消任务失败");
notice.value = "证书任务已取消";
await loadData();
} catch (err) {
error.value = err.message || "取消任务失败";
}
}
async function runRenewalNow() {
error.value = "";
notice.value = "";
@@ -821,6 +843,7 @@ export function useDashboard() {
sshKeyFormError,
certificateTypeLabels,
domainStatusLabels,
taskStatusLabels,
httpsModeLabels,
environmentLabels,
webServerLabels,
@@ -870,6 +893,14 @@ export function useDashboard() {
deleteServer,
saveDomain,
deleteDomain,
issueDomain,
validateDomain,
deployDomain,
cancelTask,
runRenewalNow,
openSettings,
closeSettings,
saveSettings,
loadData,
displayLabel,
formatDate,
+13 -1
View File
@@ -30,6 +30,7 @@ const {
sshKeyFormError,
certificateTypeLabels,
domainStatusLabels,
taskStatusLabels,
httpsModeLabels,
environmentLabels,
webServerLabels,
@@ -78,6 +79,7 @@ const {
validateDomain,
deployDomain,
runRenewalNow,
cancelTask,
displayLabel,
formatDate,
daysRemaining,
@@ -199,7 +201,17 @@ const {
<strong>{{ item.task_type }}</strong>
<span class="muted">{{ item.message || "无附加信息" }}</span>
</div>
<span class="tag" :class="statusClass(item.status)">{{ item.status }}</span>
<div class="record-row-actions">
<span class="tag" :class="statusClass(item.status)">{{ displayLabel(taskStatusLabels, item.status) }}</span>
<button
v-if="item.status === 'queued' || item.status === 'running'"
class="text-button"
type="button"
@click="cancelTask(item)"
>
取消任务
</button>
</div>
</article>
</div>
</div>