tsv2-library 1.0.61-alpha.63 → 1.0.61-alpha.64

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.
@@ -6,5 +6,5 @@ export declare const buildFileURL: (name?: string, width?: number, height?: numb
6
6
  * @param immediateRevoke Immediately revoke the object URL after download - default to true
7
7
  * @returns
8
8
  */
9
- export declare const downloadFile: (fileUrl: string, customFileName?: string, immediateRevoke?: boolean) => Promise<string>;
9
+ export declare const downloadFile: (fileUrl: string, customFileName?: string, immediateRevoke?: boolean, viewNewTab?: boolean) => Promise<string>;
10
10
  export declare const getImageURL: (name?: string | null, width?: number, height?: number, returnURLOnly?: boolean) => Promise<string | undefined>;
@@ -19603,12 +19603,14 @@ const buildFileURL = (name, width2, height) => {
19603
19603
  return url;
19604
19604
  };
19605
19605
  const getFilenameFromResponse = (response) => {
19606
- const contentDisposition = response.headers["Content-Disposition"];
19606
+ const contentDisposition = response.headers["content-disposition"];
19607
19607
  if (!contentDisposition)
19608
- return null;
19608
+ return void 0;
19609
19609
  const quotedFilenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
19610
19610
  const quotedMatch = contentDisposition.match(quotedFilenameRegex);
19611
- return (quotedMatch == null ? void 0 : quotedMatch[1]) ?? null;
19611
+ if (quotedMatch) {
19612
+ return decodeURIComponent(quotedMatch[1].replace(/['"]/g, ""));
19613
+ }
19612
19614
  };
19613
19615
  const getAuthToken = () => {
19614
19616
  const user = JSON.parse(localStorage.getItem("user") ?? "{}");
@@ -19623,19 +19625,19 @@ const fetchFile = async (url, token) => {
19623
19625
  });
19624
19626
  return {
19625
19627
  blob: new Blob([res.data], {
19626
- type: res.headers["Content-Type"] || "image/webp"
19628
+ type: res.headers["content-type"] || "image/webp"
19627
19629
  }),
19628
19630
  fileName: getFilenameFromResponse(res)
19629
19631
  };
19630
19632
  };
19631
- const downloadFile = async (fileUrl, customFileName, immediateRevoke = true) => {
19633
+ const downloadFile = async (fileUrl, customFileName, immediateRevoke = true, viewNewTab = false) => {
19632
19634
  const token = getAuthToken();
19633
19635
  const { blob: blob2, fileName: fetchFileName } = await fetchFile(fileUrl, token);
19634
19636
  let objectUrl = "";
19635
19637
  const isViewable = /^(image|application\/pdf)/i.test(blob2.type);
19636
19638
  const fileName = customFileName ?? fetchFileName;
19637
19639
  if (fileName) {
19638
- if (isViewable) {
19640
+ if (isViewable && viewNewTab) {
19639
19641
  const file = new File([blob2], fileName, {
19640
19642
  type: blob2.type
19641
19643
  });