// src/lib/services/nodeConfigService.ts import api from '@/lib/api'; import { NodeConfigEntryType, NodeConfigurationItem, NodeConfigListParams, SparseUpdatePayload, RevisionItem, } from '@/types'; export const nodeConfigService = { /** * 分页查询配置列表 */ async getList( entryType: NodeConfigEntryType, params?: NodeConfigListParams ): Promise<{ code: number; message: string; data: { total: number; page: number; page_size: number; items: NodeConfigurationItem[]; }; }> { const res = await api.get(`/api/node-configurations/${entryType}`, { params }); return res.data; }, /** * 获取配置详情 */ async getDetail( entryType: NodeConfigEntryType, entryId: number ): Promise<{ code: number; message: string; data: NodeConfigurationItem; }> { const res = await api.get(`/api/node-configurations/${entryType}/${entryId}`); return res.data; }, /** * 新建配置条目 */ async create( entryType: NodeConfigEntryType, payload: Partial ): Promise<{ code: number; message: string; data: NodeConfigurationItem; }> { const res = await api.post(`/api/node-configurations/${entryType}`, payload); return res.data; }, /** * 稀疏更新配置 (Sparse Update) */ async sparseUpdate( entryType: NodeConfigEntryType, entryId: number, payload: SparseUpdatePayload ): Promise<{ code: number; message: string; data: NodeConfigurationItem; }> { const res = await api.put(`/api/node-configurations/${entryType}/${entryId}`, payload); return res.data; }, /** * 启用 / 停用配置 */ async toggleEnable( entryType: NodeConfigEntryType, entryId: number, enable: boolean ): Promise<{ code: number; message: string; data: NodeConfigurationItem; }> { const res = await api.put(`/api/node-configurations/${entryType}/${entryId}/enable`, { enable, }); return res.data; }, /** * 删除配置条目 (支持 confirm_purge 保护守卫) */ async delete( entryType: NodeConfigEntryType, entryId: number, confirmPurge: boolean = false ): Promise<{ code: number; message: string; data: boolean; }> { const res = await api.delete(`/api/node-configurations/${entryType}/${entryId}`, { params: confirmPurge ? { confirm_purge: true } : undefined, }); return res.data; }, /** * 查询配置修订历史记录 (Revisions) */ async getRevisions( entryType: NodeConfigEntryType, entryId: number ): Promise<{ code: number; message: string; data: RevisionItem[]; }> { const res = await api.get(`/api/node-configurations/${entryType}/${entryId}/revisions`); return res.data; }, /** * 回滚配置至指定历史版本 */ async rollback( entryType: NodeConfigEntryType, entryId: number, revisionId: number ): Promise<{ code: number; message: string; data: NodeConfigurationItem; }> { const res = await api.post(`/api/node-configurations/${entryType}/${entryId}/rollback`, { revision_id: revisionId, }); return res.data; }, /** * 获取 Worker 节点集群实时状态与心跳 */ async getRuntimeStatus(params?: { role?: string; node_id?: string; }): Promise<{ code: number; message: string; data: { nodes: import('@/types').NodeRuntimeStatus[]; timestamp: string; }; }> { const res = await api.get('/api/node-configurations/runtime-status', { params }); return res.data; }, };