mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
default Alova v2
This commit is contained in:
@@ -65,7 +65,8 @@ export const readDeviceEntities = (id: number) =>
|
||||
alovaInstance.Get<DeviceEntity[]>(`/rest/deviceEntities`, {
|
||||
params: { id },
|
||||
responseType: 'arraybuffer',
|
||||
transform(data) {
|
||||
// transform(data) { // TODO alova 3
|
||||
transformData(data) {
|
||||
return (data as DeviceEntity[]).map((de: DeviceEntity) => ({
|
||||
...de,
|
||||
o_m: de.m,
|
||||
@@ -88,7 +89,8 @@ export const writeDeviceName = (data: { id: number; name: string }) =>
|
||||
// SettingsScheduler
|
||||
export const readSchedule = () =>
|
||||
alovaInstance.Get<ScheduleItem[]>('/rest/schedule', {
|
||||
transform(data) {
|
||||
// transform(data) { // TODO alova 3
|
||||
transformData(data) {
|
||||
return (data as Schedule).schedule.map((si: ScheduleItem) => ({
|
||||
...si,
|
||||
o_id: si.id,
|
||||
@@ -108,7 +110,8 @@ export const writeSchedule = (data: Schedule) =>
|
||||
// Modules
|
||||
export const readModules = () =>
|
||||
alovaInstance.Get<ModuleItem[]>('/rest/modules', {
|
||||
transform(data) {
|
||||
// transform(data) { // TODO alova 3
|
||||
transformData(data) {
|
||||
return (data as Modules).modules.map((mi: ModuleItem) => ({
|
||||
...mi,
|
||||
o_enabled: mi.enabled,
|
||||
@@ -125,7 +128,8 @@ export const writeModules = (data: {
|
||||
// SettingsEntities
|
||||
export const readCustomEntities = () =>
|
||||
alovaInstance.Get<EntityItem[]>('/rest/customEntities', {
|
||||
transform(data) {
|
||||
// transform(data) { // TODO alova 3
|
||||
transformData(data) {
|
||||
return (data as Entities).entities.map((ei: EntityItem) => ({
|
||||
...ei,
|
||||
o_id: ei.id,
|
||||
|
||||
@@ -8,25 +8,10 @@ export const ACCESS_TOKEN = 'access_token';
|
||||
|
||||
export const alovaInstance = createAlova({
|
||||
statesHook: ReactHook,
|
||||
cacheFor: null,
|
||||
// TODO fix cache
|
||||
// cacheFor: {
|
||||
// // Set the cache mode for POST uniformly
|
||||
// POST: {
|
||||
// mode: 'restore',
|
||||
// expire: 60 * 10 * 1000
|
||||
// },
|
||||
// // Set the cache mode for HEAD requests uniformly
|
||||
// HEAD: 60 * 10 * 1000
|
||||
// },
|
||||
// timeout: 3000, // 3 seconds but throwing a timeout error
|
||||
// localCache: null,
|
||||
// localCache: {
|
||||
// GET: {
|
||||
// mode: 'placeholder', // see https://alova.js.org/learning/response-cache/#cache-replaceholder-mode
|
||||
// expire: 2000
|
||||
// }
|
||||
// },
|
||||
timeout: 3000, // 3 seconds but throwing a timeout error
|
||||
localCache: null,
|
||||
// TODO Alova v3 code...
|
||||
// cacheFor: null,
|
||||
requestAdapter: xhrRequestAdapter(),
|
||||
beforeRequest(method) {
|
||||
if (localStorage.getItem(ACCESS_TOKEN)) {
|
||||
|
||||
@@ -24,15 +24,29 @@ 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', {
|
||||
transform(response: { data: { name: string } }) {
|
||||
transformData(response: { data: { name: string } }) {
|
||||
return response.data.name.substring(1);
|
||||
}
|
||||
});
|
||||
export const getDevVersion = () =>
|
||||
alovaInstanceGH.Get('tags/latest', {
|
||||
transform(response: { data: { name: string } }) {
|
||||
transformData(response: { data: { name: string } }) {
|
||||
return response.data.name.split(/\s+/).splice(-1)[0].substring(1);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user