다운로드 속도 개선
This commit is contained in:
@@ -11,7 +11,7 @@ import { SidoSigunguSelectBox } from '@/components/ui/SidoSigunguSelectBox';
|
||||
import { MsSwagePplCol2, SwtrmtFcltCol2, SwtrmtPrcsZoneCol2, MsSwageMhlCol2, ExclnSewagePumpCol2, stofcbrCol2 } from './components/common/table';
|
||||
import LoadingOverlay from '@/components/ui/LoadingBar';
|
||||
//import { useDcTree, flattenFolders, useSggCd, useCityCd } from './components/searchModalReportApi';
|
||||
import { getDcTree,useDcTree,flattenFolders, useSggCd, useCityCd,getDcFile,addFileName,getDcFileDownload } from './components/searchModalReportApi';
|
||||
import { useDcTree,flattenFolders, useSggCd, useCityCd, addFileName, getFileDownload } from './components/searchModalReportApi';
|
||||
import { useCityCdStore, type SelectDataType } from './commonStore';
|
||||
|
||||
const API_URL = `${process.env.NEXT_PUBLIC_SEWERAGE_API_URL}`;
|
||||
@@ -180,23 +180,12 @@ const SearchModal: React.FC<SearchModalProps> = ({
|
||||
}
|
||||
};
|
||||
// 하수도정비기본계획.table cellClick
|
||||
const handleReportCellClick = (index: number, headId?: string) => {
|
||||
const handleReportCellClick = (index: number) => {
|
||||
console.log(index);
|
||||
const reportData = tableData[index];
|
||||
console.log(reportData);
|
||||
const fileName = reportData.fileName;
|
||||
if (reportData.filePath) {
|
||||
console.log(reportData.filePath);
|
||||
getDcFileDownload(reportData.filePath).then((data) => {
|
||||
const url = window.URL.createObjectURL(data);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = fileName; // 원하는 파일명 지정
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
window.URL.revokeObjectURL(url);
|
||||
});
|
||||
if (reportData.fileSn !== "") {
|
||||
getFileDownload(reportData.fileSn, fileName);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -105,6 +105,22 @@ export const getDcFile = async (clsfSystmSn:string) => {
|
||||
const result = await getDcData(`/api/v1/dc/file${queryString ? `?${queryString}` : ''}`);
|
||||
return result;
|
||||
};
|
||||
export const addFileName = async (data:FlattenedFolder[]) => {
|
||||
const fileReportData = await Promise.all(
|
||||
data.map(async (item) => {
|
||||
const filenameArr:ReportDataFile[] = await getDcFile(String(item.clsfSystmSn));
|
||||
const f = filenameArr[0];
|
||||
const result = {...item, fileName:f?.fileTitle, regDate:f?.regDt, fileSn:f?.fileSn, filePath:""};
|
||||
// if (f !== undefined && f.fileSn !== "") {
|
||||
// const fprcs = await getDcFileprcs(f?.fileSn);
|
||||
// if (fprcs.length>0)
|
||||
// result.filePath = fprcs[0].filePath;
|
||||
// }
|
||||
return result;
|
||||
})
|
||||
);
|
||||
return fileReportData;
|
||||
}
|
||||
export const getDcFileprcs = async (fileSn:string) => {
|
||||
const queryString = 'fileSn='+fileSn;
|
||||
console.log("getDcTree queryString:", queryString);
|
||||
@@ -112,22 +128,6 @@ export const getDcFileprcs = async (fileSn:string) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
export const addFileName = async (data:FlattenedFolder[]) => {
|
||||
const fileReportData = await Promise.all(
|
||||
data.map(async (item) => {
|
||||
const filenameArr:ReportDataFile[] = await getDcFile(String(item.clsfSystmSn));
|
||||
const f = filenameArr[0];
|
||||
const result = {...item, fileName:f?.fileTitle, regDate:f?.regDt, fileSn:f?.fileSn, filePath:""};
|
||||
if (f !== undefined && f.fileSn !== "") {
|
||||
const fprcs = await getDcFileprcs(f?.fileSn);
|
||||
if (fprcs.length>0)
|
||||
result.filePath = fprcs[0].filePath;
|
||||
}
|
||||
return result;
|
||||
})
|
||||
);
|
||||
return fileReportData;
|
||||
}
|
||||
export const getDcFileDownload = async (filePath:string) => {
|
||||
const queryString = 'filePath='+ encodeURIComponent(filePath);
|
||||
const response = await fetch(`/dc-service/api/v1/dc/file/download?${queryString}`, {
|
||||
@@ -139,6 +139,23 @@ export const getDcFileDownload = async (filePath:string) => {
|
||||
const blob = await response.blob(); // PDF, image 등은 blob으로 받아야 함
|
||||
return blob;
|
||||
};
|
||||
export const fileDownload = (data:Blob, fileName:string) => { // Blob데이터 임시link로 연결
|
||||
const url = window.URL.createObjectURL(data);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = fileName; // 원하는 파일명 지정
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
window.URL.revokeObjectURL(url);
|
||||
}
|
||||
export const getFileDownload = async (fileSn:string, fileName:string) => {
|
||||
const fileprcsData = await getDcFileprcs(fileSn); // filePath 조회
|
||||
if (fileprcsData?.length === 0 ) { alert("filePath 조회 오류"); }
|
||||
if (fileprcsData[0].filePath === "") alert("filePath 정보 없으므로 다운로드 불가");
|
||||
const blobData = await getDcFileDownload(fileprcsData[0].filePath); // 실제 다운로드 API
|
||||
fileDownload(blobData, fileName);
|
||||
}
|
||||
// 시도 데이터
|
||||
export const getCityCd = async (): Promise<SelectDataType[]> => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user