mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
change api to api/system
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -266,8 +266,7 @@ export interface BoardProfile {
|
||||
eth_clock_mode: number;
|
||||
}
|
||||
|
||||
export interface APIcall {
|
||||
device: string;
|
||||
export interface APIdata {
|
||||
entity: string;
|
||||
id: any;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import busboy from 'busboy';
|
||||
|
||||
const encoder = new Encoder();
|
||||
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 API_ENDPOINT_ROOT = '/api/';
|
||||
@@ -2351,11 +2351,11 @@ router
|
||||
.get(VERIFY_AUTHORIZATION_ENDPOINT, () => new Response(JSON.stringify(verify_authentication), { headers }))
|
||||
.post(RESTART_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 }))
|
||||
.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) => {
|
||||
// console.log('progress_middleware');
|
||||
@@ -2775,6 +2775,7 @@ router
|
||||
});
|
||||
|
||||
// API and calls
|
||||
const SYSTEM_API_ENDPOINT = API_ENDPOINT_ROOT + 'system';
|
||||
const SYSTEM_INFO_ENDPOINT = API_ENDPOINT_ROOT + 'system/info';
|
||||
const GET_SETTINGS_ENDPOINT = REST_ENDPOINT_ROOT + 'getSettings';
|
||||
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(SCHEDULE_ENDPOINT, () => new Response(JSON.stringify(emsesp_schedule), { 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();
|
||||
if (data.device === 'system') {
|
||||
if (data.entity === 'info') {
|
||||
return new Response(JSON.stringify(emsesp_info), { headers });
|
||||
}
|
||||
if (data.entity === 'allvalues') {
|
||||
return new Response(JSON.stringify(emsesp_allvalues), { headers });
|
||||
}
|
||||
if (data.entity === 'info') {
|
||||
return new Response(JSON.stringify(emsesp_info), { headers });
|
||||
}
|
||||
if (data.entity === 'allvalues') {
|
||||
return new Response(JSON.stringify(emsesp_allvalues), { headers });
|
||||
}
|
||||
|
||||
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;
|
||||
const ES_LOG_ENDPOINT = ES_ENDPOINT_ROOT + 'log';
|
||||
|
||||
|
||||
@@ -58,11 +58,12 @@ GET {{host}}/api/temperaturesensor/info
|
||||
# Test on dev
|
||||
#
|
||||
|
||||
|
||||
GET {{host_dev}}/api/system/info
|
||||
###
|
||||
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/values
|
||||
@@ -74,16 +75,14 @@ Authorization: Bearer {{token}}
|
||||
###
|
||||
GET {{host_dev}}/api/system/commands
|
||||
###
|
||||
POST {{host_dev}}/api
|
||||
POST {{host_dev}}/api/system
|
||||
Content-Type: application/json
|
||||
Authorization: Bearer {{token}}
|
||||
|
||||
{
|
||||
"device" : "system",
|
||||
"entity" : "info",
|
||||
"id" : 0
|
||||
}
|
||||
|
||||
###
|
||||
GET {{host_dev}}/rest/features
|
||||
###
|
||||
|
||||
Reference in New Issue
Block a user