Browse Source

feat(@vben/request): export basic HttpResponse generic (#4697)

pull/4704/head
Svend 1 year ago
committed by GitHub
parent
commit
88d2b3e569
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 7
      packages/effects/request/src/request-client/modules/downloader.ts
  2. 3
      packages/effects/request/src/request-client/types.ts

7
packages/effects/request/src/request-client/modules/downloader.ts

@ -1,6 +1,7 @@
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
import type { AxiosRequestConfig } from 'axios';
import type { RequestClient } from '../request-client';
import type { RequestResponse } from '../types';
class FileDownloader {
private client: RequestClient;
@ -12,13 +13,13 @@ class FileDownloader {
public async download(
url: string,
config?: AxiosRequestConfig,
): Promise<AxiosResponse<Blob>> {
): Promise<RequestResponse<Blob>> {
const finalConfig: AxiosRequestConfig = {
...config,
responseType: 'blob',
};
const response = await this.client.get<AxiosResponse<Blob>>(
const response = await this.client.get<RequestResponse<Blob>>(
url,
finalConfig,
);

3
packages/effects/request/src/request-client/types.ts

@ -4,6 +4,8 @@ import type {
InternalAxiosRequestConfig,
} from 'axios';
type RequestResponse<T = any> = AxiosResponse<T>;
type RequestContentType =
| 'application/json;charset=utf-8'
| 'application/octet-stream;charset=utf-8'
@ -46,5 +48,6 @@ export type {
RequestClientOptions,
RequestContentType,
RequestInterceptorConfig,
RequestResponse,
ResponseInterceptorConfig,
};

Loading…
Cancel
Save