@irontec/ivoz-ui 1.7.18 → 1.7.19

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.
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  import { useStoreActions } from 'store';
12
12
  import { saveAs } from 'file-saver';
13
+ import { parseContentDispositionFilename } from '../../helpers';
13
14
  import { Tooltip } from '@mui/material';
14
15
  import DownloadIcon from '@mui/icons-material/Download';
15
16
  import { StyledPdfButton } from './DownloadFile.styles';
@@ -23,9 +24,8 @@ export default function DownloadFile(props) {
23
24
  path: `${path}/${row.id}/${fileType}`,
24
25
  params: {},
25
26
  successCallback: (data, headers) => __awaiter(this, void 0, void 0, function* () {
26
- var _a, _b;
27
- const fileName = (_b = (_a = headers['content-disposition']) === null || _a === void 0 ? void 0 : _a.split('filename=')) === null || _b === void 0 ? void 0 : _b.pop();
28
- saveAs(data, fileName || 'download');
27
+ const fileName = parseContentDispositionFilename(headers['content-disposition'] || '');
28
+ saveAs(data, fileName);
29
29
  }),
30
30
  });
31
31
  };
@@ -1,2 +1,3 @@
1
1
  export * from './fetchAllPages';
2
2
  export * from './fetchFilteredPage';
3
+ export * from './parseContentDispositionFilename';
package/helpers/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './fetchAllPages';
2
2
  export * from './fetchFilteredPage';
3
+ export * from './parseContentDispositionFilename';
@@ -0,0 +1 @@
1
+ export declare function parseContentDispositionFilename(contentDisposition: string): string;
@@ -0,0 +1,12 @@
1
+ export function parseContentDispositionFilename(contentDisposition) {
2
+ var _a;
3
+ const filenameStar = contentDisposition.match(/filename\*\s*=\s*([^']*)'([^']*)'((?:%[0-9A-Fa-f]{2}|[!#$&+\-.^_`|~\w])+)/i);
4
+ if (filenameStar) {
5
+ return decodeURIComponent(filenameStar[3]);
6
+ }
7
+ const filename = contentDisposition.match(/filename\s*=\s*(?:"([^"]*)"|([^;\s]+))/i);
8
+ if (filename) {
9
+ return (_a = filename[1]) !== null && _a !== void 0 ? _a : filename[2];
10
+ }
11
+ return 'download';
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@irontec/ivoz-ui",
3
- "version": "1.7.18",
3
+ "version": "1.7.19",
4
4
  "description": "UI library used in ivozprovider",
5
5
  "license": "GPL-3.0",
6
6
  "main": "index.js",
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
11
  import { saveAs } from 'file-saver';
12
+ import { parseContentDispositionFilename } from '../../../../helpers';
12
13
  import { useCallback, useState, } from 'react';
13
14
  import { useStoreActions } from '../../../../store';
14
15
  import { StyledFieldsetRoot } from '../CustomComponentWrapper.styles';
@@ -52,9 +53,8 @@ const FileUploader = (props) => {
52
53
  path: downloadPath,
53
54
  params: {},
54
55
  successCallback: (data, headers) => __awaiter(void 0, void 0, void 0, function* () {
55
- var _a, _b;
56
- const fileName = (_b = (_a = headers['content-disposition']) === null || _a === void 0 ? void 0 : _a.split('filename=')) === null || _b === void 0 ? void 0 : _b.pop();
57
- saveAs(data, fileName || 'download');
56
+ const fileName = parseContentDispositionFilename(headers['content-disposition'] || '');
57
+ saveAs(data, fileName);
58
58
  }),
59
59
  });
60
60
  }