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

View File

@@ -15,7 +15,7 @@ const Help: FC = () => {
const { LL } = useI18nContext(); const { LL } = useI18nContext();
useLayoutTitle(LL.HELP_OF('')); 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 immediate: false
}); });
@@ -26,14 +26,14 @@ const Help: FC = () => {
type: 'text/plain' 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(); anchor.click();
URL.revokeObjectURL(anchor.href); URL.revokeObjectURL(anchor.href);
toast.info(LL.DOWNLOAD_SUCCESSFUL()); toast.info(LL.DOWNLOAD_SUCCESSFUL());
}); });
const callAPI = async (device: string, entity: string) => { const callSystemAPI = async (entity: string) => {
await getAPI({ device, entity, id: 0 }).catch((error) => { await getSystemAPI({ entity, id: 0 }).catch((error) => {
toast.error(error.message); toast.error(error.message);
}); });
}; };
@@ -89,7 +89,7 @@ const Help: FC = () => {
{LL.HELP_INFORMATION_4()} {LL.HELP_INFORMATION_4()}
</Typography> </Typography>
</Box> </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)} {LL.SUPPORT_INFORMATION(0)}
</Button> </Button>
<Button <Button
@@ -97,7 +97,7 @@ const Help: FC = () => {
startIcon={<DownloadIcon />} startIcon={<DownloadIcon />}
variant="outlined" variant="outlined"
color="primary" color="primary"
onClick={() => callAPI('system', 'allvalues')} onClick={() => callSystemAPI('allvalues')}
> >
All Values All Values
</Button> </Button>

View File

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

View File

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

View File

@@ -5,7 +5,7 @@ import busboy from 'busboy';
const encoder = new Encoder(); const encoder = new Encoder();
const router = Router(); const router = Router();
// const upload = multer({ dest: '../mock-api/uploads' }); // TODO remove // const upload = multer({ dest: '../mock-api/uploads' }); // TODO remove multer
const REST_ENDPOINT_ROOT = '/rest/'; const REST_ENDPOINT_ROOT = '/rest/';
const API_ENDPOINT_ROOT = '/api/'; const API_ENDPOINT_ROOT = '/api/';
@@ -2351,11 +2351,11 @@ router
.get(VERIFY_AUTHORIZATION_ENDPOINT, () => new Response(JSON.stringify(verify_authentication), { headers })) .get(VERIFY_AUTHORIZATION_ENDPOINT, () => new Response(JSON.stringify(verify_authentication), { headers }))
.post(RESTART_ENDPOINT, () => new Response('OK', { status: 200 })) .post(RESTART_ENDPOINT, () => new Response('OK', { status: 200 }))
.post(FACTORY_RESET_ENDPOINT, () => new Response('OK', { status: 200 })) .post(FACTORY_RESET_ENDPOINT, () => new Response('OK', { status: 200 }))
.post(UPLOAD_FILE_ENDPOINT, () => new Response('OK', { status: 404 })) // TODO remove .post(UPLOAD_FILE_ENDPOINT, () => new Response('OK', { status: 404 })) // TODO remove upload filepoint
.post(SIGN_IN_ENDPOINT, () => new Response(JSON.stringify(signin), { headers })) .post(SIGN_IN_ENDPOINT, () => new Response(JSON.stringify(signin), { headers }))
.get(GENERATE_TOKEN_ENDPOINT, () => new Response(JSON.stringify(generate_token), { headers })); .get(GENERATE_TOKEN_ENDPOINT, () => new Response(JSON.stringify(generate_token), { headers }));
// uploads // TODO fix later // uploads // TODO fix uploads later
// const progress_middleware = async (req: any) => { // const progress_middleware = async (req: any) => {
// console.log('progress_middleware'); // console.log('progress_middleware');
@@ -2775,6 +2775,7 @@ router
}); });
// API and calls // API and calls
const SYSTEM_API_ENDPOINT = API_ENDPOINT_ROOT + 'system';
const SYSTEM_INFO_ENDPOINT = API_ENDPOINT_ROOT + 'system/info'; const SYSTEM_INFO_ENDPOINT = API_ENDPOINT_ROOT + 'system/info';
const GET_SETTINGS_ENDPOINT = REST_ENDPOINT_ROOT + 'getSettings'; const GET_SETTINGS_ENDPOINT = REST_ENDPOINT_ROOT + 'getSettings';
const GET_CUSTOMIZATIONS_ENDPOINT = REST_ENDPOINT_ROOT + 'getCustomizations'; const GET_CUSTOMIZATIONS_ENDPOINT = REST_ENDPOINT_ROOT + 'getCustomizations';
@@ -2792,32 +2793,18 @@ router
.get(GET_SCHEDULE_ENDPOINT, () => new Response(JSON.stringify(emsesp_schedule), { headers })) .get(GET_SCHEDULE_ENDPOINT, () => new Response(JSON.stringify(emsesp_schedule), { headers }))
.get(SCHEDULE_ENDPOINT, () => new Response(JSON.stringify(emsesp_schedule), { headers })) .get(SCHEDULE_ENDPOINT, () => new Response(JSON.stringify(emsesp_schedule), { headers }))
.get(ENTITIES_ENDPOINT, () => new Response(JSON.stringify(emsesp_customentities), { headers })) .get(ENTITIES_ENDPOINT, () => new Response(JSON.stringify(emsesp_customentities), { headers }))
.post(API_ENDPOINT_ROOT, async (request: any) => { .post(SYSTEM_API_ENDPOINT, async (request: any) => {
const data = await request.json(); const data = await request.json();
if (data.device === 'system') { if (data.entity === 'info') {
if (data.entity === 'info') { return new Response(JSON.stringify(emsesp_info), { headers });
return new Response(JSON.stringify(emsesp_info), { headers });
}
if (data.entity === 'allvalues') {
return new Response(JSON.stringify(emsesp_allvalues), { headers });
}
} }
if (data.entity === 'allvalues') {
return new Response(JSON.stringify(emsesp_allvalues), { headers });
}
return new Response('Not Found', { status: 404 }); return new Response('Not Found', { status: 404 });
}); });
// Event Source // TODO fix later
// const data = {
// t: '000+00:00:00.000',
// l: 3, // error
// i: 1,
// n: 'system',
// m: 'incoming message #1'
// };
// const sseFormattedResponse = `data: ${JSON.stringify(data)}\n\n`;
// router.get('/es/log', () => new Response(sseFormattedResponse, { headers: ESheaders }));
var count = 8;
var log_index = 0; var log_index = 0;
const ES_LOG_ENDPOINT = ES_ENDPOINT_ROOT + 'log'; const ES_LOG_ENDPOINT = ES_ENDPOINT_ROOT + 'log';

View File

@@ -58,11 +58,12 @@ GET {{host}}/api/temperaturesensor/info
# Test on dev # Test on dev
# #
GET {{host_dev}}/api/system/info GET {{host_dev}}/api/system/info
### ###
GET {{host_dev}}/api?device=system&cmd=test&data=general GET {{host_dev}}/api?device=system&cmd=test&data=general
### ###
GET {{host_dev}}/api?device=system&cmd=info
###
GET {{host_dev}}/api/boiler/info GET {{host_dev}}/api/boiler/info
### ###
GET {{host_dev}}/api/boiler/values GET {{host_dev}}/api/boiler/values
@@ -74,16 +75,14 @@ Authorization: Bearer {{token}}
### ###
GET {{host_dev}}/api/system/commands GET {{host_dev}}/api/system/commands
### ###
POST {{host_dev}}/api POST {{host_dev}}/api/system
Content-Type: application/json Content-Type: application/json
Authorization: Bearer {{token}} Authorization: Bearer {{token}}
{ {
"device" : "system",
"entity" : "info", "entity" : "info",
"id" : 0 "id" : 0
} }
### ###
GET {{host_dev}}/rest/features GET {{host_dev}}/rest/features
### ###