feat: 密钥调整为异步任务,取消数量限制
This commit is contained in:
@@ -62,7 +62,7 @@ export const keysApi = {
|
||||
return res.data;
|
||||
},
|
||||
|
||||
// 批量添加密钥
|
||||
// 批量添加密钥-已弃用
|
||||
async addMultipleKeys(
|
||||
group_id: number,
|
||||
keys_text: string
|
||||
@@ -78,6 +78,15 @@ export const keysApi = {
|
||||
return res.data;
|
||||
},
|
||||
|
||||
// 异步批量添加密钥
|
||||
async addKeysAsync(group_id: number, keys_text: string): Promise<TaskInfo> {
|
||||
const res = await http.post("/keys/add-async", {
|
||||
group_id,
|
||||
keys_text,
|
||||
});
|
||||
return res.data;
|
||||
},
|
||||
|
||||
// 测试密钥
|
||||
async testKeys(
|
||||
group_id: number,
|
||||
|
@@ -5,7 +5,7 @@ import { appState } from "@/utils/app-state";
|
||||
import { NButton, NCard, NProgress, NText, useMessage } from "naive-ui";
|
||||
import { onBeforeUnmount, onMounted, ref, watch } from "vue";
|
||||
|
||||
const taskInfo = ref<TaskInfo>({ is_running: false });
|
||||
const taskInfo = ref<TaskInfo>({ is_running: false, task_type: "KEY_VALIDATION" });
|
||||
const visible = ref(false);
|
||||
let pollTimer: number | null = null;
|
||||
let isPolling = false; // 添加标志位
|
||||
@@ -46,8 +46,15 @@ async function pollOnce() {
|
||||
if (task.result) {
|
||||
const lastTask = localStorage.getItem("last_closed_task");
|
||||
if (lastTask !== task.finished_at) {
|
||||
const { total_keys, valid_keys, invalid_keys } = task.result;
|
||||
const msg = `任务已完成,处理了 ${total_keys} 个密钥,其中 ${valid_keys} 个有效密钥,${invalid_keys} 个无效密钥。`;
|
||||
let msg = "任务已完成。";
|
||||
if (task.task_type === "KEY_VALIDATION") {
|
||||
const result = task.result as import("@/types/models").KeyValidationResult;
|
||||
msg = `密钥验证完成,处理了 ${result.total_keys} 个密钥,其中 ${result.valid_keys} 个有效,${result.invalid_keys} 个无效。`;
|
||||
} else if (task.task_type === "KEY_IMPORT") {
|
||||
const result = task.result as import("@/types/models").KeyImportResult;
|
||||
msg = `密钥导入完成,成功添加 ${result.added_count} 个密钥,忽略了 ${result.ignored_count} 个。`;
|
||||
}
|
||||
|
||||
message.info(msg, {
|
||||
closable: true,
|
||||
duration: 0,
|
||||
@@ -92,6 +99,20 @@ function getProgressText(): string {
|
||||
function handleClose() {
|
||||
visible.value = false;
|
||||
}
|
||||
|
||||
function getTaskTitle(): string {
|
||||
if (!taskInfo.value) {
|
||||
return "正在处理任务...";
|
||||
}
|
||||
switch (taskInfo.value.task_type) {
|
||||
case "KEY_VALIDATION":
|
||||
return `正在验证分组 [${taskInfo.value.group_name}] 的密钥`;
|
||||
case "KEY_IMPORT":
|
||||
return `正在向分组 [${taskInfo.value.group_name}] 导入密钥`;
|
||||
default:
|
||||
return "正在处理任务...";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -102,7 +123,7 @@ function handleClose() {
|
||||
<span class="progress-icon">⚡</span>
|
||||
<div class="progress-details">
|
||||
<n-text strong class="progress-title">
|
||||
正在处理分组 {{ taskInfo.group_name }} 的任务
|
||||
{{ getTaskTitle() }}
|
||||
</n-text>
|
||||
<n-text depth="3" class="progress-subtitle">
|
||||
{{ getProgressText() }} ({{ getProgressPercentage() }}%)
|
||||
|
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { keysApi } from "@/api/keys";
|
||||
import { appState } from "@/utils/app-state";
|
||||
import { Close } from "@vicons/ionicons5";
|
||||
import { NButton, NCard, NInput, NModal } from "naive-ui";
|
||||
import { ref, watch } from "vue";
|
||||
@@ -51,10 +52,11 @@ async function handleSubmit() {
|
||||
try {
|
||||
loading.value = true;
|
||||
|
||||
await keysApi.addMultipleKeys(props.groupId, keysText.value);
|
||||
|
||||
emit("success");
|
||||
await keysApi.addKeysAsync(props.groupId, keysText.value);
|
||||
resetForm();
|
||||
handleClose();
|
||||
window.$message.success("密钥导入任务已开始,请稍后在下方查看进度。");
|
||||
appState.taskPollingTrigger++;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
|
@@ -75,18 +75,29 @@ export interface RequestStats {
|
||||
failure_rate: number;
|
||||
}
|
||||
|
||||
export type TaskType = "KEY_VALIDATION" | "KEY_IMPORT";
|
||||
|
||||
export interface KeyValidationResult {
|
||||
invalid_keys: number;
|
||||
total_keys: number;
|
||||
valid_keys: number;
|
||||
}
|
||||
|
||||
export interface KeyImportResult {
|
||||
added_count: number;
|
||||
ignored_count: number;
|
||||
}
|
||||
|
||||
export interface TaskInfo {
|
||||
task_type: TaskType;
|
||||
is_running: boolean;
|
||||
group_name?: string;
|
||||
processed?: number;
|
||||
total?: number;
|
||||
started_at?: string;
|
||||
finished_at?: string;
|
||||
result?: {
|
||||
invalid_keys: number;
|
||||
total_keys: number;
|
||||
valid_keys: number;
|
||||
};
|
||||
result?: KeyValidationResult | KeyImportResult;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
// Based on backend response
|
||||
|
Reference in New Issue
Block a user