From e0543791679e290adc2bbf27a709b3afb22a41ba Mon Sep 17 00:00:00 2001 From: reinforceColumn Date: Fri, 4 Jul 2025 08:11:44 +0000 Subject: [PATCH 1/2] Added onShouldRemoveFromUrlStorage functionality --- lib/options.ts | 1 + lib/upload.ts | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/options.ts b/lib/options.ts index 53a1e284..47a95295 100644 --- a/lib/options.ts +++ b/lib/options.ts @@ -63,6 +63,7 @@ export interface UploadOptions { onError?: (error: Error | DetailedError) => void onShouldRetry?: (error: DetailedError, retryAttempt: number, options: UploadOptions) => boolean onUploadUrlAvailable?: () => void | Promise + onShouldRemoveFromUrlStorage?: () => boolean | Promise overridePatchMethod: boolean headers: { [key: string]: string } diff --git a/lib/upload.ts b/lib/upload.ts index 3cebb34c..169ebe32 100644 --- a/lib/upload.ts +++ b/lib/upload.ts @@ -32,6 +32,7 @@ export const defaultOptions = { onSuccess: undefined, onError: undefined, onUploadUrlAvailable: undefined, + onShouldRemove: undefined, overridePatchMethod: false, headers: {}, @@ -938,12 +939,21 @@ export class BaseUpload { /** * Remove the entry in the URL storage, if it has been saved before. + * + * If the `onShouldRemoveFromUrlStorage` option is provided and is a function, + * it will be invoked to determine whether the removal should proceed. + * If it returns or resolves to `false`, the removal is skipped. * * @api private */ private async _removeFromUrlStorage(): Promise { if (!this._urlStorageKey) return + if (typeof this.options.onShouldRemoveFromUrlStorage === 'function') { + const shouldRemove = await Promise.resolve(this.options.onShouldRemoveFromUrlStorage()) + if (!shouldRemove) return + } + await this.options.urlStorage.removeUpload(this._urlStorageKey) this._urlStorageKey = undefined } From 3c61ee5dd68fd34f2c6326906fa5ca78fd19dadc Mon Sep 17 00:00:00 2001 From: reinforceColumn Date: Fri, 4 Jul 2025 08:16:24 +0000 Subject: [PATCH 2/2] Fix linting error --- lib/upload.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/upload.ts b/lib/upload.ts index 169ebe32..87751cbc 100644 --- a/lib/upload.ts +++ b/lib/upload.ts @@ -939,7 +939,6 @@ export class BaseUpload { /** * Remove the entry in the URL storage, if it has been saved before. - * * If the `onShouldRemoveFromUrlStorage` option is provided and is a function, * it will be invoked to determine whether the removal should proceed. * If it returns or resolves to `false`, the removal is skipped.