ginipick commited on
Commit
722e2a8
Β·
verified Β·
1 Parent(s): d98ef41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +156 -116
app.py CHANGED
@@ -884,16 +884,18 @@ HTML = """
884
 
885
  <section id="home" class="fade-in">
886
  <div class="upload-container">
887
- <button class="upload" id="imageUploadBtn">
888
  <i class="fas fa-images"></i> 이미지 μΆ”κ°€
889
- <input id="imgInput" type="file" accept="image/*" multiple hidden>
890
  </button>
891
- <button class="upload" id="pdfUploadBtn">
892
  <i class="fas fa-file-pdf"></i> PDF μΆ”κ°€
893
- <input id="pdfInput" type="file" accept="application/pdf" hidden>
894
  </button>
895
  </div>
896
 
 
 
 
 
897
  <div class="section-title">λ‚΄ ν”„λ‘œμ νŠΈ</div>
898
  <div class="grid" id="grid">
899
  <!-- μΉ΄λ“œκ°€ 여기에 λ™μ μœΌλ‘œ μΆ”κ°€λ©λ‹ˆλ‹€ -->
@@ -926,54 +928,161 @@ HTML = """
926
  .play().then(a=>a.pause()).catch(()=>{});document.removeEventListener(evt,u,{capture:true});},
927
  {once:true,capture:true});
928
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
929
 
930
- // μ—…λ‘œλ“œ λ²„νŠΌ 이벀트 μ—°κ²° ν•¨μˆ˜
931
- function setupUploadButtons() {
932
- // λͺ¨λ“  μ—…λ‘œλ“œ λ²„νŠΌμ— 이벀트 λ¦¬μŠ€λ„ˆ μΆ”κ°€
933
- document.querySelectorAll('.upload').forEach(button => {
934
- button.addEventListener('click', function(e) {
935
- // λ²„νŠΌ λ‚΄λΆ€μ˜ input μš”μ†Œ μ°ΎκΈ°
936
- const inputElement = this.querySelector('input[type="file"]');
937
- if (inputElement) {
938
- // input μš”μ†Œ 클릭 (파일 선택 λ‹€μ΄μ–Όλ‘œκ·Έ μ—΄κΈ°)
939
- inputElement.click();
940
- e.preventDefault(); // λ²„νŠΌ κΈ°λ³Έ λ™μž‘ λ°©μ§€
 
 
 
 
 
 
 
 
 
 
 
 
941
  }
942
- });
 
943
  });
944
  }
945
-
946
- /* ── μœ ν‹Έ ── */
947
- function $id(id){return document.getElementById(id)}
948
 
