coollsd commited on
Commit
cb76d88
·
verified ·
1 Parent(s): 83c084c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -7
app.py CHANGED
@@ -3,7 +3,7 @@ from fastapi.responses import HTMLResponse, JSONResponse, StreamingResponse, Fil
3
  import requests
4
  import time
5
  import asyncio
6
- from typing import Dict, List
7
  import os
8
  import mimetypes
9
 
@@ -425,7 +425,7 @@ HTML_CONTENT = """
425
  gap: 5px;
426
  }
427
 
428
- .quick-open-modal {
429
  display: none;
430
  position: fixed;
431
  z-index: 4;
@@ -437,7 +437,7 @@ HTML_CONTENT = """
437
  overflow: auto;
438
  }
439
 
440
- .quick-open-content {
441
  margin: 5% auto;
442
  padding: 20px;
443
  width: 90%;
@@ -602,6 +602,8 @@ HTML_CONTENT = """
602
  const historyList = document.getElementById('historyList');
603
  const quickOpenContent = document.getElementById('quickOpenContent');
604
 
 
 
605
  fileInput.addEventListener('change', handleFileSelect);
606
 
607
  uploadForm.addEventListener('submit', (e) => {
@@ -628,15 +630,27 @@ HTML_CONTENT = """
628
 
629
  document.addEventListener('paste', (e) => {
630
  const items = e.clipboardData.items;
 
631
  for (let i = 0; i < items.length; i++) {
632
  if (items[i].kind === 'file') {
633
  const file = items[i].getAsFile();
634
- handleFileSelect({ target: { files: [file] } });
635
- break;
 
636
  }
637
  }
 
 
 
638
  });
639
 
 
 
 
 
 
 
 
640
  span[0].onclick = function() {
641
  modal.style.display = "none";
642
  }
@@ -856,7 +870,7 @@ HTML_CONTENT = """
856
  copyBtn.textContent = 'Copy Link';
857
  copyBtn.className = 'small-btn';
858
  copyBtn.onclick = () => {
859
- navigator.clipboard.writeText(window.location.origin + item.url).then(() => {
860
  alert('Link copied to clipboard!');
861
  });
862
  };
@@ -881,7 +895,7 @@ HTML_CONTENT = """
881
  actionsContainer.appendChild(embedBtn);
882
  }
883
 
884
- historyItem.appendChild(actionsContainer);
885
  historyList.appendChild(historyItem);
886
  });
887
  historyModal.style.display = "block";
 
3
  import requests
4
  import time
5
  import asyncio
6
+ from typing import Dict
7
  import os
8
  import mimetypes
9
 
 
425
  gap: 5px;
426
  }
427
 
428
+ .quick-open-modal {
429
  display: none;
430
  position: fixed;
431
  z-index: 4;
 
437
  overflow: auto;
438
  }
439
 
440
+ .quick-open-content {
441
  margin: 5% auto;
442
  padding: 20px;
443
  width: 90%;
 
602
  const historyList = document.getElementById('historyList');
603
  const quickOpenContent = document.getElementById('quickOpenContent');
604
 
605
+ let pastedImageCounter = 0;
606
+
607
  fileInput.addEventListener('change', handleFileSelect);
608
 
609
  uploadForm.addEventListener('submit', (e) => {
 
630
 
631
  document.addEventListener('paste', (e) => {
632
  const items = e.clipboardData.items;
633
+ const files = [];
634
  for (let i = 0; i < items.length; i++) {
635
  if (items[i].kind === 'file') {
636
  const file = items[i].getAsFile();
637
+ const newFileName = generateUniqueFileName(file.name);
638
+ const renamedFile = new File([file], newFileName, { type: file.type });
639
+ files.push(renamedFile);
640
  }
641
  }
642
+ if (files.length > 0) {
643
+ handleFileSelect({ target: { files: files } });
644
+ }
645
  });
646
 
647
+ function generateUniqueFileName(originalName) {
648
+ const extension = originalName.split('.').pop();
649
+ const baseName = originalName.split('.').slice(0, -1).join('.');
650
+ pastedImageCounter++;
651
+ return `${baseName}${pastedImageCounter}.${extension}`;
652
+ }
653
+
654
  span[0].onclick = function() {
655
  modal.style.display = "none";
656
  }
 
870
  copyBtn.textContent = 'Copy Link';
871
  copyBtn.className = 'small-btn';
872
  copyBtn.onclick = () => {
873
+ navigator.clipboard.writeText(window.location.origin + item.url).then(() => {
874
  alert('Link copied to clipboard!');
875
  });
876
  };
 
895
  actionsContainer.appendChild(embedBtn);
896
  }
897
 
898
+ historyItem.appendChild(actionsContainer);
899
  historyList.appendChild(historyItem);
900
  });
901
  historyModal.style.display = "block";