@tagsamurai/fats-api-services 1.0.3-alpha.31 → 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.
@@ -42,7 +42,7 @@ const queryParamsStringfy = (data) => {
42
42
  });
43
43
  return assignedData;
44
44
  };
45
- const buildImageUrl = (name, width, height) => {
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 fetchImageBlob = async (url, token) => {
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 getImageURL = async (name, width, height, returnURLOnly) => {
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 fetchImageBlob(url, token);
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}`
@@ -98,7 +101,7 @@ const ChangelogServices = {
98
101
  getChangelogList: (params) => {
99
102
  return API$I.get("/change-log", { params });
100
103
  },
101
- getChangelogListOptions: () => {
104
+ getChangelogListOptions: (params) => {
102
105
  return API$I.get("/change-log/options");
103
106
  },
104
107
  getSessionLogList: (params) => {
@@ -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,
@@ -49,7 +49,7 @@ System.register(["axios"], function(exports, module) {
49
49
  });
50
50
  return assignedData;
51
51
  });
52
- const buildImageUrl = (name, width, height) => {
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 fetchImageBlob = async (url, token) => {
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 getImageURL = exports("getImageURL", async (name, width, height, returnURLOnly) => {
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 fetchImageBlob(url, token);
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(
@@ -105,7 +108,7 @@ System.register(["axios"], function(exports, module) {
105
108
  getChangelogList: (params) => {
106
109
  return API$I.get("/change-log", { params });
107
110
  },
108
- getChangelogListOptions: () => {
111
+ getChangelogListOptions: (params) => {
109
112
  return API$I.get("/change-log/options");
110
113
  },
111
114
  getSessionLogList: (params) => {
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagsamurai/fats-api-services",
3
- "version": "1.0.3-alpha.31",
3
+ "version": "1.0.3-alpha.33",
4
4
  "author": "developer.tagsamurai",
5
5
  "description": "Fixed Asset Tag Samurai Services Library",
6
6
  "module": "./api-services.es.js",
@@ -1,6 +1,6 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { FetchDetailResponse, FetchListResponse, FetchOptionResponse } from '../types/fetchResponse.type';
3
- import { GetChangeLogListQueryParams, GetSessionLogListResponse, GetUserSystemLogListResponse, GetUserSystemLogOptionsResponse, SessionLogFetchParams, SessionOptionsQueryParams, SystemLogFetchParams, SystemLogLoadingFilters } from '../dto/log.dto';
3
+ import { ChangeLogOptionParams, GetChangeLogListQueryParams, GetSessionLogListResponse, GetUserSystemLogListResponse, GetUserSystemLogOptionsResponse, SessionLogFetchParams, SessionOptionsQueryParams, SystemLogFetchParams, SystemLogLoadingFilters } from '../dto/log.dto';
4
4
  import { ChangelogList, ChangelogListOptions } from '../types/log.type';
5
5
  import { GetUserLogAssignmentOptionsResponse, GetUserLogBorrowingOptionsResponse, UserLogAssignmentFetchParams, UserLogAssignmentLoadingFilters, UserLogBorrowingFetchParams, UserLogBorrowingLoadingFilters } from '../dto/user.dto';
6
6
  import { UserLogAssignment, UserLogBorrowing } from '../types/userLog.type';
@@ -10,7 +10,7 @@ import { TransactionDataType } from '../types/assetDetail.type';
10
10
  import { FetchOptionFn } from '@fewangsit/wangsvue-fats/components/filtercontainer/FilterContainer.vue';
11
11
  declare const ChangelogServices: {
12
12
  getChangelogList: (params?: GetChangeLogListQueryParams) => Promise<AxiosResponse<FetchListResponse<ChangelogList>>>;
13
- getChangelogListOptions: () => Promise<AxiosResponse<FetchDetailResponse<ChangelogListOptions>>>;
13
+ getChangelogListOptions: (params?: ChangeLogOptionParams) => Promise<AxiosResponse<FetchDetailResponse<ChangelogListOptions>>>;
14
14
  getSessionLogList: (params: SessionLogFetchParams) => Promise<AxiosResponse<GetSessionLogListResponse>>;
15
15
  getSessionLogListOptions: <T = SessionOptionsQueryParams>(params: T) => FetchOptionFn<T>;
16
16
  getTransactionLog: (params?: TransactionLogFilterParams) => Promise<AxiosResponse<FetchListResponse<TransactionDataType>>>;
@@ -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>;
@@ -1,6 +1,5 @@
1
1
  export { createAxiosInstance } from './createInstance.util';
2
2
  export { queryParamsStringfy } from './queryParamsStringify.util';
3
- export { getImageURL } from './getImageURL.util';
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;