Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -884,16 +884,10 @@ HTML = """
|
|
884 |
|
885 |
<section id="home" class="fade-in">
|
886 |
<div class="upload-container">
|
887 |
-
|
888 |
-
<
|
889 |
-
<i class="fas fa-images"></i> ์ด๋ฏธ์ง ์ถ๊ฐ
|
890 |
-
<input id="imgInput" type="file" accept="image/*" multiple hidden>
|
891 |
-
</button>
|
892 |
-
<button class="upload" id="pdfUploadBtn" onclick="document.getElementById('pdfInput').click(); return false;">
|
893 |
-
<i class="fas fa-file-pdf"></i> PDF ์ถ๊ฐ
|
894 |
-
<input id="pdfInput" type="file" accept="application/pdf" hidden>
|
895 |
-
|
896 |
</button>
|
|
|
897 |
</div>
|
898 |
|
899 |
<div class="section-title">๋ด ํ๋ก์ ํธ</div>
|
@@ -901,7 +895,7 @@ HTML = """
|
|
901 |
<!-- ์นด๋๊ฐ ์ฌ๊ธฐ์ ๋์ ์ผ๋ก ์ถ๊ฐ๋ฉ๋๋ค -->
|
902 |
</div>
|
903 |
<div id="noProjects" class="no-projects" style="display: none;">
|
904 |
-
ํ๋ก์ ํธ๊ฐ ์์ต๋๋ค.
|
905 |
</div>
|
906 |
</section>
|
907 |
|
@@ -912,7 +906,7 @@ HTML = """
|
|
912 |
|
913 |
<script>
|
914 |
let projects=[], fb=null;
|
915 |
-
const grid
|
916 |
pdfjsLib.GlobalWorkerOptions.workerSrc='/static/pdf.worker.js';
|
917 |
|
918 |
// ์๋ฒ์์ ๋ฏธ๋ฆฌ ๋ก๋๋ PDF ํ๋ก์ ํธ
|
@@ -929,135 +923,86 @@ HTML = """
|
|
929 |
{once:true,capture:true});
|
930 |
});
|
931 |
|
932 |
-
// ์
๋ก๋ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ ํจ์
|
933 |
-
function setupUploadButtons() {
|
934 |
-
// ๋ชจ๋ ์
๋ก๋ ๋ฒํผ์ ์ด๋ฒคํธ ๋ฆฌ์ค๋ ์ถ๊ฐ
|
935 |
-
document.querySelectorAll('.upload').forEach(button => {
|
936 |
-
button.addEventListener('click', function(e) {
|
937 |
-
// ๋ฒํผ ๋ด๋ถ์ input ์์ ์ฐพ๊ธฐ
|
938 |
-
const inputElement = this.querySelector('input[type="file"]');
|
939 |
-
if (inputElement) {
|
940 |
-
// input ์์ ํด๋ฆญ (ํ์ผ ์ ํ ๋ค์ด์ผ๋ก๊ทธ ์ด๊ธฐ)
|
941 |
-
inputElement.click();
|
942 |
-
e.preventDefault(); // ๋ฒํผ ๊ธฐ๋ณธ ๋์ ๋ฐฉ์ง
|
943 |
-
}
|
944 |
-
});
|
945 |
-
});
|
946 |
-
}
|
947 |
-
|
948 |
/* โโ ์ ํธ โโ */
|
949 |
function $id(id){return document.getElementById(id)}
|
950 |
|
951 |
-
//
|
952 |
-
|
953 |
-
|
954 |
-
console.log('์ด๋ฒคํธ ์ค์ ์์');
|
955 |
-
|
956 |
-
// ์ด๋ฏธ์ง ์
๋ก๋ ๋ฒํผ
|
957 |
-
const imageBtn = document.getElementById('imageUploadBtn');
|
958 |
-
const imageInput = document.getElementById('imgInput');
|
959 |
-
|
960 |
-
if (imageBtn && imageInput) {
|
961 |
-
console.log('์ด๋ฏธ์ง ๋ฒํผ ์ฐพ์:', imageBtn);
|
962 |
-
// ์ด๋ฒคํธ ๋ฆฌ์ค๋๋ฅผ ๋ช
์์ ์ผ๋ก ์ ๊ฑฐํ๊ณ ๋ค์ ์ถ๊ฐ
|
963 |
-
imageBtn.removeEventListener('click', imageClickHandler);
|
964 |
-
imageBtn.addEventListener('click', imageClickHandler);
|
965 |
-
|
966 |
-
function imageClickHandler(e) {
|
967 |
-
console.log('์ด๋ฏธ์ง ๋ฒํผ ํด๋ฆญ๋จ');
|
968 |
-
e.preventDefault();
|
969 |
-
e.stopPropagation();
|
970 |
-
imageInput.click();
|
971 |
-
}
|
972 |
-
} else {
|
973 |
-
console.error('์ด๋ฏธ์ง ๋ฒํผ ๋๋ ์ธํ์ ์ฐพ์ ์ ์์');
|
974 |
-
}
|
975 |
-
|
976 |
-
// PDF ์
๋ก๋ ๋ฒํผ
|
977 |
-
const pdfBtn = document.getElementById('pdfUploadBtn');
|
978 |
-
const pdfInput = document.getElementById('pdfInput');
|
979 |
-
|
980 |
-
if (pdfBtn && pdfInput) {
|
981 |
-
console.log('PDF ๋ฒํผ ์ฐพ์:', pdfBtn);
|
982 |
-
// ์ด๋ฒคํธ ๋ฆฌ์ค๋๋ฅผ ๋ช
์์ ์ผ๋ก ์ ๊ฑฐํ๊ณ ๋ค์ ์ถ๊ฐ
|
983 |
-
pdfBtn.removeEventListener('click', pdfClickHandler);
|
984 |
-
pdfBtn.addEventListener('click', pdfClickHandler);
|
985 |
-
|
986 |
-
function pdfClickHandler(e) {
|
987 |
-
console.log('PDF ๋ฒํผ ํด๋ฆญ๋จ');
|
988 |
-
e.preventDefault();
|
989 |
-
e.stopPropagation();
|
990 |
-
pdfInput.click();
|
991 |
-
}
|
992 |
-
} else {
|
993 |
-
console.error('PDF ๋ฒํผ ๋๋ ์ธํ์ ์ฐพ์ ์ ์์');
|
994 |
-
}
|
995 |
-
|
996 |
-
// ํ์ผ ์ ํ ์ด๋ฒคํธ ์ฌ์ค์
|
997 |
-
if (imageInput) {
|
998 |
-
imageInput.onchange = function(e) {
|
999 |
-
console.log('์ด๋ฏธ์ง ํ์ผ ์ ํ๋จ:', e.target.files.length);
|
1000 |
-
const files = [...e.target.files];
|
1001 |
-
if (!files.length) return;
|
1002 |
|
1003 |
-
|
|
|
|
|
1004 |
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
};
|
1020 |
-
}
|
1021 |
-
|
1022 |
-
if (pdfInput) {
|
1023 |
-
pdfInput.onchange = function(e) {
|
1024 |
-
console.log('PDF ํ์ผ ์ ํ๋จ:', e.target.files.length);
|
1025 |
-
const file = e.target.files[0];
|
1026 |
-
if (!file) return;
|
1027 |
-
|
1028 |
-
showLoading("PDF ๋ก๋ฉ ์ค...");
|
1029 |
-
|
1030 |
-
const fr = new FileReader();
|
1031 |
-
fr.onload = v => {
|
1032 |
-
pdfjsLib.getDocument({data: v.target.result}).promise.then(async pdf => {
|
1033 |
-
const pages = [];
|
1034 |
|
1035 |
-
|
1036 |
-
updateLoading(`PDF ํ์ด์ง ๋ก๋ฉ ์ค... (${p}/${pdf.numPages})`);
|
1037 |
-
|
1038 |
-
const pg = await pdf.getPage(p);
|
1039 |
-
const vp = pg.getViewport({scale: 1});
|
1040 |
-
const c = document.createElement('canvas');
|
1041 |
-
c.width = vp.width;
|
1042 |
-
c.height = vp.height;
|
1043 |
-
await pg.render({canvasContext: c.getContext('2d'), viewport: vp}).promise;
|
1044 |
-
pages.push({src: c.toDataURL(), thumb: c.toDataURL()});
|
1045 |
-
}
|
1046 |
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1053 |
});
|
1054 |
-
}
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
|
|
|
|
|
|
1061 |
|
1062 |
function addCard(i, thumb, title, isCached = false) {
|
1063 |
const d = document.createElement('div');
|
@@ -1086,54 +1031,6 @@ function setupDirectEvents() {
|
|
1086 |
$id('noProjects').style.display = 'none';
|
1087 |
}
|
1088 |
|
1089 |
-
/* โโ ์ด๋ฏธ์ง ์
๋ก๋ โโ */
|
1090 |
-
$id('imgInput').onchange=e=>{
|
1091 |
-
const files=[...e.target.files]; if(!files.length) return;
|
1092 |
-
|
1093 |
-
// ๋ก๋ฉ ํ์ ์ถ๊ฐ
|
1094 |
-
showLoading("์ด๋ฏธ์ง ๋ก๋ฉ ์ค...");
|
1095 |
-
|
1096 |
-
const pages=[],tot=files.length;let done=0;
|
1097 |
-
files.forEach((f,i)=>{const r=new FileReader();r.onload=x=>{pages[i]={src:x.target.result,thumb:x.target.result};
|
1098 |
-
if(++done===tot) {
|
1099 |
-
save(pages, '์ด๋ฏธ์ง ์ปฌ๋ ์
');
|
1100 |
-
hideLoading();
|
1101 |
-
}
|
1102 |
-
};r.readAsDataURL(f);});
|
1103 |
-
};
|
1104 |
-
|
1105 |
-
/* โโ PDF ์
๋ก๋ โโ */
|
1106 |
-
$id('pdfInput').onchange=e=>{
|
1107 |
-
const file=e.target.files[0]; if(!file) return;
|
1108 |
-
|
1109 |
-
// ๋ก๋ฉ ํ์ ์ถ๊ฐ
|
1110 |
-
showLoading("PDF ๋ก๋ฉ ์ค...");
|
1111 |
-
|
1112 |
-
const fr=new FileReader();
|
1113 |
-
fr.onload=v=>{
|
1114 |
-
pdfjsLib.getDocument({data:v.target.result}).promise.then(async pdf=>{
|
1115 |
-
const pages=[];
|
1116 |
-
|
1117 |
-
for(let p=1;p<=pdf.numPages;p++){
|
1118 |
-
// ๋ก๋ฉ ์ํ ์
๋ฐ์ดํธ
|
1119 |
-
updateLoading(`PDF ํ์ด์ง ๋ก๋ฉ ์ค... (${p}/${pdf.numPages})`);
|
1120 |
-
|
1121 |
-
const pg=await pdf.getPage(p), vp=pg.getViewport({scale:1});
|
1122 |
-
const c=document.createElement('canvas');c.width=vp.width;c.height=vp.height;
|
1123 |
-
await pg.render({canvasContext:c.getContext('2d'),viewport:vp}).promise;
|
1124 |
-
pages.push({src:c.toDataURL(),thumb:c.toDataURL()});
|
1125 |
-
}
|
1126 |
-
|
1127 |
-
hideLoading();
|
1128 |
-
save(pages, file.name.replace('.pdf', ''));
|
1129 |
-
}).catch(error => {
|
1130 |
-
console.error("PDF ๋ก๋ฉ ์ค๋ฅ:", error);
|
1131 |
-
hideLoading();
|
1132 |
-
showError("PDF ๋ก๋ฉ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.");
|
1133 |
-
});
|
1134 |
-
};fr.readAsArrayBuffer(file);
|
1135 |
-
};
|
1136 |
-
|
1137 |
/* โโ ํ๋ก์ ํธ ์ ์ฅ โโ */
|
1138 |
function save(pages, title, isCached = false){
|
1139 |
const id=projects.push(pages)-1;
|
@@ -1727,28 +1624,6 @@ function setupDirectEvents() {
|
|
1727 |
}
|
1728 |
}, 5000);
|
1729 |
}
|
1730 |
-
|
1731 |
-
|
1732 |
-
// ํ์ด์ง ๋ก๋ ์ ์๋ฒ PDF ๋ก๋
|
1733 |
-
window.addEventListener('DOMContentLoaded', () => {
|
1734 |
-
console.log('DOM ๋ก๋๋จ');
|
1735 |
-
|
1736 |
-
// ์ง์ ์ด๋ฒคํธ ๋ฆฌ์ค๋ ์ค์ (๋ ํ์คํ ๋ฐฉ๋ฒ)
|
1737 |
-
setupDirectEvents();
|
1738 |
-
|
1739 |
-
// ์ฝ๊ฐ์ ์ง์ฐ ํ ๋ค์ ํ๋ฒ ์ด๋ฒคํธ ์ค์ (DOM ์์ ๋ก๋ ๋ณด์ฅ)
|
1740 |
-
setTimeout(() => {
|
1741 |
-
console.log('์ง์ฐ ํ ์ด๋ฒคํธ ์ฌ์ค์ ');
|
1742 |
-
setupDirectEvents();
|
1743 |
-
}, 500);
|
1744 |
-
|
1745 |
-
loadServerPDFs();
|
1746 |
-
|
1747 |
-
// ์บ์ ์ํ๋ฅผ ์ฃผ๊ธฐ์ ์ผ๋ก ํ์ธ (3์ด๋ง๋ค)
|
1748 |
-
setInterval(checkCacheStatus, 3000);
|
1749 |
-
});
|
1750 |
-
|
1751 |
-
|
1752 |
</script>
|
1753 |
</body>
|
1754 |
</html>
|
|
|
884 |
|
885 |
<section id="home" class="fade-in">
|
886 |
<div class="upload-container">
|
887 |
+
<button class="upload" id="pdfUploadBtn">
|
888 |
+
<i class="fas fa-file-pdf"></i> PDF ์ถ๊ฐ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
889 |
</button>
|
890 |
+
<input id="pdfInput" type="file" accept="application/pdf" style="display:none">
|
891 |
</div>
|
892 |
|
893 |
<div class="section-title">๋ด ํ๋ก์ ํธ</div>
|
|
|
895 |
<!-- ์นด๋๊ฐ ์ฌ๊ธฐ์ ๋์ ์ผ๋ก ์ถ๊ฐ๋ฉ๋๋ค -->
|
896 |
</div>
|
897 |
<div id="noProjects" class="no-projects" style="display: none;">
|
898 |
+
ํ๋ก์ ํธ๊ฐ ์์ต๋๋ค. PDF๋ฅผ ์ถ๊ฐํ์ฌ ์์ํ์ธ์.
|
899 |
</div>
|
900 |
</section>
|
901 |
|
|
|
906 |
|
907 |
<script>
|
908 |
let projects=[], fb=null;
|
909 |
+
const grid=document.getElementById('grid'), viewer=document.getElementById('viewer');
|
910 |
pdfjsLib.GlobalWorkerOptions.workerSrc='/static/pdf.worker.js';
|
911 |
|
912 |
// ์๋ฒ์์ ๋ฏธ๋ฆฌ ๋ก๋๋ PDF ํ๋ก์ ํธ
|
|
|
923 |
{once:true,capture:true});
|
924 |
});
|
925 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
926 |
/* โโ ์ ํธ โโ */
|
927 |
function $id(id){return document.getElementById(id)}
|
928 |
|
929 |
+
// ํ์ผ ์
๋ก๋ ์ด๋ฒคํธ ์ฒ๋ฆฌ
|
930 |
+
document.addEventListener("DOMContentLoaded", function() {
|
931 |
+
console.log("DOM ๋ก๋ ์๋ฃ, ์ด๋ฒคํธ ์ค์ ์์");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
932 |
|
933 |
+
// PDF ์
๋ก๋ ๋ฒํผ
|
934 |
+
const pdfBtn = document.getElementById('pdfUploadBtn');
|
935 |
+
const pdfInput = document.getElementById('pdfInput');
|
936 |
|
937 |
+
if (pdfBtn && pdfInput) {
|
938 |
+
console.log("PDF ์
๋ก๋ ๋ฒํผ ์ฐพ์");
|
939 |
+
|
940 |
+
// ๋ฒํผ ํด๋ฆญ ์ ํ์ผ ์
๋ ฅ ํธ๋ฆฌ๊ฑฐ
|
941 |
+
pdfBtn.addEventListener('click', function() {
|
942 |
+
console.log("PDF ๋ฒํผ ํด๋ฆญ๋จ");
|
943 |
+
pdfInput.click();
|
944 |
+
});
|
945 |
+
|
946 |
+
// ํ์ผ ์ ํ ์ ์ฒ๋ฆฌ
|
947 |
+
pdfInput.addEventListener('change', function(e) {
|
948 |
+
console.log("PDF ํ์ผ ์ ํ๋จ:", e.target.files.length);
|
949 |
+
const file = e.target.files[0];
|
950 |
+
if (!file) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
951 |
|
952 |
+
showLoading("PDF ๋ก๋ฉ ์ค...");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
953 |
|
954 |
+
const reader = new FileReader();
|
955 |
+
reader.onload = function(event) {
|
956 |
+
pdfjsLib.getDocument({data: event.target.result}).promise.then(async function(pdf) {
|
957 |
+
const pages = [];
|
958 |
+
|
959 |
+
for (let pageNum = 1; pageNum <= pdf.numPages; pageNum++) {
|
960 |
+
updateLoading(`PDF ํ์ด์ง ๋ก๋ฉ ์ค... (${pageNum}/${pdf.numPages})`);
|
961 |
+
|
962 |
+
const page = await pdf.getPage(pageNum);
|
963 |
+
const viewport = page.getViewport({scale: 1});
|
964 |
+
const canvas = document.createElement('canvas');
|
965 |
+
canvas.width = viewport.width;
|
966 |
+
canvas.height = viewport.height;
|
967 |
+
|
968 |
+
await page.render({
|
969 |
+
canvasContext: canvas.getContext('2d'),
|
970 |
+
viewport: viewport
|
971 |
+
}).promise;
|
972 |
+
|
973 |
+
pages.push({
|
974 |
+
src: canvas.toDataURL(),
|
975 |
+
thumb: canvas.toDataURL()
|
976 |
+
});
|
977 |
+
}
|
978 |
+
|
979 |
+
hideLoading();
|
980 |
+
save(pages, file.name.replace('.pdf', ''));
|
981 |
+
}).catch(function(error) {
|
982 |
+
console.error("PDF ๋ก๋ฉ ์ค๋ฅ:", error);
|
983 |
+
hideLoading();
|
984 |
+
showError("PDF ๋ก๋ฉ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: " + error.message);
|
985 |
+
});
|
986 |
+
};
|
987 |
+
|
988 |
+
reader.onerror = function(error) {
|
989 |
+
console.error("ํ์ผ ์ฝ๊ธฐ ์ค๋ฅ:", error);
|
990 |
+
hideLoading();
|
991 |
+
showError("ํ์ผ์ ์ฝ๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.");
|
992 |
+
};
|
993 |
+
|
994 |
+
reader.readAsArrayBuffer(file);
|
995 |
});
|
996 |
+
} else {
|
997 |
+
console.error("PDF ์
๋ก๋ ์์๋ฅผ ์ฐพ์ ์ ์์");
|
998 |
+
}
|
999 |
+
|
1000 |
+
// ์๋ฒ PDF ๋ก๋ ๋ฐ ์บ์ ์ํ ํ์ธ
|
1001 |
+
loadServerPDFs();
|
1002 |
+
|
1003 |
+
// ์บ์ ์ํ๋ฅผ ์ฃผ๊ธฐ์ ์ผ๋ก ํ์ธ
|
1004 |
+
setInterval(checkCacheStatus, 3000);
|
1005 |
+
});
|
1006 |
|
1007 |
function addCard(i, thumb, title, isCached = false) {
|
1008 |
const d = document.createElement('div');
|
|
|
1031 |
$id('noProjects').style.display = 'none';
|
1032 |
}
|
1033 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1034 |
/* โโ ํ๋ก์ ํธ ์ ์ฅ โโ */
|
1035 |
function save(pages, title, isCached = false){
|
1036 |
const id=projects.push(pages)-1;
|
|
|
1624 |
}
|
1625 |
}, 5000);
|
1626 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1627 |
</script>
|
1628 |
</body>
|
1629 |
</html>
|