@hashrytech/quick-components-kit 0.15.6 → 0.15.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -241,7 +241,7 @@ export declare class FetchClient {
|
|
|
241
241
|
* @returns A Promise resolving to the typed response from the server.
|
|
242
242
|
* @template T - Expected shape of the server's JSON response.
|
|
243
243
|
*/
|
|
244
|
-
uploadFileWithProgress<T>(endpoint: string,
|
|
244
|
+
uploadFileWithProgress<T>(endpoint: string, data: FormData, method?: "POST" | "PATCH", onProgress?: (percent: number) => void, options?: RequestOptions): Promise<T>;
|
|
245
245
|
/**
|
|
246
246
|
* Downloads a file from the specified endpoint while reporting progress.
|
|
247
247
|
*
|
|
@@ -399,10 +399,9 @@ export class FetchClient {
|
|
|
399
399
|
* @returns A Promise resolving to the typed response from the server.
|
|
400
400
|
* @template T - Expected shape of the server's JSON response.
|
|
401
401
|
*/
|
|
402
|
-
async uploadFileWithProgress(endpoint,
|
|
403
|
-
const url = new URL(endpoint, this.baseURL).toString();
|
|
404
|
-
const
|
|
405
|
-
formData.append(fieldName, file);
|
|
402
|
+
async uploadFileWithProgress(endpoint, data, method = "POST", onProgress, options = {}) {
|
|
403
|
+
//const url = new URL(endpoint, this.baseURL).toString();
|
|
404
|
+
const url = this.baseURL ? new URL(endpoint, this.baseURL).toString() : endpoint; // Resolve endpoint relative to baseURL
|
|
406
405
|
const token = this.accessToken;
|
|
407
406
|
const headers = new Headers(this.defaultHeaders);
|
|
408
407
|
// Merge user-supplied headers
|
|
@@ -412,7 +411,7 @@ export class FetchClient {
|
|
|
412
411
|
}
|
|
413
412
|
return new Promise((resolve, reject) => {
|
|
414
413
|
const xhr = new XMLHttpRequest();
|
|
415
|
-
xhr.open(
|
|
414
|
+
xhr.open(method, url, true);
|
|
416
415
|
// Add Authorization if not skipped
|
|
417
416
|
if (!options.skipAuth && token) {
|
|
418
417
|
xhr.setRequestHeader('Authorization', `Bearer ${token}`);
|
|
@@ -426,7 +425,7 @@ export class FetchClient {
|
|
|
426
425
|
});
|
|
427
426
|
xhr.upload.onprogress = (event) => {
|
|
428
427
|
if (event.lengthComputable) {
|
|
429
|
-
onProgress(Math.round((event.loaded / event.total) * 100));
|
|
428
|
+
onProgress?.(Math.round((event.loaded / event.total) * 100));
|
|
430
429
|
}
|
|
431
430
|
};
|
|
432
431
|
xhr.onload = () => {
|
|
@@ -451,7 +450,7 @@ export class FetchClient {
|
|
|
451
450
|
}
|
|
452
451
|
};
|
|
453
452
|
xhr.onerror = () => reject(new Error('Upload failed'));
|
|
454
|
-
xhr.send(
|
|
453
|
+
xhr.send(data);
|
|
455
454
|
});
|
|
456
455
|
}
|
|
457
456
|
/**
|