change api to api/system

This commit is contained in:
Proddy
2023-12-29 12:04:40 +01:00
parent 4b831e864c
commit 9ca0782ae7
6 changed files with 32 additions and 51 deletions

View File

@@ -28,7 +28,7 @@ const UploadFileForm: FC = () => {
const { send: getSchedule, onSuccess: onSuccessGetSchedule } = useRequest(EMSESP.getSchedule(), {
immediate: false
});
const { send: getAPI, onSuccess: onGetAPI } = useRequest((data) => EMSESP.API(data), {
const { send: getSystemAPI, onSuccess: onSystemAPI } = useRequest((data) => EMSESP.APIcall('system', data), {
immediate: false
});
@@ -89,8 +89,8 @@ const UploadFileForm: FC = () => {
onSuccessGetSchedule((event) => {
saveFile(event.data, 'schedule.json');
});
onGetAPI((event) => {
saveFile(event.data, event.sendArgs[0].device + '_' + event.sendArgs[0].entity + '.txt');
onSystemAPI((event) => {
saveFile(event.data, event.sendArgs[0].entity + '.txt');
});
const downloadSettings = async () => {
@@ -121,8 +121,8 @@ const UploadFileForm: FC = () => {
});
};
const callAPI = async (device: string, entity: string) => {
await getAPI({ device, entity, id: 0 }).catch((error) => {
const callSystemAPI = async (entity: string) => {
await getSystemAPI({ entity, id: 0 }).catch((error) => {
toast.error(error.message);
});
};
@@ -134,7 +134,8 @@ const UploadFileForm: FC = () => {
</Typography>
<Box mb={2} color="warning.main">
<Typography variant="body2">
{LL.UPLOAD_TEXT()}
{LL.UPLOAD_TEXT()}.
<br />
<br />
{LL.RESTART_TEXT(1)}.
</Typography>
@@ -155,12 +156,7 @@ const UploadFileForm: FC = () => {
{LL.HELP_INFORMATION_4()}
</Typography>
</Box>
<Button
startIcon={<DownloadIcon />}
variant="outlined"
color="primary"
onClick={() => callAPI('system', 'info')}
>
<Button startIcon={<DownloadIcon />} variant="outlined" color="primary" onClick={() => callSystemAPI('info')}>
{LL.SUPPORT_INFORMATION(0)}
</Button>
<Button
@@ -168,7 +164,7 @@ const UploadFileForm: FC = () => {
startIcon={<DownloadIcon />}
variant="outlined"
color="primary"
onClick={() => callAPI('system', 'allvalues')}
onClick={() => callSystemAPI('allvalues')}
>
All Values
</Button>

View File

@@ -15,7 +15,7 @@ const Help: FC = () => {
const { LL } = useI18nContext();
useLayoutTitle(LL.HELP_OF(''));
const { send: getAPI, onSuccess: onGetAPI } = useRequest((data) => EMSESP.API(data), {
const { send: getSystemAPI, onSuccess: onGetAPI } = useRequest((data) => EMSESP.APIcall('system', data), {
immediate: false
});
@@ -26,14 +26,14 @@ const Help: FC = () => {
type: 'text/plain'
})
);
anchor.download = 'emsesp_' + event.sendArgs[0].device + '_' + event.sendArgs[0].entity + '.txt';
anchor.download = 'emsesp_' + event.sendArgs[0].entity + '.txt';
anchor.click();
URL.revokeObjectURL(anchor.href);
toast.info(LL.DOWNLOAD_SUCCESSFUL());
});
const callAPI = async (device: string, entity: string) => {
await getAPI({ device, entity, id: 0 }).catch((error) => {
const callSystemAPI = async (entity: string) => {
await getSystemAPI({ entity, id: 0 }).catch((error) => {
toast.error(error.message);
});
};
@@ -89,7 +89,7 @@ const Help: FC = () => {
{LL.HELP_INFORMATION_4()}
</Typography>
</Box>
<Button startIcon={<DownloadIcon />} variant="outlined" color="primary" onClick={() => callAPI('system', 'info')}>
<Button startIcon={<DownloadIcon />} variant="outlined" color="primary" onClick={() => callSystemAPI('info')}>
{LL.SUPPORT_INFORMATION(0)}
</Button>
<Button
@@ -97,7 +97,7 @@ const Help: FC = () => {
startIcon={<DownloadIcon />}
variant="outlined"
color="primary"
onClick={() => callAPI('system', 'allvalues')}
onClick={() => callSystemAPI('allvalues')}
>
All Values
</Button>

View File

@@ -1,5 +1,5 @@
import type {
APIcall,
APIdata,
Settings,
Status,
CoreData,
@@ -44,7 +44,7 @@ export const readStatus = () => alovaInstance.Get<Status>('/rest/status');
export const scanDevices = () => alovaInstance.Post('/rest/scanDevices');
// HelpInformation
export const API = (apiCall: APIcall) => alovaInstance.Post('/api', apiCall);
export const APIcall = (device: string, apiData: APIdata) => alovaInstance.Post(`/api/${device}`, apiData);
// UploadFileForm
export const getSettings = () => alovaInstance.Get('/rest/getSettings');

View File

@@ -266,8 +266,7 @@ export interface BoardProfile {
eth_clock_mode: number;
}
export interface APIcall {
device: string;
export interface APIdata {
entity: string;
id: any;
}