alova - add interceptor

This commit is contained in:
Proddy
2023-06-18 16:35:32 +02:00
parent b1d666d7b9
commit ce1b9f22cb
24 changed files with 200 additions and 331 deletions

View File

@@ -1,8 +1,8 @@
import { alovaInstance, startUploadFile } from './endpoints';
import { alovaInstance, alovaInstanceGH, startUploadFile } from './endpoints';
import type { FileUploadConfig } from './endpoints';
import type { AxiosPromise } from 'axios';
import type { OTASettings, SystemStatus, LogSettings } from 'types';
import type { OTASettings, SystemStatus, LogSettings, Version } from 'types';
// SystemStatus - also used to ping in Restart monitor
export const readSystemStatus = () => alovaInstance.Get<SystemStatus>('/rest/systemStatus');
@@ -21,6 +21,28 @@ export const readLogSettings = () => alovaInstance.Get<LogSettings>(`/rest/logSe
export const updateLogSettings = (data: any) => alovaInstance.Post('/rest/logSettings', data);
export const fetchLog = () => alovaInstance.Post('/rest/fetchLog');
// TODO fileupload move to Alova
// Get versions from github
export const getStableVersion = () =>
alovaInstanceGH.Get<Version>('releases/latest', {
transformData(reponse: any) {
return {
version: reponse.data.name,
url: reponse.data.assets[1].browser_download_url,
changelog: reponse.data.assets[0].browser_download_url
};
}
});
export const getDevVersion = () =>
alovaInstanceGH.Get<Version>('releases/tags/latest', {
transformData(reponse: any) {
return {
version: reponse.data.name.split(/\s+/).splice(-1),
url: reponse.data.assets[1].browser_download_url,
changelog: reponse.data.assets[0].browser_download_url
};
}
});
// TODO fileupload move to alova
export const uploadFile = (file: File, config?: FileUploadConfig): AxiosPromise<void> =>
startUploadFile('/uploadFile', file, config);