https://dev.kronoz.win/r/marzneshin.git
1import { fetch } from 'service/http';
2import { create } from 'zustand';
3
4type CoreSettingsStore = {
5 isLoading: boolean;
6 isPostLoading: boolean;
7 fetchCoreSettings: () => void;
8 updateConfig: (json: string) => Promise<void>;
9 restartCore: () => Promise<void>;
10 version: string | null;
11 started: boolean | null;
12 logs_websocket: string | null;
13 config: string;
14};
15
16export const useCoreSettings = create<CoreSettingsStore>((set) => ({
17 isLoading: true,
18 isPostLoading: false,
19 version: null,
20 started: false,
21 logs_websocket: null,
22 config: '',
23 fetchCoreSettings: () => {
24 set({ isLoading: true });
25 Promise.all([
26 fetch('/core').then(({ version, started, logs_websocket }) =>
27 set({ version, started, logs_websocket })
28 ),
29 fetch('/core/config').then((config) => set({ config })),
30 ]).finally(() => set({ isLoading: false }));
31 },
32 updateConfig: (body) => {
33 set({ isPostLoading: true });
34 return fetch('/core/config', { method: 'PUT', body }).finally(() => {
35 set({ isPostLoading: false });
36 });
37 },
38 restartCore: () => {
39 return fetch('/core/restart', { method: 'POST' });
40 },
41}));