2025-04-30 00:17:09 +08:00
|
|
|
import http from '@core/http';
|
|
|
|
|
2025-05-11 18:46:59 +08:00
|
|
|
import type { RobotDetail, RobotGroup, RobotInfo } from './type';
|
2025-04-30 00:17:09 +08:00
|
|
|
|
|
|
|
const enum API {
|
|
|
|
获取所有机器人 = '/robot/getAll',
|
2025-05-05 01:06:09 +08:00
|
|
|
|
|
|
|
注册机器人 = '/robot/register',
|
|
|
|
|
|
|
|
批量抢占控制权 = '/robot/seizeByIds',
|
2025-05-11 18:46:59 +08:00
|
|
|
同步组文件 = 'robot/syncByGroupId',
|
2025-04-30 00:17:09 +08:00
|
|
|
}
|
|
|
|
|
2025-05-05 01:06:09 +08:00
|
|
|
export async function getAllRobots(): Promise<Array<RobotInfo>> {
|
2025-04-30 00:17:09 +08:00
|
|
|
type D = RobotInfo[];
|
2025-05-05 23:21:31 +08:00
|
|
|
try {
|
|
|
|
const data = await http.post<D>(API.获取所有机器人);
|
|
|
|
return data ?? [];
|
|
|
|
} catch (error) {
|
|
|
|
console.debug(error);
|
|
|
|
return [];
|
|
|
|
}
|
2025-04-30 00:17:09 +08:00
|
|
|
}
|
2025-05-05 01:06:09 +08:00
|
|
|
|
|
|
|
export async function registerRobot(robot: Omit<RobotDetail, 'id'>): Promise<RobotInfo | null> {
|
|
|
|
type B = Omit<RobotDetail, 'id'>;
|
|
|
|
type D = RobotInfo;
|
2025-05-05 23:21:31 +08:00
|
|
|
try {
|
|
|
|
const body = robot;
|
|
|
|
const data = await http.post<D, B>(API.注册机器人, body);
|
|
|
|
return data ?? null;
|
|
|
|
} catch (error) {
|
|
|
|
console.debug(error);
|
|
|
|
return null;
|
|
|
|
}
|
2025-05-05 01:06:09 +08:00
|
|
|
}
|
|
|
|
|
2025-05-05 23:21:31 +08:00
|
|
|
export async function seizeRobotByIds(ids: Array<RobotInfo['id']>): Promise<Array<RobotInfo['id']>> {
|
|
|
|
if (!ids.length) return [];
|
2025-05-05 01:06:09 +08:00
|
|
|
type B = { ids: string[] };
|
2025-05-05 23:21:31 +08:00
|
|
|
type D = string[];
|
2025-05-05 01:06:09 +08:00
|
|
|
try {
|
|
|
|
const body = { ids };
|
2025-05-05 23:21:31 +08:00
|
|
|
const data = await http.post<D, B>(API.批量抢占控制权, body);
|
|
|
|
return data ?? [];
|
2025-05-05 01:06:09 +08:00
|
|
|
} catch (error) {
|
|
|
|
console.debug(error);
|
2025-05-05 23:21:31 +08:00
|
|
|
return [];
|
2025-05-05 01:06:09 +08:00
|
|
|
}
|
|
|
|
}
|
2025-05-11 18:46:59 +08:00
|
|
|
export async function syncGroupRobotsById(id: RobotGroup['id'], sid: RobotGroup['sid']): Promise<boolean> {
|
|
|
|
if (!id || !sid) return false;
|
|
|
|
type B = { id: string; sid: string };
|
|
|
|
type D = void;
|
|
|
|
try {
|
|
|
|
const body = { id, sid };
|
|
|
|
await http.post<D, B>(API.同步组文件, body);
|
|
|
|
return true;
|
|
|
|
} catch (error) {
|
|
|
|
console.debug(error);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|