@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.
@@ -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
  };
@@ -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';
@@ -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';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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
  }
@@ -1,4 +1,5 @@
1
1
  export interface PsXhrUploadResponse {
2
2
  body: unknown;
3
+ contentType: string | null;
3
4
  status: number;
4
5
  }
@@ -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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pallasoft/ps-file-components",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/esm/index.js",