@qlibs/utils 1.7.2 → 1.7.4

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.
@@ -1,2 +1,8 @@
1
1
  import { AxiosInstance } from 'axios';
2
- export declare function injectAxiosInstance(axiosInstance: AxiosInstance, contentType: 'application/json' | 'multipart/form-data' | string, Modal: any): AxiosInstance;
2
+ export declare function injectAxiosInstance(axiosInstance: AxiosInstance, headers: 'application/json' | 'multipart/form-data' | string | {
3
+ contentType: 'application/json' | 'multipart/form-data' | string;
4
+ 'x-platform'?: 'cms' | 'web' | 'mobile';
5
+ 'x-device-id': string;
6
+ 'x-device-name': string;
7
+ 'x-app-version': string;
8
+ }, Modal: any): AxiosInstance;
@@ -2,9 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.injectAxiosInstance = injectAxiosInstance;
4
4
  const auth_1 = require("./auth");
5
- function injectAxiosInstance(axiosInstance, contentType, Modal) {
5
+ function injectAxiosInstance(axiosInstance, headers, Modal) {
6
6
  axiosInstance.interceptors.request.use(async (config) => {
7
- config.headers['Content-Type'] = contentType || 'application/json';
7
+ config.headers['Content-Type'] = (typeof headers === 'object' ? headers.contentType : headers) || 'application/json';
8
+ config.headers['x-platform'] = headers['x-platform'] || 'cms';
9
+ config.headers['x-device-id'] = headers['x-device-id'];
10
+ config.headers['x-device-name'] = headers['x-device-name'];
11
+ config.headers['x-app-version'] = headers['x-app-version'];
8
12
  config.headers['Authorization'] = 'Bearer ' + (0, auth_1.getToken)();
9
13
  return config;
10
14
  }, (error) => {
@@ -8,5 +8,5 @@ export declare function bytesToMB(sizeInBytes: number): number;
8
8
  export declare function isImage(file: File | Blob): any;
9
9
  export declare const getBase64: (file: File) => Promise<string>;
10
10
  export declare function fileListToBase64(fileList: any[]): Promise<string[]>;
11
- export declare function getFile(newFile: File | any): any;
11
+ export declare function getFile(newFile: File | any, fileType?: 'image' | 'file'): any;
12
12
  export declare function isPhotoDataOK(item: any): boolean;
@@ -105,14 +105,22 @@ async function fileListToBase64(fileList) {
105
105
  }
106
106
  return (await Promise.all(promises));
107
107
  }
108
- function getFile(newFile) {
109
- console.info('getFile - newFile instanceof File', newFile instanceof File);
110
- if (isImage(newFile) && newFile.originFileObj) {
111
- console.info('getFile - return (newFile as any).originFileObj');
108
+ function getFile(newFile, fileType = 'image') {
109
+ console.info('getFile - newFile instanceof File', newFile instanceof File, fileType);
110
+ if (fileType === 'image' && isImage(newFile) && newFile.originFileObj) {
111
+ console.info('image - getFile - return (newFile as any).originFileObj');
112
112
  return newFile.originFileObj;
113
113
  }
114
- else if (isImage(newFile) && newFile instanceof File) {
115
- console.info('getFile - return newFile');
114
+ else if (fileType === 'image' && isImage(newFile) && newFile instanceof File) {
115
+ console.info('image - getFile - return newFile');
116
+ return newFile;
117
+ }
118
+ else if (fileType === 'file' && newFile.originFileObj) {
119
+ console.info('file - getFile - return (newFile as any).originFileObj');
120
+ return newFile.originFileObj;
121
+ }
122
+ else if (fileType === 'file' && newFile instanceof File) {
123
+ console.info('file - getFile - return newFile');
116
124
  return newFile;
117
125
  }
118
126
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qlibs/utils",
3
- "version": "1.7.2",
3
+ "version": "1.7.4",
4
4
  "description": "",
5
5
  "author": "QBIT Developer",
6
6
  "license": "MIT",