949
- // 직접 이벀트 λ¦¬μŠ€λ„ˆ μ„€μ • (더 ν™•μ‹€ν•œ 방법)
950
- function setupDirectEvents() {
951
- // 이미지 μ—…λ‘œλ“œ λ²„νŠΌ
952
- const imageBtn = $id('imageUploadBtn');
953
- const imageInput = $id('imgInput');
954
- if (imageBtn && imageInput) {
955
- console.log('이미지 μ—…λ‘œλ“œ λ²„νŠΌ 이벀트 μ„€μ •');
956
- imageBtn.onclick = function(e) {
957
- e.preventDefault();
958
- e.stopPropagation();
959
- imageInput.click();
960
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
961
  }
 
962
 
963
- // PDF μ—…λ‘œλ“œ λ²„νŠΌ
964
- const pdfBtn = $id('pdfUploadBtn');
965
- const pdfInput = $id('pdfInput');
966
- if (pdfBtn && pdfInput) {
967
- console.log('PDF μ—…λ‘œλ“œ λ²„νŠΌ 이벀트 μ„€μ •');
968
- pdfBtn.onclick = function(e) {
969
- e.preventDefault();
970
- e.stopPropagation();
971
- pdfInput.click();
972
- };
973
  }
 
 
974
  }
975
-
976
- function addCard(i, thumb, title, isCached = false) {
977
  const d = document.createElement('div');
978
  d.className = 'card fade-in';
979
  d.onclick = () => open(i);
@@ -1000,53 +1109,8 @@ HTML = """
1000
  $id('noProjects').style.display = 'none';
1001
  }
1002
 
1003
- /* ── 이미지 μ—…λ‘œλ“œ ── */
1004
- $id('imgInput').onchange=e=>{
1005
- const files=[...e.target.files]; if(!files.length) return;
1006
-
1007
- // λ‘œλ”© ν‘œμ‹œ μΆ”κ°€
1008
- showLoading("이미지 λ‘œλ”© 쀑...");
1009
-
1010
- const pages=[],tot=files.length;let done=0;
1011
- files.forEach((f,i)=>{const r=new FileReader();r.onload=x=>{pages[i]={src:x.target.result,thumb:x.target.result};
1012
- if(++done===tot) {
1013
- save(pages, '이미지 μ»¬λ ‰μ…˜');
1014
- hideLoading();
1015
- }
1016
- };r.readAsDataURL(f);});
1017
- };
1018
-
1019
- /* ── PDF μ—…λ‘œλ“œ ── */
1020
- $id('pdfInput').onchange=e=>{
1021
- const file=e.target.files[0]; if(!file) return;
1022
-
1023
- // λ‘œλ”© ν‘œμ‹œ μΆ”κ°€
1024
- showLoading("PDF λ‘œλ”© 쀑...");
1025
-
1026
- const fr=new FileReader();
1027
- fr.onload=v=>{
1028
- pdfjsLib.getDocument({data:v.target.result}).promise.then(async pdf=>{
1029
- const pages=[];
1030
-
1031
- for(let p=1;p<=pdf.numPages;p++){
1032
- // λ‘œλ”© μƒνƒœ μ—…λ°μ΄νŠΈ
1033
- updateLoading(`PDF νŽ˜μ΄μ§€ λ‘œλ”© 쀑... (${p}/${pdf.numPages})`);
1034
-
1035
- const pg=await pdf.getPage(p), vp=pg.getViewport({scale:1});
1036
- const c=document.createElement('canvas');c.width=vp.width;c.height=vp.height;
1037
- await pg.render({canvasContext:c.getContext('2d'),viewport:vp}).promise;
1038
- pages.push({src:c.toDataURL(),thumb:c.toDataURL()});
1039
- }
1040
-
1041
- hideLoading();
1042
- save(pages, file.name.replace('.pdf', ''));
1043
- }).catch(error => {
1044
- console.error("PDF λ‘œλ”© 였λ₯˜:", error);
1045
- hideLoading();
1046
- showError("PDF λ‘œλ”© 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€.");
1047
- });
1048
- };fr.readAsArrayBuffer(file);
1049
- };
1050
 
1051
  /* ── ν”„λ‘œμ νŠΈ μ €μž₯ ── */
1052
  function save(pages, title, isCached = false){
@@ -1524,22 +1588,7 @@ HTML = """
1524
  }
1525
 
1526
  /* ── λ„€λΉ„κ²Œμ΄μ…˜ ── */
1527
- $id('homeButton').onclick=()=>{
1528
- if(fb) {
1529
- fb.destroy();
1530
- viewer.innerHTML = '';
1531
- fb = null;
1532
- }
1533
- toggle(true);
1534
-
1535
- // λ‘œλ”© 인디케이터 정리
1536
- if (pageLoadingInterval) {
1537
- clearInterval(pageLoadingInterval);
1538
- pageLoadingInterval = null;
1539
- }
1540
- $id('loadingPages').style.display = 'none';
1541
- currentLoadingPdfPath = null;
1542
- };
1543
 
1544
  function toggle(showHome){
1545
  $id('home').style.display=showHome?'block':'none';
@@ -1642,16 +1691,7 @@ HTML = """
1642
  }, 5000);
1643
  }
1644
 
1645
- // νŽ˜μ΄μ§€ λ‘œλ“œ μ‹œ μ„œλ²„ PDF λ‘œλ“œ
1646
- window.addEventListener('DOMContentLoaded', () => {
1647
- // 직접 이벀트 λ¦¬μŠ€λ„ˆ μ„€μ • (더 ν™•μ‹€ν•œ 방법)
1648
- setupDirectEvents();
1649
-
1650
- loadServerPDFs();
1651
-
1652
- // μΊμ‹œ μƒνƒœλ₯Ό 주기적으둜 확인 (3μ΄ˆλ§ˆλ‹€)
1653
- setInterval(checkCacheStatus, 3000);
1654
- });
1655
  </script>
1656
  </body>
1657
  </html>
 
884
 
885
  <section id="home" class="fade-in">
886
  <div class="upload-container">
887
+ <button type="button" id="imageUploadBtn" class="upload">
888
  <i class="fas fa-images"></i> 이미지 μΆ”κ°€
 
889
  </button>
890
+ <button type="button" id="pdfUploadBtn" class="upload">
891
  <i class="fas fa-file-pdf"></i> PDF μΆ”κ°€
 
892
  </button>
893
  </div>
894
 
895
+ <!-- 파일 μž…λ ₯ μš”μ†Œλ₯Ό λ²„νŠΌ λ°–μœΌλ‘œ μ΄λ™ν•˜μ—¬ 별도 배치 -->
896
+ <input id="imgInput" type="file" accept="image/*" multiple style="display:none">
897
+ <input id="pdfInput" type="file" accept="application/pdf" style="display:none">
898
+
899
  <div class="section-title">λ‚΄ ν”„λ‘œμ νŠΈ</div>
900
  <div class="grid" id="grid">
901
  <!-- μΉ΄λ“œκ°€ 여기에 λ™μ μœΌλ‘œ μΆ”κ°€λ©λ‹ˆλ‹€ -->
 
928
  .play().then(a=>a.pause()).catch(()=>{});document.removeEventListener(evt,u,{capture:true});},
929
  {once:true,capture:true});
930
  });
931
+
932
+ // νŽ˜μ΄μ§€ λ‘œλ“œ μ‹œ 이벀트 μ„€μ •
933
+ document.addEventListener('DOMContentLoaded', function() {
934
+ console.log('DOM Content Loaded - 이벀트 μ„€μ • μ‹œμž‘');
935
+
936
+ // 이미지 μ—…λ‘œλ“œ λ²„νŠΌ 이벀트
937
+ var imageUploadBtn = document.getElementById('imageUploadBtn');
938
+ var imgInput = document.getElementById('imgInput');
939
+
940
+ if (imageUploadBtn && imgInput) {
941
+ console.log('이미지 μ—…λ‘œλ“œ λ²„νŠΌ 발견');
942
+ imageUploadBtn.addEventListener('click', function() {
943
+ console.log('이미지 μ—…λ‘œλ“œ λ²„νŠΌ 클릭됨');
944
+ imgInput.click();
945
+ });
946
+ } else {
947
+ console.error('이미지 μ—…λ‘œλ“œ λ²„νŠΌ λ˜λŠ” μž…λ ₯ μš”μ†Œλ₯Ό 찾을 수 μ—†μŒ');
948
+ }
949
+
950
+ // PDF μ—…λ‘œλ“œ λ²„νŠΌ 이벀트
951
+ var pdfUploadBtn = document.getElementById('pdfUploadBtn');
952
+ var pdfInput = document.getElementById('pdfInput');
953
+
954
+ if (pdfUploadBtn && pdfInput) {
955
+ console.log('PDF μ—…λ‘œλ“œ λ²„νŠΌ 발견');
956
+ pdfUploadBtn.addEventListener('click', function() {
957
+ console.log('PDF μ—…λ‘œλ“œ λ²„νŠΌ 클릭됨');
958
+ pdfInput.click();
959
+ });
960
+ } else {
961
+ console.error('PDF μ—…λ‘œλ“œ λ²„νŠΌ λ˜λŠ” μž…λ ₯ μš”μ†Œλ₯Ό 찾을 수 μ—†μŒ');
962
+ }
963
+
964
+ console.log('PDF/이미지 μž…λ ₯ ν•„λ“œ 이벀트 μ„€μ •');
965
+ if (imgInput) {
966
+ imgInput.addEventListener('change', function(e) {
967
+ console.log('이미지 μž…λ ₯ λ³€κ²½ 감지됨');
968
+ handleImageUpload(e);
969
+ });
970
+ }
971
+
972
+ if (pdfInput) {
973
+ pdfInput.addEventListener('change', function(e) {
974
+ console.log('PDF μž…λ ₯ λ³€κ²½ 감지됨');
975
+ handlePdfUpload(e);
976
+ });
977
+ }
978
+
979
+ // ν™ˆ λ²„νŠΌ 이벀트 μ„€μ •
980
+ var homeButton = document.getElementById('homeButton');
981
+ if (homeButton) {
982
+ homeButton.addEventListener('click', function() {
983
+ console.log('ν™ˆ λ²„νŠΌ 클릭됨');
984
+ homeButtonClicked();
985
+ });
986
+ }
987
+
988
+ // μ„œλ²„μ—μ„œ PDF λ‘œλ“œ
989
+ loadServerPDFs();
990
+
991
+ // μΊμ‹œ μƒνƒœ 주기적 확인
992
+ setInterval(checkCacheStatus, 3000);
993
+ });
994
 
995
+ // 이미지 μ—…λ‘œλ“œ 처리 ν•¨μˆ˜
996
+ function handleImageUpload(e) {
997
+ const files = Array.from(e.target.files);
998
+ if (!files.length) return;
999
+
1000
+ // λ‘œλ”© ν‘œμ‹œ μΆ”κ°€
1001
+ showLoading("이미지 λ‘œλ”© 쀑...");
1002
+
1003
+ const pages = [];
1004
+ let done = 0;
1005
+ const total = files.length;
1006
+
1007
+ files.forEach((file, index) => {
1008
+ const reader = new FileReader();
1009
+ reader.onload = function(event) {
1010
+ pages[index] = {
1011
+ src: event.target.result,
1012
+ thumb: event.target.result
1013
+ };
1014
+ done++;
1015
+ if (done === total) {
1016
+ save(pages, '이미지 μ»¬λ ‰μ…˜');
1017
+ hideLoading();
1018
  }
1019
+ };
1020
+ reader.readAsDataURL(file);
1021
  });
1022
  }
 
 
 
1023
 
1024
+ // PDF μ—…λ‘œλ“œ 처리 ν•¨μˆ˜
1025
+ function handlePdfUpload(e) {
1026
+ const file = e.target.files[0];
1027
+ if (!file) return;
1028
+
1029
+ // λ‘œλ”© ν‘œμ‹œ μΆ”κ°€
1030
+ showLoading("PDF λ‘œλ”© 쀑...");
1031
+
1032
+ const reader = new FileReader();
1033
+ reader.onload = function(event) {
1034
+ pdfjsLib.getDocument({data: event.target.result}).promise.then(async pdf => {
1035
+ const pages = [];
1036
+
1037
+ for (let p = 1; p <= pdf.numPages; p++) {
1038
+ // λ‘œλ”© μƒνƒœ μ—…λ°μ΄νŠΈ
1039
+ updateLoading(`PDF νŽ˜μ΄μ§€ λ‘œλ”© 쀑... (${p}/${pdf.numPages})`);
1040
+
1041
+ const page = await pdf.getPage(p);
1042
+ const viewport = page.getViewport({scale: 1});
1043
+ const canvas = document.createElement('canvas');
1044
+ canvas.width = viewport.width;
1045
+ canvas.height = viewport.height;
1046
+
1047
+ await page.render({
1048
+ canvasContext: canvas.getContext('2d'),
1049
+ viewport: viewport
1050
+ }).promise;
1051
+
1052
+ pages.push({
1053
+ src: canvas.toDataURL(),
1054
+ thumb: canvas.toDataURL()
1055
+ });
1056
+ }
1057
+
1058
+ hideLoading();
1059
+ save(pages, file.name.replace('.pdf', ''));
1060
+ }).catch(error => {
1061
+ console.error("PDF λ‘œλ”© 였λ₯˜:", error);
1062
+ hideLoading();
1063
+ showError("PDF λ‘œλ”© 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€.");
1064
+ });
1065
+ };
1066
+ reader.readAsArrayBuffer(file);
1067
+ }
1068
+
1069
+ // ν™ˆ λ²„νŠΌ 클릭 처리 ν•¨μˆ˜
1070
+ function homeButtonClicked() {
1071
+ if (fb) {
1072
+ fb.destroy();
1073
+ viewer.innerHTML = '';
1074
+ fb = null;
1075
  }
1076
+ toggle(true);
1077
 
1078
+ // λ‘œλ”© 인디케이터 정리
1079
+ if (pageLoadingInterval) {
1080
+ clearInterval(pageLoadingInterval);
1081
+ pageLoadingInterval = null;
 
 
 
 
 
 
1082
  }
1083
+ document.getElementById('loadingPages').style.display = 'none';
1084
+ currentLoadingPdfPath = null;
1085
  }
 
 
1086
  const d = document.createElement('div');
1087
  d.className = 'card fade-in';
1088
  d.onclick = () => open(i);
 
1109
  $id('noProjects').style.display = 'none';
1110
  }
1111
 
1112
+ /* ── μœ ν‹Έ ── */
1113
+ function $id(id){return document.getElementById(id)}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1114
 
1115
  /* ── ν”„λ‘œμ νŠΈ μ €μž₯ ── */
1116
  function save(pages, title, isCached = false){
 
1588
  }
1589
 
1590
  /* ── λ„€λΉ„κ²Œμ΄μ…˜ ── */
1591
+ $id('homeButton').onclick=homeButtonClicked;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1592
 
1593
  function toggle(showHome){
1594
  $id('home').style.display=showHome?'block':'none';
 
1691
  }, 5000);
1692
  }
1693
 
1694
+ function addCard(i, thumb, title, isCached = false) {
 
 
 
 
 
 
 
 
 
1695
  </script>
1696
  </body>
1697
  </html>