tsv2-library 1.0.61-alpha.60 → 1.0.61-alpha.62
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,5 +1,8 @@
|
|
|
1
1
|
export declare const buildFileURL: (name?: string, width?: number, height?: number) => string;
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const fetchFile: (url: string, token: string) => Promise<{
|
|
3
|
+
blob: Blob;
|
|
4
|
+
fetchFileName: string | null;
|
|
5
|
+
}>;
|
|
3
6
|
/**
|
|
4
7
|
*
|
|
5
8
|
* @param fileUrl The full URL
|
|
@@ -7,5 +10,5 @@ export declare const fetchBlobFile: (url: string, token: string) => Promise<Blob
|
|
|
7
10
|
* @param immediateRevoke Immediately revoke the object URL after download - default to true
|
|
8
11
|
* @returns
|
|
9
12
|
*/
|
|
10
|
-
export declare const downloadFile: (fileUrl: string,
|
|
13
|
+
export declare const downloadFile: (fileUrl: string, customFileName?: string, immediateRevoke?: boolean) => Promise<string>;
|
|
11
14
|
export declare const getImageURL: (name?: string | null, width?: number, height?: number, returnURLOnly?: boolean) => Promise<string | undefined>;
|
package/dist/tsv2-library.es.js
CHANGED
|
@@ -19605,11 +19605,19 @@ const buildFileURL = (name, width2, height) => {
|
|
|
19605
19605
|
}
|
|
19606
19606
|
return url;
|
|
19607
19607
|
};
|
|
19608
|
+
const getFilenameFromResponse = (response) => {
|
|
19609
|
+
const contentDisposition = response.headers.get("Content-Disposition");
|
|
19610
|
+
if (!contentDisposition)
|
|
19611
|
+
return null;
|
|
19612
|
+
const quotedFilenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
|
|
19613
|
+
const quotedMatch = contentDisposition.match(quotedFilenameRegex);
|
|
19614
|
+
return (quotedMatch == null ? void 0 : quotedMatch[1]) ?? null;
|
|
19615
|
+
};
|
|
19608
19616
|
const getAuthToken = () => {
|
|
19609
19617
|
const user = JSON.parse(localStorage.getItem("user") ?? "{}");
|
|
19610
19618
|
return user.jwt ?? user.token ?? "";
|
|
19611
19619
|
};
|
|
19612
|
-
const
|
|
19620
|
+
const fetchFile = async (url, token) => {
|
|
19613
19621
|
const res = await fetch(url, {
|
|
19614
19622
|
headers: {
|
|
19615
19623
|
Authorization: `Bearer ${token}`
|
|
@@ -19619,29 +19627,35 @@ const fetchBlobFile = async (url, token) => {
|
|
|
19619
19627
|
throw new Error(`Image fetch failed: ${res.status} ${res.statusText}`);
|
|
19620
19628
|
}
|
|
19621
19629
|
const arrayBuffer = await res.arrayBuffer();
|
|
19622
|
-
return
|
|
19623
|
-
|
|
19624
|
-
|
|
19630
|
+
return {
|
|
19631
|
+
blob: new Blob([arrayBuffer], {
|
|
19632
|
+
type: res.headers.get("Content-Type") || "image/webp"
|
|
19633
|
+
}),
|
|
19634
|
+
fetchFileName: getFilenameFromResponse(res)
|
|
19635
|
+
};
|
|
19625
19636
|
};
|
|
19626
|
-
const downloadFile = async (fileUrl,
|
|
19637
|
+
const downloadFile = async (fileUrl, customFileName, immediateRevoke = true) => {
|
|
19627
19638
|
const token = getAuthToken();
|
|
19628
|
-
const blob2 = await
|
|
19639
|
+
const { blob: blob2, fetchFileName } = await fetchFile(fileUrl, token);
|
|
19629
19640
|
let objectUrl = "";
|
|
19630
19641
|
const isViewable = /^(image|application\/pdf)/i.test(blob2.type);
|
|
19631
|
-
|
|
19632
|
-
|
|
19633
|
-
|
|
19634
|
-
|
|
19635
|
-
|
|
19636
|
-
|
|
19637
|
-
|
|
19638
|
-
|
|
19639
|
-
|
|
19640
|
-
|
|
19641
|
-
|
|
19642
|
-
|
|
19643
|
-
|
|
19644
|
-
|
|
19642
|
+
const fileName = customFileName ?? fetchFileName;
|
|
19643
|
+
if (fileName) {
|
|
19644
|
+
if (isViewable) {
|
|
19645
|
+
const file = new File([blob2], fileName, {
|
|
19646
|
+
type: blob2.type
|
|
19647
|
+
});
|
|
19648
|
+
objectUrl = URL.createObjectURL(file);
|
|
19649
|
+
window.open(objectUrl, "_blank");
|
|
19650
|
+
} else {
|
|
19651
|
+
objectUrl = URL.createObjectURL(blob2);
|
|
19652
|
+
const a = document.createElement("a");
|
|
19653
|
+
a.href = objectUrl;
|
|
19654
|
+
a.download = fileName;
|
|
19655
|
+
document.body.appendChild(a);
|
|
19656
|
+
a.click();
|
|
19657
|
+
a.remove();
|
|
19658
|
+
}
|
|
19645
19659
|
}
|
|
19646
19660
|
if (immediateRevoke) {
|
|
19647
19661
|
URL.revokeObjectURL(objectUrl);
|
|
@@ -19651,7 +19665,7 @@ const downloadFile = async (fileUrl, fileName, immediateRevoke = true) => {
|
|
|
19651
19665
|
const createBlobURL = async (rawFileUrl) => {
|
|
19652
19666
|
try {
|
|
19653
19667
|
const token = getAuthToken();
|
|
19654
|
-
const blob2 = await
|
|
19668
|
+
const { blob: blob2 } = await fetchFile(rawFileUrl, token);
|
|
19655
19669
|
return URL.createObjectURL(blob2);
|
|
19656
19670
|
} catch (err) {
|
|
19657
19671
|
return void 0;
|
|
@@ -51971,16 +51985,19 @@ const _sfc_main$U = /* @__PURE__ */ defineComponent({
|
|
|
51971
51985
|
const totalRecords2 = ref();
|
|
51972
51986
|
const loadingTable = ref(false);
|
|
51973
51987
|
const prevQueryParams = shallowRef({});
|
|
51974
|
-
const queryParams = computed(() =>
|
|
51975
|
-
|
|
51976
|
-
|
|
51977
|
-
|
|
51978
|
-
|
|
51979
|
-
|
|
51980
|
-
|
|
51981
|
-
|
|
51982
|
-
|
|
51983
|
-
|
|
51988
|
+
const queryParams = computed(() => {
|
|
51989
|
+
var _a;
|
|
51990
|
+
return {
|
|
51991
|
+
...props.defaultQueryParams,
|
|
51992
|
+
search: (_a = props.search) == null ? void 0 : _a.trim(),
|
|
51993
|
+
page: props.usePaginator ? tablePage.value : void 0,
|
|
51994
|
+
limit: props.usePaginator ? tableRows.value : void 0,
|
|
51995
|
+
sortOrder: sortOrder2.value,
|
|
51996
|
+
sortBy: sortField2.value,
|
|
51997
|
+
...props.filters
|
|
51998
|
+
// This will resets the previous filters.
|
|
51999
|
+
};
|
|
52000
|
+
});
|
|
51984
52001
|
const isArrayIncluded = (smallArray, largeArray) => {
|
|
51985
52002
|
return smallArray.every((element) => largeArray.includes(element));
|
|
51986
52003
|
};
|