[inula-request]<feat> 新增对外类型 IrInstance 和 IrProgressEvent
This commit is contained in:
parent
31b5b473c6
commit
3b401b84f1
|
@ -68,7 +68,7 @@ export {
|
||||||
isAxiosError,
|
isAxiosError,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type { IrRequestConfig, IrResponse, IrInstance, CancelTokenSource } from './src/types/interfaces';
|
export type { IrRequestConfig, IrResponse, IrInstance, CancelTokenSource, IrProgressEvent } from './src/types/interfaces';
|
||||||
export type { Method, ResponseType } from './src/types/types';
|
export type { Method, ResponseType } from './src/types/types';
|
||||||
|
|
||||||
export default inulaRequest;
|
export default inulaRequest;
|
||||||
|
|
|
@ -13,7 +13,13 @@
|
||||||
* See the Mulan PSL v2 for more details.
|
* See the Mulan PSL v2 for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function processDownloadProgress(stream: ReadableStream | null, response: Response, onProgress: Function | null) {
|
import { IrProgressEvent } from '../types/interfaces';
|
||||||
|
|
||||||
|
function processDownloadProgress(
|
||||||
|
stream: ReadableStream | null,
|
||||||
|
response: Response,
|
||||||
|
onProgress: (progressEvent: IrProgressEvent) => void | null
|
||||||
|
) {
|
||||||
// 文件下载过程中更新进度
|
// 文件下载过程中更新进度
|
||||||
if (onProgress) {
|
if (onProgress) {
|
||||||
const reader = stream?.getReader();
|
const reader = stream?.getReader();
|
||||||
|
|
|
@ -13,11 +13,11 @@
|
||||||
* See the Mulan PSL v2 for more details.
|
* See the Mulan PSL v2 for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { IrRequestConfig, IrResponse } from '../types/interfaces';
|
import { IrProgressEvent, IrRequestConfig, IrResponse } from '../types/interfaces';
|
||||||
import IrError from "../core/IrError";
|
import IrError from '../core/IrError';
|
||||||
|
|
||||||
function processUploadProgress(
|
function processUploadProgress(
|
||||||
onUploadProgress: Function | null,
|
onUploadProgress: (progressEvent: IrProgressEvent) => void | null,
|
||||||
data: FormData,
|
data: FormData,
|
||||||
reject: (reason?: any) => void,
|
reject: (reason?: any) => void,
|
||||||
resolve: (value: PromiseLike<IrResponse<any>> | IrResponse<any>) => void,
|
resolve: (value: PromiseLike<IrResponse<any>> | IrResponse<any>) => void,
|
||||||
|
|
|
@ -125,6 +125,9 @@ export interface IrInterface {
|
||||||
|
|
||||||
// Ir 实例接口类型
|
// Ir 实例接口类型
|
||||||
export interface IrInstance extends IrInterface {
|
export interface IrInstance extends IrInterface {
|
||||||
|
<T = any, R = IrResponse<T>>(config: IrRequestConfig): Promise<R>;
|
||||||
|
<T = any, R = IrResponse<T>>(url: string, config?: IrRequestConfig): Promise<R>;
|
||||||
|
|
||||||
// Ir 类
|
// Ir 类
|
||||||
InulaRequest: IrInterface;
|
InulaRequest: IrInterface;
|
||||||
|
|
||||||
|
@ -177,6 +180,18 @@ export interface IrInstance extends IrInterface {
|
||||||
AxiosHeaders: any;
|
AxiosHeaders: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IrProgressEvent {
|
||||||
|
loaded: string | number;
|
||||||
|
total?: string | number | null;
|
||||||
|
progress?: number;
|
||||||
|
bytes?: number;
|
||||||
|
rate?: number;
|
||||||
|
estimated?: number;
|
||||||
|
upload?: boolean;
|
||||||
|
download?: boolean;
|
||||||
|
event?: any;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Interceptors {
|
export interface Interceptors {
|
||||||
request: IrInterceptorManager<IrRequestConfig>;
|
request: IrInterceptorManager<IrRequestConfig>;
|
||||||
response: IrInterceptorManager<IrResponse>;
|
response: IrInterceptorManager<IrResponse>;
|
||||||
|
|
Loading…
Reference in New Issue