2026-02-20 14:42:41 +00:00
|
|
|
export interface EditorSettings {
|
|
|
|
|
editor_command: string | null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DEFAULT_API_BASE = "/api";
|
|
|
|
|
|
|
|
|
|
function buildApiUrl(path: string, baseUrl = DEFAULT_API_BASE): string {
|
|
|
|
|
return `${baseUrl}${path}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function requestJson<T>(
|
|
|
|
|
path: string,
|
|
|
|
|
options: RequestInit = {},
|
|
|
|
|
baseUrl = DEFAULT_API_BASE,
|
|
|
|
|
): Promise<T> {
|
|
|
|
|
const res = await fetch(buildApiUrl(path, baseUrl), {
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
...(options.headers ?? {}),
|
|
|
|
|
},
|
|
|
|
|
...options,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
const text = await res.text();
|
|
|
|
|
throw new Error(text || `Request failed (${res.status})`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res.json() as Promise<T>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const settingsApi = {
|
|
|
|
|
getEditorCommand(baseUrl?: string): Promise<EditorSettings> {
|
|
|
|
|
return requestJson<EditorSettings>("/settings/editor", {}, baseUrl);
|
|
|
|
|
},
|
|
|
|
|
|
2026-02-20 15:53:24 +00:00
|
|
|
setEditorCommand(
|
|
|
|
|
command: string | null,
|
|
|
|
|
baseUrl?: string,
|
|
|
|
|
): Promise<EditorSettings> {
|
2026-02-20 14:42:41 +00:00
|
|
|
return requestJson<EditorSettings>(
|
|
|
|
|
"/settings/editor",
|
|
|
|
|
{
|
|
|
|
|
method: "PUT",
|
|
|
|
|
body: JSON.stringify({ editor_command: command }),
|
|
|
|
|
},
|
|
|
|
|
baseUrl,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
};
|