[inula-request]<feat> 新增对外类型 IrInstance 和 IrProgressEvent
This commit is contained in:
parent
31b5b473c6
commit
3b401b84f1
|
@ -68,7 +68,7 @@ export {
|
|||
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 default inulaRequest;
|
||||
|
|
|
@ -13,7 +13,13 @@
|
|||
* 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) {
|
||||
const reader = stream?.getReader();
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
import { IrRequestConfig, IrResponse } from '../types/interfaces';
|
||||
import IrError from "../core/IrError";
|
||||
import { IrProgressEvent, IrRequestConfig, IrResponse } from '../types/interfaces';
|
||||
import IrError from '../core/IrError';
|
||||
|
||||
function processUploadProgress(
|
||||
onUploadProgress: Function | null,
|
||||
onUploadProgress: (progressEvent: IrProgressEvent) => void | null,
|
||||
data: FormData,
|
||||
reject: (reason?: any) => void,
|
||||
resolve: (value: PromiseLike<IrResponse<any>> | IrResponse<any>) => void,
|
||||
|
|
|
@ -125,6 +125,9 @@ export interface IrInterface {
|
|||
|
||||
// Ir 实例接口类型
|
||||
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 类
|
||||
InulaRequest: IrInterface;
|
||||
|
||||
|
@ -177,6 +180,18 @@ export interface IrInstance extends IrInterface {
|
|||
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 {
|
||||
request: IrInterceptorManager<IrRequestConfig>;
|
||||
response: IrInterceptorManager<IrResponse>;
|
||||
|
|
Loading…
Reference in New Issue