2025-05-10 15:41:21 +08:00

54 lines
1.3 KiB
TypeScript

import type { RobotGroup } from '@api/robot';
import http from '@core/http';
import type { SceneDetail, SceneInfo } from './type';
const enum API {
= '/scene/getById',
= '/scene/saveById',
= '/scene/getByGroupId',
}
export async function getSceneById(id: SceneInfo['id']): Promise<SceneDetail | null> {
if (!id) return null;
type B = { id: string };
type D = SceneDetail;
try {
const body = { id };
const data = await http.post<D, B>(API., body);
return data ?? null;
} catch (error) {
console.debug(error);
return null;
}
}
export async function saveSceneById(id: SceneInfo['id'], json: string): Promise<boolean> {
if (!id) return false;
type B = { id: string; json: string };
type D = void;
try {
const body = { id, json };
await http.post<D, B>(API., body);
return true;
} catch (error) {
console.debug(error);
return false;
}
}
export async function getSceneByGroupId(id: RobotGroup['id'], sid: RobotGroup['sid']): Promise<SceneDetail | null> {
if (!id) return null;
type B = { id: string; sid?: string };
type D = SceneDetail;
try {
const body = { id, sid };
const data = await http.post<D, B>(API., body);
return data ?? null;
} catch (error) {
console.debug(error);
return null;
}
}