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