picgo
Version:
A tool for image uploading
40 lines (39 loc) • 2.02 kB
TypeScript
import type { AxiosRequestConfig } from 'axios';
import type { IOldReqOptions, IPicGo } from '../types';
/**
* Meta info for an `uploadWithProgress` call. `fileName` is required (consumers use it to
* disambiguate concurrent uploads); the rest are optional and default to the "non-multipart"
* placeholders.
*/
export interface IUploadProgressMeta {
/** The file name currently being uploaded (i.e. IImgInfo.fileName). */
fileName: string;
/**
* Total bytes for this upload. Axios usually fills `total` in its progress event, but some
* transports (notably SDK-wrapped requests) don't — in that case the helper falls back to
* meta.totalBytes. If neither is available, emitted payloads use total = 0, fraction = 0.
*/
totalBytes?: number;
/** Multipart-only: whether this upload is a resumed session. Defaults to false. */
resumed?: boolean;
/** Multipart-only: number of parts already completed. Defaults to -1 (N/A). */
partsCompleted?: number;
/** Multipart-only: total part count. Defaults to -1 (N/A). */
totalParts?: number;
}
type SupportedConfig = AxiosRequestConfig | IOldReqOptions;
/**
* Thin wrapper around `ctx.request` that injects axios's `onUploadProgress` hook and emits
* `IBuildInEvent.FILE_UPLOAD_PROGRESS` events as bytes flow out. Pass-through return type
* matches `ctx.request` exactly.
*
* Intent: establish a single convention for "emit progress while uploading" — built-in uploaders
* and external plugins can drop in a one-line replacement:
* `await ctx.request(opts)` → `await uploadWithProgress(ctx, opts, { fileName })`.
*
* Multipart's state machine does NOT use this helper. Per-part progress is emitted directly
* from the runner so it can include multipart-only fields (partsCompleted, resumed). This
* helper serves the simpler "one PUT/POST = one file" case.
*/
export declare function uploadWithProgress<T>(ctx: IPicGo, options: SupportedConfig, meta: IUploadProgressMeta): Promise<T>;
export {};