downloader.ts 655 B

12345678910111213141516171819202122232425262728293031
  1. import type { AxiosRequestConfig } from 'axios';
  2. import type { RequestClient } from '../request-client';
  3. import type { RequestResponse } from '../types';
  4. class FileDownloader {
  5. private client: RequestClient;
  6. constructor(client: RequestClient) {
  7. this.client = client;
  8. }
  9. public async download(
  10. url: string,
  11. config?: AxiosRequestConfig,
  12. ): Promise<RequestResponse<Blob>> {
  13. const finalConfig: AxiosRequestConfig = {
  14. ...config,
  15. responseType: 'blob',
  16. };
  17. const response = await this.client.get<RequestResponse<Blob>>(
  18. url,
  19. finalConfig,
  20. );
  21. return response;
  22. }
  23. }
  24. export { FileDownloader };