@bluecopa/core 0.1.27 → 0.1.28

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,7 +1,7 @@
1
1
  export interface FileDownloadRequest {
2
2
  fileId: string;
3
3
  contentType?: string;
4
- method?: 'GET' | 'PUT';
4
+ method?: "GET" | "PUT";
5
5
  }
6
6
  /**
7
7
  * Downloads a file from S3 using presigned URL
package/dist/index.es.js CHANGED
@@ -230,10 +230,10 @@ async function fileUpload({
230
230
  contentType,
231
231
  method
232
232
  });
233
- if (!response.data || !response.data.url) {
233
+ if (!response.data) {
234
234
  throw { message: "Failed to upload file", status: 500 };
235
235
  }
236
- const fileUploadUrl = response.data.url;
236
+ const fileUploadUrl = response.data;
237
237
  const config = {
238
238
  method,
239
239
  url: fileUploadUrl,
@@ -255,7 +255,7 @@ async function fileDownload({
255
255
  contentType,
256
256
  method
257
257
  }) {
258
- var _a, _b, _c;
258
+ var _a, _b, _c, _d;
259
259
  try {
260
260
  if (!fileId) {
261
261
  throw { message: "File ID is required", status: 400 };
@@ -265,13 +265,28 @@ async function fileDownload({
265
265
  contentType: contentType || "application/json",
266
266
  method: method || "GET"
267
267
  });
268
- if (!response.data || !response.data.data) {
268
+ if (!response.data) {
269
269
  throw { message: "Failed to download file", status: 500 };
270
270
  }
271
- return response.data.url;
271
+ const fileUrl = response.data;
272
+ let fileName = fileId;
273
+ try {
274
+ fileName = (_a = fileId.split("/").pop().split(".")) == null ? void 0 : _a[0];
275
+ } catch (error) {
276
+ }
277
+ if (fileUrl) {
278
+ const link = document.createElement("a");
279
+ link.href = fileUrl;
280
+ link.download = fileId;
281
+ link.target = "_blank";
282
+ document.body.appendChild(link);
283
+ link.click();
284
+ document.body.removeChild(link);
285
+ }
286
+ return fileUrl;
272
287
  } catch (error) {
273
- const message = ((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message || "An unexpected error occurred while downloading file";
274
- const status = ((_c = error.response) == null ? void 0 : _c.status) || 500;
288
+ const message = ((_c = (_b = error.response) == null ? void 0 : _b.data) == null ? void 0 : _c.message) || error.message || "An unexpected error occurred while downloading file";
289
+ const status = ((_d = error.response) == null ? void 0 : _d.status) || 500;
275
290
  throw { message, status };
276
291
  }
277
292
  }