wails-app-dock/frontend/src/api/index.ts

49 lines
881 B
TypeScript
Raw Normal View History

2024-02-19 04:12:11 +08:00
import {getAxiosInstance} from "@/utils/axios";
export const http = getAxiosInstance({
timeout: 60 * 1000
})
export default http;
export interface ReadFileParams {
chunkSize?: number
offset?: number
2024-02-19 04:12:11 +08:00
path: string
}
export interface SaveFileParams {
fileName: string
data: Blob
}
2024-02-19 04:12:11 +08:00
export class Api {
server:string
constructor(server:string) {
this.server = server
}
readFile(params: ReadFileParams){
return http.get(`${this.server}/s/file/get`,{
2024-02-19 04:12:11 +08:00
params: params
})
}
saveFile(params: SaveFileParams){
return http.postForm(`${this.server}/s/file/save`,{
fileName: params.fileName,
fileContent: params.data
})
}
2024-02-19 04:12:11 +08:00
}
let api = new Api("")
export function initApi(server:string){
api = new Api(server)
}
export function useApi(){
return api
}