import baseAxios from '../index'
export default class FileService {
  static instance: FileService
  static getInstance() {
    if (!FileService.instance) {
      FileService.instance = new FileService()
    }
    return FileService.instance
  }

  download(file_hash: string) {
    return (baseAxios({
      method: 'get',
      url: '/image/download',
      params: {
        file_hash,
      },
    }) as unknown) as Promise<File>
  }

  getImageSrc(file_hash: string) {
    return `/proxyApi/api/v1/image/show?file_hash=${file_hash}`
  }

  showImage(file_hash: string) {
    return (baseAxios({
      method: 'get',
      url: '/image/show',
      params: {
        file_hash,
      },
    }) as unknown) as Promise<File>
  }

  uploadImage(uploadFile: File) {
    const fd = new FormData()
    fd.append('uploadFile', uploadFile)
    return baseAxios<string>({
      method: 'post',
      url: '/image/upload',
      data: fd,
    })
  }
}
