@pallasoft/ps-file-components 1.1.0 → 1.2.0
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/dist/esm/models/index.js +1 -0
- package/dist/esm/models/ps-xhr-response-type.js +1 -0
- package/dist/esm/services/ps-xhr-upload-service.js +3 -2
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.js +1 -0
- package/dist/models/ps-xhr-response-type.d.ts +1 -0
- package/dist/models/ps-xhr-response-type.js +2 -0
- package/dist/models/ps-xhr-upload-request.d.ts +2 -0
- package/dist/models/ps-xhr-upload-response.d.ts +1 -0
- package/dist/services/ps-xhr-upload-service.js +3 -2
- package/package.json +1 -1
package/dist/esm/models/index.js
CHANGED
|
@@ -18,5 +18,6 @@ export * from './ps-upload-queue-options';
|
|
|
18
18
|
export * from './ps-upload-queue-state';
|
|
19
19
|
export * from './ps-upload-summary';
|
|
20
20
|
export * from './ps-viewer-file';
|
|
21
|
+
export * from './ps-xhr-response-type';
|
|
21
22
|
export * from './ps-xhr-upload-request';
|
|
22
23
|
export * from './ps-xhr-upload-response';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -25,15 +25,16 @@ export class PsXhrUploadService {
|
|
|
25
25
|
return new Promise((resolve, reject) => {
|
|
26
26
|
const xhr = new XMLHttpRequest();
|
|
27
27
|
xhr.open(request.method === undefined ? 'POST' : request.method, request.url);
|
|
28
|
+
xhr.responseType = request.responseType === undefined ? 'text' : request.responseType;
|
|
28
29
|
Object.entries(request.headers === undefined ? {} : request.headers).forEach(([name, value]) => xhr.setRequestHeader(name, value));
|
|
29
30
|
xhr.upload.onprogress = (event) => {
|
|
30
31
|
if (event.lengthComputable && request.onProgress)
|
|
31
32
|
request.onProgress(event.total === 0 ? 1 : event.loaded / event.total);
|
|
32
33
|
};
|
|
33
34
|
xhr.onload = () => {
|
|
34
|
-
const body = PsXhrUploadService.parse(xhr.responseText);
|
|
35
|
+
const body = xhr.responseType === 'blob' ? xhr.response : PsXhrUploadService.parse(xhr.responseText);
|
|
35
36
|
if (xhr.status >= 200 && xhr.status < 300)
|
|
36
|
-
resolve({ body, status: xhr.status });
|
|
37
|
+
resolve({ body, contentType: xhr.getResponseHeader('content-type'), status: xhr.status });
|
|
37
38
|
else
|
|
38
39
|
reject(new Error(PsXhrUploadService.errorMessage(body)));
|
|
39
40
|
};
|
package/dist/models/index.d.ts
CHANGED
|
@@ -18,5 +18,6 @@ export * from './ps-upload-queue-options';
|
|
|
18
18
|
export * from './ps-upload-queue-state';
|
|
19
19
|
export * from './ps-upload-summary';
|
|
20
20
|
export * from './ps-viewer-file';
|
|
21
|
+
export * from './ps-xhr-response-type';
|
|
21
22
|
export * from './ps-xhr-upload-request';
|
|
22
23
|
export * from './ps-xhr-upload-response';
|
package/dist/models/index.js
CHANGED
|
@@ -34,5 +34,6 @@ __exportStar(require("./ps-upload-queue-options"), exports);
|
|
|
34
34
|
__exportStar(require("./ps-upload-queue-state"), exports);
|
|
35
35
|
__exportStar(require("./ps-upload-summary"), exports);
|
|
36
36
|
__exportStar(require("./ps-viewer-file"), exports);
|
|
37
|
+
__exportStar(require("./ps-xhr-response-type"), exports);
|
|
37
38
|
__exportStar(require("./ps-xhr-upload-request"), exports);
|
|
38
39
|
__exportStar(require("./ps-xhr-upload-response"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type PsXhrResponseType = 'blob' | 'text';
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import type { PsXhrResponseType } from './ps-xhr-response-type';
|
|
1
2
|
export interface PsXhrUploadRequest {
|
|
2
3
|
body: FormData;
|
|
3
4
|
headers?: Record<string, string>;
|
|
4
5
|
method?: string;
|
|
5
6
|
onProgress?: (progress: number) => void;
|
|
7
|
+
responseType?: PsXhrResponseType;
|
|
6
8
|
signal?: AbortSignal;
|
|
7
9
|
url: string;
|
|
8
10
|
}
|
|
@@ -28,15 +28,16 @@ class PsXhrUploadService {
|
|
|
28
28
|
return new Promise((resolve, reject) => {
|
|
29
29
|
const xhr = new XMLHttpRequest();
|
|
30
30
|
xhr.open(request.method === undefined ? 'POST' : request.method, request.url);
|
|
31
|
+
xhr.responseType = request.responseType === undefined ? 'text' : request.responseType;
|
|
31
32
|
Object.entries(request.headers === undefined ? {} : request.headers).forEach(([name, value]) => xhr.setRequestHeader(name, value));
|
|
32
33
|
xhr.upload.onprogress = (event) => {
|
|
33
34
|
if (event.lengthComputable && request.onProgress)
|
|
34
35
|
request.onProgress(event.total === 0 ? 1 : event.loaded / event.total);
|
|
35
36
|
};
|
|
36
37
|
xhr.onload = () => {
|
|
37
|
-
const body = PsXhrUploadService.parse(xhr.responseText);
|
|
38
|
+
const body = xhr.responseType === 'blob' ? xhr.response : PsXhrUploadService.parse(xhr.responseText);
|
|
38
39
|
if (xhr.status >= 200 && xhr.status < 300)
|
|
39
|
-
resolve({ body, status: xhr.status });
|
|
40
|
+
resolve({ body, contentType: xhr.getResponseHeader('content-type'), status: xhr.status });
|
|
40
41
|
else
|
|
41
42
|
reject(new Error(PsXhrUploadService.errorMessage(body)));
|
|
42
43
|
};
|