sales-frontend-components 0.0.186 → 0.0.188

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/dist/index.d.ts CHANGED
@@ -665,7 +665,7 @@ interface DownloadTargetInfo {
665
665
  downloadTarget: string | (() => Promise<string>);
666
666
  onSuccess?: () => void;
667
667
  onError?: () => void;
668
- fileName?: string;
668
+ fileName: string;
669
669
  }
670
670
  /**
671
671
  * @property downloadTargetInfo - 다운로드 대상 정보
package/dist/index.esm.js CHANGED
@@ -144,6 +144,16 @@ var isClient = () => {
144
144
  return false;
145
145
  }
146
146
  };
147
+ var getBusinessWorkDivisionCode = () => {
148
+ return location.pathname.split("/")[1] ?? "";
149
+ };
150
+ var getServicePath = () => {
151
+ if (typeof window.isStorybookEnv === "boolean") {
152
+ return "";
153
+ } else {
154
+ return `/${getBusinessWorkDivisionCode()}`;
155
+ }
156
+ };
147
157
  var isAndroidDevice = () => {
148
158
  if (isClient() === false) {
149
159
  return false;
@@ -4555,26 +4565,9 @@ const useDownloader = () => {
4555
4565
  const [isLoading, setIsLoading] = useState(false);
4556
4566
  const downloadFile = async (url, fileName) => {
4557
4567
  try {
4558
- let downloadUrl = "";
4559
- if (url.startsWith("http")) {
4560
- const response = await fetch(url);
4561
- if (!response.ok) {
4562
- throw new Error(`Failed to download ${url}`);
4563
- }
4564
- const blob = await response.blob();
4565
- downloadUrl = window.URL.createObjectURL(blob);
4566
- } else if (url.startsWith("blob")) {
4567
- downloadUrl = url;
4568
- } else {
4569
- throw new Error(`unknown type : ${url}`);
4570
- }
4571
- const a = document.createElement("a");
4572
- a.href = downloadUrl;
4573
- a.download = fileName || url.split("/").pop() || "download";
4574
- document.body.appendChild(a);
4575
- a.click();
4576
- a.remove();
4577
- window.URL.revokeObjectURL(downloadUrl);
4568
+ const servicePath = getServicePath();
4569
+ const downloadUrl = `${servicePath}/internal/api/download?filename=${encodeURIComponent(fileName)}&filepath=${encodeURIComponent(url)}`;
4570
+ window.location.href = downloadUrl;
4578
4571
  } catch (e) {
4579
4572
  console.error(e);
4580
4573
  throw e;