import {getAxiosInstance} from "@/utils/axios";

export const http = getAxiosInstance({
    timeout: 60 * 1000
})

export default http;

export interface ReadFileParams {
    chunkSize?: number
    offset?: number
    path: string
}

export interface SaveFileParams {
    fileName: string
    data: Blob
}

export class Api {
    server:string
    constructor(server:string) {
        this.server = server
    }

    readFile(params: ReadFileParams){
        return http.get(`${this.server}/s/file/get`,{
            params: params
        })
    }

    saveFile(params: SaveFileParams){
        return http.postForm(`${this.server}/s/file/save`,{
            fileName:  params.fileName,
            fileContent:  params.data
        })
    }
}

let api = new Api("")

export function initApi(server:string){
    api = new Api(server)
}

export function useApi(){
    return api
}
