tsv2-library 1.0.61-alpha.62 → 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.
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
export declare const buildFileURL: (name?: string, width?: number, height?: number) => string;
|
|
2
|
-
export declare const fetchFile: (url: string, token: string) => Promise<{
|
|
3
|
-
blob: Blob;
|
|
4
|
-
fetchFileName: string | null;
|
|
5
|
-
}>;
|
|
6
2
|
/**
|
|
7
3
|
*
|
|
8
4
|
* @param fileUrl The full URL
|
|
@@ -10,5 +6,5 @@ export declare const fetchFile: (url: string, token: string) => Promise<{
|
|
|
10
6
|
* @param immediateRevoke Immediately revoke the object URL after download - default to true
|
|
11
7
|
* @returns
|
|
12
8
|
*/
|
|
13
|
-
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>;
|
|
14
10
|
export declare const getImageURL: (name?: string | null, width?: number, height?: number, returnURLOnly?: boolean) => Promise<string | undefined>;
|
package/dist/tsv2-library.es.js
CHANGED
|
@@ -19186,11 +19186,11 @@ function generateXlsxFile(data30, _ref2) {
|
|
|
19186
19186
|
}
|
|
19187
19187
|
const prepareRows = (headers, data30) => {
|
|
19188
19188
|
const rows3 = [];
|
|
19189
|
+
if (headers) {
|
|
19190
|
+
rows3.push(headers.map((h2) => ({ value: h2 })));
|
|
19191
|
+
}
|
|
19189
19192
|
const isObjectArray = Array.isArray(data30) && data30.length > 0 && !Array.isArray(data30[0]);
|
|
19190
19193
|
if (isObjectArray) {
|
|
19191
|
-
if (headers) {
|
|
19192
|
-
rows3.push(headers.map((h2) => ({ value: h2 })));
|
|
19193
|
-
}
|
|
19194
19194
|
if (data30.length > 0) {
|
|
19195
19195
|
const keys2 = Object.keys(data30[0]);
|
|
19196
19196
|
data30.forEach((row2) => {
|
|
@@ -19204,9 +19204,6 @@ const prepareRows = (headers, data30) => {
|
|
|
19204
19204
|
}
|
|
19205
19205
|
} else if (Array.isArray(data30) && Array.isArray(data30[0])) {
|
|
19206
19206
|
const arrayData = data30;
|
|
19207
|
-
if (headers) {
|
|
19208
|
-
rows3.push(headers.map((h2) => ({ value: h2 })));
|
|
19209
|
-
}
|
|
19210
19207
|
arrayData.forEach((row2) => {
|
|
19211
19208
|
if (row2.length === 0) {
|
|
19212
19209
|
rows3.push([{ value: "" }]);
|
|
@@ -19606,42 +19603,41 @@ const buildFileURL = (name, width2, height) => {
|
|
|
19606
19603
|
return url;
|
|
19607
19604
|
};
|
|
19608
19605
|
const getFilenameFromResponse = (response) => {
|
|
19609
|
-
const contentDisposition = response.headers
|
|
19606
|
+
const contentDisposition = response.headers["content-disposition"];
|
|
19610
19607
|
if (!contentDisposition)
|
|
19611
|
-
return
|
|
19608
|
+
return void 0;
|
|
19612
19609
|
const quotedFilenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
|
|
19613
19610
|
const quotedMatch = contentDisposition.match(quotedFilenameRegex);
|
|
19614
|
-
|
|
19611
|
+
if (quotedMatch) {
|
|
19612
|
+
return decodeURIComponent(quotedMatch[1].replace(/['"]/g, ""));
|
|
19613
|
+
}
|
|
19615
19614
|
};
|
|
19616
19615
|
const getAuthToken = () => {
|
|
19617
19616
|
const user = JSON.parse(localStorage.getItem("user") ?? "{}");
|
|
19618
19617
|
return user.jwt ?? user.token ?? "";
|
|
19619
19618
|
};
|
|
19620
19619
|
const fetchFile = async (url, token) => {
|
|
19621
|
-
const res = await
|
|
19620
|
+
const res = await axios.get(url, {
|
|
19621
|
+
responseType: "blob",
|
|
19622
19622
|
headers: {
|
|
19623
19623
|
Authorization: `Bearer ${token}`
|
|
19624
19624
|
}
|
|
19625
19625
|
});
|
|
19626
|
-
if (!res.ok) {
|
|
19627
|
-
throw new Error(`Image fetch failed: ${res.status} ${res.statusText}`);
|
|
19628
|
-
}
|
|
19629
|
-
const arrayBuffer = await res.arrayBuffer();
|
|
19630
19626
|
return {
|
|
19631
|
-
blob: new Blob([
|
|
19632
|
-
type: res.headers
|
|
19627
|
+
blob: new Blob([res.data], {
|
|
19628
|
+
type: res.headers["content-type"] || "image/webp"
|
|
19633
19629
|
}),
|
|
19634
|
-
|
|
19630
|
+
fileName: getFilenameFromResponse(res)
|
|
19635
19631
|
};
|
|
19636
19632
|
};
|
|
19637
|
-
const downloadFile = async (fileUrl, customFileName, immediateRevoke = true) => {
|
|
19633
|
+
const downloadFile = async (fileUrl, customFileName, immediateRevoke = true, viewNewTab = false) => {
|
|
19638
19634
|
const token = getAuthToken();
|
|
19639
|
-
const { blob: blob2, fetchFileName } = await fetchFile(fileUrl, token);
|
|
19635
|
+
const { blob: blob2, fileName: fetchFileName } = await fetchFile(fileUrl, token);
|
|
19640
19636
|
let objectUrl = "";
|
|
19641
19637
|
const isViewable = /^(image|application\/pdf)/i.test(blob2.type);
|
|
19642
19638
|
const fileName = customFileName ?? fetchFileName;
|
|
19643
19639
|
if (fileName) {
|
|
19644
|
-
if (isViewable) {
|
|
19640
|
+
if (isViewable && viewNewTab) {
|
|
19645
19641
|
const file = new File([blob2], fileName, {
|
|
19646
19642
|
type: blob2.type
|
|
19647
19643
|
});
|