import { Observable, Subject } from "rxjs"; import { VasatModel } from "./base-models"; /** * NOTE ON TYPES * ------------- * `VasatModel`, `Vasat`, and `UploadRes` are assumed to come from your * existing project (same as in the original file). Adjust the import below * to match your actual module paths — they're only sketched here so this * file is self-contained/readable. */ export interface UploadRes { finished: boolean; error: any; aborted: boolean; uploader: UploaderHandle; status?: number; } export interface UploaderHandle { readonly finish: Observable; readonly progress: Observable; upload(f: File, name: string): Observable; abort(): void; reference: any; } export declare class SimpleUpload implements UploaderHandle { private model; private fileName; progressSubject: Subject; progressObservable: Observable; reference: any; finishObs: Observable; get progress(): Observable; get finish(): Observable; constructor(model: VasatModel, fileName: string); upload(f: File, name?: string): Observable; abort(): void; } export interface ChunkedFileUploaderConfig { /** Bytes per chunk. Default 1,000,000. */ chunkSize?: number; /** * How many chunks may be in flight at once. Default 1 (fully sequential, * same behaviour as the original implementation). * * IMPORTANT: raising this above 1 only helps if the server can accept * chunks out of order / write them at arbitrary offsets concurrently. If * the server assumes chunks arrive strictly in `seq` order, keep this at 1. */ maxConcurrentChunks?: number; /** Retries for a single chunk (network error / timeout / bad response) before giving up entirely. Default 5. */ maxRetriesPerChunk?: number; /** Retries for the initial "resume from where we left off" query. Default 3. */ maxQueryRetries?: number; /** Retries for token-refresh-then-retry-chunk loop, to avoid an infinite loop on repeated auth failures. Default 3. */ maxTokenRefreshRetries?: number; /** Per-chunk XHR timeout in ms. Default 30000. */ chunkTimeoutMs?: number; /** Base delay for exponential backoff between chunk retries, in ms. Default 1000. */ retryBackoffBaseMs?: number; /** Cap on backoff delay, in ms. Default 15000. */ retryBackoffMaxMs?: number; /** if the file being sent exists and is complete * - override (defalt) override it * - fail throw error * */ existingFileBehaviour?: 'override' | 'fail'; } export declare class ChunkedFileUploader implements UploaderHandle { private model; private fileName; reference: any; private readonly progressSubject; private readonly finishSubject; private readonly progressObservable; private readonly finishObservable; private _progress; private aborted; private settled; private total; private uploadedBytes; private chunkSize; private maxConcurrentChunks; private maxRetriesPerChunk; private maxQueryRetries; private maxTokenRefreshRetries; private chunkTimeoutMs; private retryBackoffBaseMs; private retryBackoffMaxMs; private phase; private firstTask?; private lastTask?; private middleQueue; private nextMiddleIndex; private activeWorkers; private readonly inFlight; private existingFileBehaviour?; get progress(): Observable; get finish(): Observable; constructor(model: VasatModel, fileName: string, config?: ChunkedFileUploaderConfig); /** * Actually cancels in-flight work (fixes: original `abort()` only set a * flag that was checked *after* the current chunk finished uploading). */ abort(): void; upload(f: File, name?: string): Observable; private queryExistingProgress; private beginUpload; private buildChunkQueue; private spawnMiddleWorker; private uploadChunk; private handleChunkFailure; /** * Handles a confirmed chunk completion and decides what happens next * based on the chunk's role — this is where the first-alone / * middle-concurrent / last-alone guarantee is enforced. */ private onChunkSuccess; private workerDone; private finalFail; private emitFinishOnce; }