@tagsamurai/fats-api-services 1.0.3-alpha.32 → 1.0.3-alpha.33
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.
package/api-services.es.js
CHANGED
|
@@ -42,7 +42,7 @@ const queryParamsStringfy = (data) => {
|
|
|
42
42
|
});
|
|
43
43
|
return assignedData;
|
|
44
44
|
};
|
|
45
|
-
const
|
|
45
|
+
const buildFileURL = (name, width, height) => {
|
|
46
46
|
const BASE_URL = new URL(getBaseURL("APP_API")).origin;
|
|
47
47
|
let url = name.startsWith("http") ? name : `${BASE_URL}/file-storage/api/file/${name.replace(/^\/+/, "")}`;
|
|
48
48
|
if (width || height) {
|
|
@@ -59,7 +59,7 @@ const getAuthToken = () => {
|
|
|
59
59
|
const user = JSON.parse(localStorage.getItem("user") ?? "{}");
|
|
60
60
|
return user.jwt ?? user.token ?? "";
|
|
61
61
|
};
|
|
62
|
-
const
|
|
62
|
+
const fetchBlobFile = async (url, token) => {
|
|
63
63
|
const res = await fetch(url, {
|
|
64
64
|
headers: {
|
|
65
65
|
Authorization: `Bearer ${token}`
|
|
@@ -73,18 +73,21 @@ const fetchImageBlob = async (url, token) => {
|
|
|
73
73
|
type: res.headers.get("Content-Type") || "image/webp"
|
|
74
74
|
});
|
|
75
75
|
};
|
|
76
|
-
const
|
|
77
|
-
if (!name) return;
|
|
78
|
-
const url = buildImageUrl(name, width, height);
|
|
79
|
-
if (returnURLOnly) return url;
|
|
76
|
+
const createBlobURL = async (rawFileUrl) => {
|
|
80
77
|
try {
|
|
81
78
|
const token = getAuthToken();
|
|
82
|
-
const blob = await
|
|
79
|
+
const blob = await fetchBlobFile(rawFileUrl, token);
|
|
83
80
|
return URL.createObjectURL(blob);
|
|
84
81
|
} catch (err) {
|
|
85
82
|
return void 0;
|
|
86
83
|
}
|
|
87
84
|
};
|
|
85
|
+
const getImageURL = async (name, width, height, returnURLOnly) => {
|
|
86
|
+
if (!name) return;
|
|
87
|
+
const url = buildFileURL(name, width, height);
|
|
88
|
+
if (returnURLOnly) return url;
|
|
89
|
+
return createBlobURL(url);
|
|
90
|
+
};
|
|
88
91
|
const getAssetsFile = async (file, type = "excel") => {
|
|
89
92
|
const response = await fetch(
|
|
90
93
|
`${getBaseURL("APP_ASSETS_URL")}/${type}/${file}`
|
|
@@ -2730,6 +2733,7 @@ export {
|
|
|
2730
2733
|
TransactionSettingServices,
|
|
2731
2734
|
TransferServicesGo as TransferServices,
|
|
2732
2735
|
UserServices,
|
|
2736
|
+
buildFileURL,
|
|
2733
2737
|
getAssetsFile,
|
|
2734
2738
|
getBaseURL,
|
|
2735
2739
|
getImageURL,
|
package/api-services.system.js
CHANGED
|
@@ -49,7 +49,7 @@ System.register(["axios"], function(exports, module) {
|
|
|
49
49
|
});
|
|
50
50
|
return assignedData;
|
|
51
51
|
});
|
|
52
|
-
const
|
|
52
|
+
const buildFileURL = exports("buildFileURL", (name, width, height) => {
|
|
53
53
|
const BASE_URL = new URL(getBaseURL("APP_API")).origin;
|
|
54
54
|
let url = name.startsWith("http") ? name : `${BASE_URL}/file-storage/api/file/${name.replace(/^\/+/, "")}`;
|
|
55
55
|
if (width || height) {
|
|
@@ -61,12 +61,12 @@ System.register(["axios"], function(exports, module) {
|
|
|
61
61
|
url += `?${params.toString()}`;
|
|
62
62
|
}
|
|
63
63
|
return url;
|
|
64
|
-
};
|
|
64
|
+
});
|
|
65
65
|
const getAuthToken = () => {
|
|
66
66
|
const user = JSON.parse(localStorage.getItem("user") ?? "{}");
|
|
67
67
|
return user.jwt ?? user.token ?? "";
|
|
68
68
|
};
|
|
69
|
-
const
|
|
69
|
+
const fetchBlobFile = async (url, token) => {
|
|
70
70
|
const res = await fetch(url, {
|
|
71
71
|
headers: {
|
|
72
72
|
Authorization: `Bearer ${token}`
|
|
@@ -80,17 +80,20 @@ System.register(["axios"], function(exports, module) {
|
|
|
80
80
|
type: res.headers.get("Content-Type") || "image/webp"
|
|
81
81
|
});
|
|
82
82
|
};
|
|
83
|
-
const
|
|
84
|
-
if (!name) return;
|
|
85
|
-
const url = buildImageUrl(name, width, height);
|
|
86
|
-
if (returnURLOnly) return url;
|
|
83
|
+
const createBlobURL = async (rawFileUrl) => {
|
|
87
84
|
try {
|
|
88
85
|
const token = getAuthToken();
|
|
89
|
-
const blob = await
|
|
86
|
+
const blob = await fetchBlobFile(rawFileUrl, token);
|
|
90
87
|
return URL.createObjectURL(blob);
|
|
91
88
|
} catch (err) {
|
|
92
89
|
return void 0;
|
|
93
90
|
}
|
|
91
|
+
};
|
|
92
|
+
const getImageURL = exports("getImageURL", async (name, width, height, returnURLOnly) => {
|
|
93
|
+
if (!name) return;
|
|
94
|
+
const url = buildFileURL(name, width, height);
|
|
95
|
+
if (returnURLOnly) return url;
|
|
96
|
+
return createBlobURL(url);
|
|
94
97
|
});
|
|
95
98
|
const getAssetsFile = exports("getAssetsFile", async (file, type = "excel") => {
|
|
96
99
|
const response = await fetch(
|
package/main.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { getImageURL as getImageURL, getBaseURL, getAssetsFile, queryParamsStringfy, } from './src/utils';
|
|
1
|
+
export { getImageURL as getImageURL, getBaseURL, getAssetsFile, queryParamsStringfy, buildFileURL, } from './src/utils';
|
|
2
2
|
export { default as LogServices } from './src/services/log.service';
|
|
3
3
|
export { default as AssetServices } from './src/services/asset.service';
|
|
4
4
|
export { default as MissingServices } from './src/services/missing.service';
|
package/package.json
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
+
export declare const buildFileURL: (name: string, width?: number, height?: number) => string;
|
|
2
|
+
export declare const fetchBlobFile: (url: string, token: string) => Promise<Blob>;
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param fileUrl Full URL of the file to download
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare const downloadFile: (fileUrl: string) => Promise<string>;
|
|
1
9
|
export declare const getImageURL: (name?: string | null, width?: number, height?: number, returnURLOnly?: boolean) => Promise<string | undefined>;
|
package/src/utils/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { createAxiosInstance } from './createInstance.util';
|
|
2
2
|
export { queryParamsStringfy } from './queryParamsStringify.util';
|
|
3
|
-
export
|
|
4
|
-
export { getImageURL as oldGetImageURL } from './oldGetImageURL.util';
|
|
3
|
+
export * from './getImageURL.util';
|
|
5
4
|
export { getBaseURL } from './getBaseURL.util';
|
|
6
5
|
export { getAssetsFile } from './getAssetsFile.util';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getImageURL: (name?: string | null) => string | undefined;
|