37 lines
883 B
TypeScript
Raw Normal View History

2025-04-30 00:17:09 +08:00
import http from '@core/http';
import type { SceneDetail, SceneInfo } from './type';
2025-04-29 20:08:08 +08:00
const enum API {
= '/scene/getById',
2025-05-10 00:49:45 +08:00
= '/scene/saveById',
2025-04-29 20:08:08 +08:00
}
2025-04-30 00:17:09 +08:00
export async function getSceneById(id: SceneInfo['id']): Promise<SceneDetail | null> {
if (!id) return null;
type B = { id: string };
type D = SceneDetail;
2025-05-05 01:06:09 +08:00
try {
const body = { id };
const data = await http.post<D, B>(API., body);
return data ?? null;
} catch (error) {
console.debug(error);
return null;
}
2025-04-30 00:17:09 +08:00
}
2025-05-10 00:49:45 +08:00
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;
}
}