@tagsamurai/fats-api-services 1.0.0-alpha.301 → 1.0.0-alpha.303
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,19 +42,50 @@ const queryParamsStringfy = (data) => {
|
|
|
42
42
|
});
|
|
43
43
|
return assignedData;
|
|
44
44
|
};
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const filePath = name.startsWith("http") ? name : `${BASE_URL}/utility/v2/files/${name.replace(/^\/+/, "")}`;
|
|
45
|
+
const buildImageUrl = (name, width, height) => {
|
|
46
|
+
const BASE_URL = new URL(getBaseURL("APP_API")).origin;
|
|
47
|
+
let url = name.startsWith("http") ? name : `${BASE_URL}/file-storage/api/file/${name.replace(/^\/+/, "")}`;
|
|
49
48
|
if (width || height) {
|
|
50
49
|
const params = new URLSearchParams();
|
|
51
50
|
if (width) {
|
|
52
51
|
params.set("width", width.toString());
|
|
53
|
-
params.set("height", height
|
|
52
|
+
params.set("height", (height == null ? void 0 : height.toString()) || width.toString());
|
|
53
|
+
}
|
|
54
|
+
url += `?${params.toString()}`;
|
|
55
|
+
}
|
|
56
|
+
return url;
|
|
57
|
+
};
|
|
58
|
+
const getAuthToken = () => {
|
|
59
|
+
const user = JSON.parse(localStorage.getItem("user") ?? "{}");
|
|
60
|
+
return user.jwt ?? user.token ?? "";
|
|
61
|
+
};
|
|
62
|
+
const fetchImageBlob = async (url, token) => {
|
|
63
|
+
const res = await fetch(url, {
|
|
64
|
+
headers: {
|
|
65
|
+
Authorization: `Bearer ${token}`
|
|
54
66
|
}
|
|
55
|
-
|
|
67
|
+
});
|
|
68
|
+
if (!res.ok) {
|
|
69
|
+
throw new Error(`Image fetch failed: ${res.status} ${res.statusText}`);
|
|
70
|
+
}
|
|
71
|
+
return res.blob();
|
|
72
|
+
};
|
|
73
|
+
const blobToDataURI = (blob) => new Promise((resolve, reject) => {
|
|
74
|
+
const reader = new FileReader();
|
|
75
|
+
reader.onloadend = () => resolve(reader.result);
|
|
76
|
+
reader.onerror = reject;
|
|
77
|
+
reader.readAsDataURL(blob);
|
|
78
|
+
});
|
|
79
|
+
const getImageURL = async (name, width, height) => {
|
|
80
|
+
if (!name) return;
|
|
81
|
+
try {
|
|
82
|
+
const url = buildImageUrl(name, width, height);
|
|
83
|
+
const token = getAuthToken();
|
|
84
|
+
const blob = await fetchImageBlob(url, token);
|
|
85
|
+
return blobToDataURI(blob);
|
|
86
|
+
} catch (err) {
|
|
87
|
+
return void 0;
|
|
56
88
|
}
|
|
57
|
-
return filePath;
|
|
58
89
|
};
|
|
59
90
|
const getAssetsFile = async (file, type = "excel") => {
|
|
60
91
|
const response = await fetch(
|
|
@@ -1875,6 +1906,9 @@ const ReaderServices = {
|
|
|
1875
1906
|
getIOTReaderListOptions: (params) => {
|
|
1876
1907
|
return API$b.get("/options", { params });
|
|
1877
1908
|
},
|
|
1909
|
+
setIOTAliasName: (body) => {
|
|
1910
|
+
return API$b.put("/set-alias-name", body);
|
|
1911
|
+
},
|
|
1878
1912
|
getActivityLogData: (params) => {
|
|
1879
1913
|
return API$b.get("/activity-log", { params });
|
|
1880
1914
|
},
|
package/api-services.system.js
CHANGED
|
@@ -49,19 +49,50 @@ System.register(["axios"], function(exports, module) {
|
|
|
49
49
|
});
|
|
50
50
|
return assignedData;
|
|
51
51
|
});
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const filePath = name.startsWith("http") ? name : `${BASE_URL}/utility/v2/files/${name.replace(/^\/+/, "")}`;
|
|
52
|
+
const buildImageUrl = (name, width, height) => {
|
|
53
|
+
const BASE_URL = new URL(getBaseURL("APP_API")).origin;
|
|
54
|
+
let url = name.startsWith("http") ? name : `${BASE_URL}/file-storage/api/file/${name.replace(/^\/+/, "")}`;
|
|
56
55
|
if (width || height) {
|
|
57
56
|
const params = new URLSearchParams();
|
|
58
57
|
if (width) {
|
|
59
58
|
params.set("width", width.toString());
|
|
60
|
-
params.set("height", height
|
|
59
|
+
params.set("height", (height == null ? void 0 : height.toString()) || width.toString());
|
|
60
|
+
}
|
|
61
|
+
url += `?${params.toString()}`;
|
|
62
|
+
}
|
|
63
|
+
return url;
|
|
64
|
+
};
|
|
65
|
+
const getAuthToken = () => {
|
|
66
|
+
const user = JSON.parse(localStorage.getItem("user") ?? "{}");
|
|
67
|
+
return user.jwt ?? user.token ?? "";
|
|
68
|
+
};
|
|
69
|
+
const fetchImageBlob = async (url, token) => {
|
|
70
|
+
const res = await fetch(url, {
|
|
71
|
+
headers: {
|
|
72
|
+
Authorization: `Bearer ${token}`
|
|
61
73
|
}
|
|
62
|
-
|
|
74
|
+
});
|
|
75
|
+
if (!res.ok) {
|
|
76
|
+
throw new Error(`Image fetch failed: ${res.status} ${res.statusText}`);
|
|
77
|
+
}
|
|
78
|
+
return res.blob();
|
|
79
|
+
};
|
|
80
|
+
const blobToDataURI = (blob) => new Promise((resolve, reject) => {
|
|
81
|
+
const reader = new FileReader();
|
|
82
|
+
reader.onloadend = () => resolve(reader.result);
|
|
83
|
+
reader.onerror = reject;
|
|
84
|
+
reader.readAsDataURL(blob);
|
|
85
|
+
});
|
|
86
|
+
const getImageURL = exports("getImageURL", async (name, width, height) => {
|
|
87
|
+
if (!name) return;
|
|
88
|
+
try {
|
|
89
|
+
const url = buildImageUrl(name, width, height);
|
|
90
|
+
const token = getAuthToken();
|
|
91
|
+
const blob = await fetchImageBlob(url, token);
|
|
92
|
+
return blobToDataURI(blob);
|
|
93
|
+
} catch (err) {
|
|
94
|
+
return void 0;
|
|
63
95
|
}
|
|
64
|
-
return filePath;
|
|
65
96
|
});
|
|
66
97
|
const getAssetsFile = exports("getAssetsFile", async (file, type = "excel") => {
|
|
67
98
|
const response = await fetch(
|
|
@@ -1882,6 +1913,9 @@ System.register(["axios"], function(exports, module) {
|
|
|
1882
1913
|
getIOTReaderListOptions: (params) => {
|
|
1883
1914
|
return API$b.get("/options", { params });
|
|
1884
1915
|
},
|
|
1916
|
+
setIOTAliasName: (body) => {
|
|
1917
|
+
return API$b.put("/set-alias-name", body);
|
|
1918
|
+
},
|
|
1885
1919
|
getActivityLogData: (params) => {
|
|
1886
1920
|
return API$b.get("/activity-log", { params });
|
|
1887
1921
|
},
|
package/package.json
CHANGED
package/src/dto/reader.dto.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { ActivityLogOptionParams, ChangeLogOptionParams, ChangeLogParams, IOTReaderList, IOTReaderListOptions, QueryParams } from '../types/reader.type';
|
|
3
|
-
import { FetchDetailResponse, FetchListResponse } from '../types/fetchResponse.type';
|
|
4
|
-
import { GetIOTReaderListOptionsQueryParams, GetIOTReaderListQueryParams } from '../dto/reader.dto';
|
|
3
|
+
import { FetchDetailResponse, FetchListResponse, FetchResponse } from '../types/fetchResponse.type';
|
|
4
|
+
import { GetIOTReaderListOptionsQueryParams, GetIOTReaderListQueryParams, SetIOTAliasNameBody } from '../dto/reader.dto';
|
|
5
5
|
declare const ReaderServices: {
|
|
6
6
|
getIOTReaderList: (params: GetIOTReaderListQueryParams) => Promise<AxiosResponse<FetchListResponse<IOTReaderList>>>;
|
|
7
7
|
getIOTReaderListOptions: (params: GetIOTReaderListOptionsQueryParams) => Promise<AxiosResponse<FetchDetailResponse<IOTReaderListOptions>>>;
|
|
8
|
+
setIOTAliasName: (body: SetIOTAliasNameBody) => Promise<AxiosResponse<FetchResponse>>;
|
|
8
9
|
getActivityLogData: (params: QueryParams) => Promise<AxiosResponse>;
|
|
9
10
|
getActivityLogOptions: (params: ActivityLogOptionParams) => Promise<AxiosResponse>;
|
|
10
11
|
getDataById: (id: string) => Promise<AxiosResponse>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const getImageURL: (name?: string | null, width?: number, height?: number) => string | undefined
|
|
1
|
+
export declare const getImageURL: (name?: string | null, width?: number, height?: number) => Promise<string | undefined>;
|