mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
Alova 3 now working
This commit is contained in:
@@ -65,8 +65,7 @@ export const readDeviceEntities = (id: number) =>
|
||||
alovaInstance.Get<DeviceEntity[]>(`/rest/deviceEntities`, {
|
||||
params: { id },
|
||||
responseType: 'arraybuffer',
|
||||
// transform(data) { // TODO alova 3
|
||||
transformData(data) {
|
||||
transform(data) {
|
||||
return (data as DeviceEntity[]).map((de: DeviceEntity) => ({
|
||||
...de,
|
||||
o_m: de.m,
|
||||
@@ -89,8 +88,7 @@ export const writeDeviceName = (data: { id: number; name: string }) =>
|
||||
// SettingsScheduler
|
||||
export const readSchedule = () =>
|
||||
alovaInstance.Get<ScheduleItem[]>('/rest/schedule', {
|
||||
// transform(data) { // TODO alova 3
|
||||
transformData(data) {
|
||||
transform(data) {
|
||||
return (data as Schedule).schedule.map((si: ScheduleItem) => ({
|
||||
...si,
|
||||
o_id: si.id,
|
||||
@@ -110,8 +108,7 @@ export const writeSchedule = (data: Schedule) =>
|
||||
// Modules
|
||||
export const readModules = () =>
|
||||
alovaInstance.Get<ModuleItem[]>('/rest/modules', {
|
||||
// transform(data) { // TODO alova 3
|
||||
transformData(data) {
|
||||
transform(data) {
|
||||
return (data as Modules).modules.map((mi: ModuleItem) => ({
|
||||
...mi,
|
||||
o_enabled: mi.enabled,
|
||||
@@ -128,8 +125,7 @@ export const writeModules = (data: {
|
||||
// SettingsEntities
|
||||
export const readCustomEntities = () =>
|
||||
alovaInstance.Get<EntityItem[]>('/rest/customEntities', {
|
||||
// transform(data) { // TODO alova 3
|
||||
transformData(data) {
|
||||
transform(data) {
|
||||
return (data as Entities).entities.map((ei: EntityItem) => ({
|
||||
...ei,
|
||||
o_id: ei.id,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { xhrRequestAdapter } from '@alova/adapter-xhr';
|
||||
import { type AlovaXHRResponse, xhrRequestAdapter } from '@alova/adapter-xhr';
|
||||
import { createAlova } from 'alova';
|
||||
import ReactHook from 'alova/react';
|
||||
|
||||
@@ -8,10 +8,13 @@ export const ACCESS_TOKEN = 'access_token';
|
||||
|
||||
export const alovaInstance = createAlova({
|
||||
statesHook: ReactHook,
|
||||
timeout: 3000, // 3 seconds but throwing a timeout error
|
||||
localCache: null,
|
||||
// TODO Alova v3 code...
|
||||
// cacheFor: null,
|
||||
timeout: 3000, // 3 seconds before throwing a timeout error
|
||||
cacheFor: {
|
||||
GET: {
|
||||
mode: 'memory',
|
||||
expire: 60 * 10 * 1000 // 60 seconds in cache
|
||||
}
|
||||
},
|
||||
requestAdapter: xhrRequestAdapter(),
|
||||
beforeRequest(method) {
|
||||
if (localStorage.getItem(ACCESS_TOKEN)) {
|
||||
@@ -21,7 +24,7 @@ export const alovaInstance = createAlova({
|
||||
},
|
||||
|
||||
responded: {
|
||||
onSuccess: async (response) => {
|
||||
onSuccess: async (response: AlovaXHRResponse) => {
|
||||
// if (response.status === 202) {
|
||||
// throw new Error('Wait'); // wifi scan in progress
|
||||
// } else
|
||||
|
||||
@@ -24,29 +24,15 @@ export const fetchLog = () => alovaInstance.Post('/rest/fetchLog');
|
||||
export const fetchLogES = () => alovaInstance.Get('/es/log');
|
||||
|
||||
// Get versions from github
|
||||
|
||||
// Alova 3 code...
|
||||
// export const getStableVersion = () =>
|
||||
// alovaInstanceGH.Get('latest', {
|
||||
// transform(response: { data: { name: string } }) {
|
||||
// return response.data.name.substring(1);
|
||||
// }
|
||||
// });
|
||||
// export const getDevVersion = () =>
|
||||
// alovaInstanceGH.Get('tags/latest', {
|
||||
// transform(response: { data: { name: string } }) {
|
||||
// return response.data.name.split(/\s+/).splice(-1)[0].substring(1);
|
||||
// }
|
||||
// });
|
||||
export const getStableVersion = () =>
|
||||
alovaInstanceGH.Get('latest', {
|
||||
transformData(response: { data: { name: string } }) {
|
||||
transform(response: { data: { name: string } }) {
|
||||
return response.data.name.substring(1);
|
||||
}
|
||||
});
|
||||
export const getDevVersion = () =>
|
||||
alovaInstanceGH.Get('tags/latest', {
|
||||
transformData(response: { data: { name: string } }) {
|
||||
transform(response: { data: { name: string } }) {
|
||||
return response.data.name.split(/\s+/).splice(-1)[0].substring(1);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user