Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -602,14 +602,15 @@ HTML_CONTENT = """
|
|
602 |
const historyList = document.getElementById('historyList');
|
603 |
const quickOpenContent = document.getElementById('quickOpenContent');
|
604 |
|
605 |
-
let
|
606 |
|
607 |
fileInput.addEventListener('change', handleFileSelect);
|
608 |
|
609 |
uploadForm.addEventListener('submit', (e) => {
|
610 |
e.preventDefault();
|
611 |
-
|
612 |
-
|
|
|
613 |
}
|
614 |
});
|
615 |
|
@@ -630,25 +631,37 @@ HTML_CONTENT = """
|
|
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 |
-
|
640 |
}
|
641 |
}
|
642 |
-
if (
|
643 |
-
|
|
|
644 |
}
|
645 |
});
|
646 |
|
647 |
-
function generateUniqueFileName(originalName) {
|
648 |
const extension = originalName.split('.').pop();
|
649 |
const baseName = originalName.split('.').slice(0, -1).join('.');
|
650 |
-
|
651 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
652 |
}
|
653 |
|
654 |
span[0].onclick = function() {
|
@@ -691,6 +704,7 @@ HTML_CONTENT = """
|
|
691 |
const fileNames = Array.from(e.target.files).map(file => file.name).join(', ');
|
692 |
fileName.textContent = fileNames;
|
693 |
uploadBtn.style.display = 'inline-block';
|
|
|
694 |
}
|
695 |
}
|
696 |
|
@@ -780,6 +794,7 @@ HTML_CONTENT = """
|
|
780 |
uploadBtn.style.display = 'none';
|
781 |
uploadBtn.disabled = false;
|
782 |
loadingSpinner.style.display = 'none';
|
|
|
783 |
}
|
784 |
|
785 |
function addResultLink(url, fileName, originalExtension) {
|
@@ -858,7 +873,7 @@ HTML_CONTENT = """
|
|
858 |
const historyItem = document.createElement('div');
|
859 |
historyItem.className = 'history-item';
|
860 |
|
861 |
-
|
862 |
itemName.className = 'history-item-name';
|
863 |
itemName.textContent = item.fileName;
|
864 |
historyItem.appendChild(itemName);
|
@@ -870,7 +885,7 @@ HTML_CONTENT = """
|
|
870 |
copyBtn.textContent = 'Copy Link';
|
871 |
copyBtn.className = 'small-btn';
|
872 |
copyBtn.onclick = () => {
|
873 |
-
|
874 |
alert('Link copied to clipboard!');
|
875 |
});
|
876 |
};
|
|
|
602 |
const historyList = document.getElementById('historyList');
|
603 |
const quickOpenContent = document.getElementById('quickOpenContent');
|
604 |
|
605 |
+
let pastedFiles = [];
|
606 |
|
607 |
fileInput.addEventListener('change', handleFileSelect);
|
608 |
|
609 |
uploadForm.addEventListener('submit', (e) => {
|
610 |
e.preventDefault();
|
611 |
+
const filesToUpload = fileInput.files.length > 0 ? fileInput.files : pastedFiles;
|
612 |
+
if (filesToUpload.length > 0) {
|
613 |
+
uploadFiles(filesToUpload);
|
614 |
}
|
615 |
});
|
616 |
|
|
|
631 |
|
632 |
document.addEventListener('paste', (e) => {
|
633 |
const items = e.clipboardData.items;
|
|
|
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, pastedFiles);
|
638 |
const renamedFile = new File([file], newFileName, { type: file.type });
|
639 |
+
pastedFiles.push(renamedFile);
|
640 |
}
|
641 |
}
|
642 |
+
if (pastedFiles.length > 0) {
|
643 |
+
updateFileNameDisplay();
|
644 |
+
uploadBtn.style.display = 'inline-block';
|
645 |
}
|
646 |
});
|
647 |
|
648 |
+
function generateUniqueFileName(originalName, fileList) {
|
649 |
const extension = originalName.split('.').pop();
|
650 |
const baseName = originalName.split('.').slice(0, -1).join('.');
|
651 |
+
let counter = 1;
|
652 |
+
let newName = originalName;
|
653 |
+
|
654 |
+
while (fileList.some(file => file.name === newName)) {
|
655 |
+
newName = `${baseName}${counter}.${extension}`;
|
656 |
+
counter++;
|
657 |
+
}
|
658 |
+
|
659 |
+
return newName;
|
660 |
+
}
|
661 |
+
|
662 |
+
function updateFileNameDisplay() {
|
663 |
+
const fileNames = pastedFiles.map(file => file.name).join(', ');
|
664 |
+
fileName.textContent = fileNames;
|
665 |
}
|
666 |
|
667 |
span[0].onclick = function() {
|
|
|
704 |
const fileNames = Array.from(e.target.files).map(file => file.name).join(', ');
|
705 |
fileName.textContent = fileNames;
|
706 |
uploadBtn.style.display = 'inline-block';
|
707 |
+
pastedFiles = []; // Clear pasted files when new files are selected
|
708 |
}
|
709 |
}
|
710 |
|
|
|
794 |
uploadBtn.style.display = 'none';
|
795 |
uploadBtn.disabled = false;
|
796 |
loadingSpinner.style.display = 'none';
|
797 |
+
pastedFiles = [];
|
798 |
}
|
799 |
|
800 |
function addResultLink(url, fileName, originalExtension) {
|
|
|
873 |
const historyItem = document.createElement('div');
|
874 |
historyItem.className = 'history-item';
|
875 |
|
876 |
+
const itemName = document.createElement('span');
|
877 |
itemName.className = 'history-item-name';
|
878 |
itemName.textContent = item.fileName;
|
879 |
historyItem.appendChild(itemName);
|
|
|
885 |
copyBtn.textContent = 'Copy Link';
|
886 |
copyBtn.className = 'small-btn';
|
887 |
copyBtn.onclick = () => {
|
888 |
+
navigator.clipboard.writeText(window.location.origin + item.url).then(() => {
|
889 |
alert('Link copied to clipboard!');
|
890 |
});
|
891 |
};
|