新增上传队列显示
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
// app/api/queue.ts
|
||||
// 队列状态 API 客户端
|
||||
|
||||
import axios from 'axios';
|
||||
import { API_BASE_URL } from '../config/api-config';
|
||||
|
||||
/**
|
||||
* 队列状态响应接口
|
||||
*/
|
||||
export interface QueueStatus {
|
||||
success: boolean;
|
||||
timestamp: string;
|
||||
queue: {
|
||||
pending_tasks: number;
|
||||
processing_tasks: number;
|
||||
available_slots: number;
|
||||
max_concurrent: number;
|
||||
};
|
||||
documents: {
|
||||
waiting: number; // 排队中的文档数
|
||||
processing: number; // 处理中的文档数
|
||||
processing_ids: string[];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取队列整体状态
|
||||
* @returns 队列状态信息
|
||||
*/
|
||||
export async function getQueueStatus(): Promise<{ data?: QueueStatus; error?: string }> {
|
||||
try {
|
||||
// 从 localStorage 获取 token
|
||||
let token: string | null = null;
|
||||
if (typeof window !== 'undefined') {
|
||||
token = localStorage.getItem('access_token');
|
||||
}
|
||||
|
||||
const headers: Record<string, string> = {
|
||||
'Accept': 'application/json'
|
||||
};
|
||||
|
||||
if (token) {
|
||||
headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
const response = await axios.get<QueueStatus>(
|
||||
`${API_BASE_URL}/api/v2/system/queue/status`,
|
||||
{ headers }
|
||||
);
|
||||
|
||||
return { data: response.data };
|
||||
} catch (error) {
|
||||
console.error('【队列状态】获取队列状态失败:', error);
|
||||
if (axios.isAxiosError(error)) {
|
||||
return { error: error.response?.data?.detail || error.message };
|
||||
}
|
||||
return { error: error instanceof Error ? error.message : '获取队列状态失败' };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user