Merge branch 'susu' into dev
This commit is contained in:
@@ -13,15 +13,21 @@
|
||||
</dd>
|
||||
</dl>
|
||||
<div class="detail-content">
|
||||
<p th:utext="${notice.content}"></p>
|
||||
<p th:utext="${ notice.content }"></p>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="download-file" th:if="${!#lists.isEmpty(notice.uploadFiles)}">
|
||||
<p class="tit">첨부파일</p>
|
||||
<ul>
|
||||
<li th:each="item : ${notice.uploadFiles}"><a th:href="${item.attachmentURL}" download
|
||||
th:text="${item.originName}"></a></li>
|
||||
<li th:each="item : ${notice.uploadFiles}">
|
||||
<a href="javascript:void(0);"
|
||||
th:text="${item.originName}"
|
||||
th:data-url="${item.attachmentURL}"
|
||||
th:data-filename="${item.originName}"
|
||||
onclick="formControl.fileDownload(this)">
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -57,13 +63,71 @@ root: /*[[|#{uri.front.info.user.path}/password|]]*/'rootUrl',
|
||||
*/
|
||||
const previousUrl = document.referrer;
|
||||
|
||||
if (previousUrl.includes('/info/notice')) {
|
||||
/* if (previousUrl.includes('/info/notice')) {
|
||||
history.back();
|
||||
} else {
|
||||
} else {*/
|
||||
location.href = '/info/notice';
|
||||
// }
|
||||
},
|
||||
fileDownload(element) {
|
||||
const url = element.dataset.url;
|
||||
const fileName = element.dataset.filename;
|
||||
if (!url || !fileName) {
|
||||
console.error('Invalid URL or fileName:', url, fileName);
|
||||
ajaxUtil._alert('파일 다운로드를 시작할 수 없습니다: 유효하지 않은 URL 또는 파일명입니다.', null);
|
||||
return;
|
||||
}
|
||||
fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/octet-stream'
|
||||
}
|
||||
}).then(response => {
|
||||
console.log('Response status:', response.status);
|
||||
if (!response.ok) {
|
||||
// 응답 본문 읽기
|
||||
return response.text().then(errorMessage => {
|
||||
let message = errorMessage || '파일 다운로드에 실패했습니다. 상태 코드: ' + response.status;
|
||||
if (response.status === 404) {
|
||||
message = errorMessage || '파일을 찾을 수 없습니다.';
|
||||
} else if (response.status === 500) {
|
||||
message = errorMessage || '서버 오류로 인해 파일 다운로드에 실패했습니다.';
|
||||
}
|
||||
throw new Error(message);
|
||||
});
|
||||
}
|
||||
// Content-Disposition 헤더에서 파일명 추출
|
||||
const disposition = response.headers.get('Content-Disposition');
|
||||
console.log('Content-Disposition:', disposition);
|
||||
let serverFileName = fileName;
|
||||
if (disposition && disposition.includes('filename*=')) {
|
||||
const matches = disposition.match(/filename\*=UTF-8''(.+)/);
|
||||
if (matches && matches[1]) {
|
||||
try {
|
||||
serverFileName = decodeURIComponent(matches[1]);
|
||||
} catch (e) {
|
||||
console.error('Failed to decode filename:', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return response.blob().then(blob => ({ blob, fileName: serverFileName }));
|
||||
})
|
||||
.then(({ blob, fileName }) => {
|
||||
console.log('Blob received, size:', blob.size);
|
||||
const link = document.createElement('a');
|
||||
link.href = window.URL.createObjectURL(blob);
|
||||
link.download = fileName;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
window.URL.revokeObjectURL(link.href);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Download error:', error);
|
||||
ajaxUtil._alert('파일 다운로드에 실패했습니다: ', null);
|
||||
});
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user