Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -425,7 +425,7 @@ HTML_CONTENT = """
|
|
425 |
gap: 5px;
|
426 |
}
|
427 |
|
428 |
-
|
429 |
display: none;
|
430 |
position: fixed;
|
431 |
z-index: 4;
|
@@ -445,7 +445,7 @@ HTML_CONTENT = """
|
|
445 |
text-align: center;
|
446 |
}
|
447 |
|
448 |
-
|
449 |
.quick-open-content video,
|
450 |
.quick-open-content audio {
|
451 |
max-width: 100%;
|
@@ -537,12 +537,12 @@ HTML_CONTENT = """
|
|
537 |
<h1>Radd PRO Uploader</h1>
|
538 |
<form id="uploadForm">
|
539 |
<div id="dropZone" class="drop-zone">
|
540 |
-
<input type="file" name="file" id="file" class="file-input" accept="*" required
|
541 |
-
<label for="file" class="btn">Choose
|
542 |
-
<p>or drag and drop
|
543 |
</div>
|
544 |
<div class="file-name" id="fileName"></div>
|
545 |
-
<button type="submit" id="uploadBtn" class="btn" style="display: none; margin-top: 1rem;">Upload
|
546 |
<div class="progress-container" id="progressContainer"></div>
|
547 |
<div class="loading-spinner" id="loadingSpinner"></div>
|
548 |
</form>
|
@@ -602,14 +602,12 @@ HTML_CONTENT = """
|
|
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) => {
|
610 |
e.preventDefault();
|
611 |
if (fileInput.files.length > 0) {
|
612 |
-
|
613 |
}
|
614 |
});
|
615 |
|
@@ -630,27 +628,15 @@ 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 |
-
|
638 |
-
|
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 |
}
|
@@ -688,13 +674,17 @@ HTML_CONTENT = """
|
|
688 |
|
689 |
function handleFileSelect(e) {
|
690 |
if (e.target.files && e.target.files.length > 0) {
|
691 |
-
const
|
692 |
-
fileName.textContent =
|
693 |
uploadBtn.style.display = 'inline-block';
|
|
|
|
|
|
|
|
|
694 |
}
|
695 |
}
|
696 |
|
697 |
-
async function
|
698 |
progressContainer.innerHTML = '';
|
699 |
progressContainer.style.display = 'block';
|
700 |
loadingSpinner.style.display = 'block';
|
@@ -702,53 +692,51 @@ HTML_CONTENT = """
|
|
702 |
resultContainer.innerHTML = '';
|
703 |
resultContainer.style.display = 'none';
|
704 |
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
xhr.
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
throw new Error('Upload failed: ' + response.error);
|
726 |
-
}
|
727 |
} else {
|
728 |
-
throw new Error(
|
729 |
}
|
730 |
-
}
|
|
|
|
|
|
|
731 |
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
|
736 |
-
|
737 |
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
}
|
748 |
}
|
749 |
}
|
750 |
-
|
751 |
-
resetUploadState();
|
752 |
}
|
753 |
|
754 |
function createProgressBar(fileName) {
|
@@ -870,7 +858,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 |
};
|
@@ -901,7 +889,7 @@ HTML_CONTENT = """
|
|
901 |
historyModal.style.display = "block";
|
902 |
}
|
903 |
|
904 |
-
|
905 |
quickOpenContent.innerHTML = '';
|
906 |
const fullUrl = window.location.origin + url;
|
907 |
|
|
|
425 |
gap: 5px;
|
426 |
}
|
427 |
|
428 |
+
.quick-open-modal {
|
429 |
display: none;
|
430 |
position: fixed;
|
431 |
z-index: 4;
|
|
|
445 |
text-align: center;
|
446 |
}
|
447 |
|
448 |
+
.quick-open-content img,
|
449 |
.quick-open-content video,
|
450 |
.quick-open-content audio {
|
451 |
max-width: 100%;
|
|
|
537 |
<h1>Radd PRO Uploader</h1>
|
538 |
<form id="uploadForm">
|
539 |
<div id="dropZone" class="drop-zone">
|
540 |
+
<input type="file" name="file" id="file" class="file-input" accept="*" required>
|
541 |
+
<label for="file" class="btn">Choose File</label>
|
542 |
+
<p>or drag and drop file here/paste image</p>
|
543 |
</div>
|
544 |
<div class="file-name" id="fileName"></div>
|
545 |
+
<button type="submit" id="uploadBtn" class="btn" style="display: none; margin-top: 1rem;">Upload File</button>
|
546 |
<div class="progress-container" id="progressContainer"></div>
|
547 |
<div class="loading-spinner" id="loadingSpinner"></div>
|
548 |
</form>
|
|
|
602 |
const historyList = document.getElementById('historyList');
|
603 |
const quickOpenContent = document.getElementById('quickOpenContent');
|
604 |
|
|
|
|
|
605 |
fileInput.addEventListener('change', handleFileSelect);
|
606 |
|
607 |
uploadForm.addEventListener('submit', (e) => {
|
608 |
e.preventDefault();
|
609 |
if (fileInput.files.length > 0) {
|
610 |
+
uploadFile(fileInput.files[0]);
|
611 |
}
|
612 |
});
|
613 |
|
|
|
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 |
}
|
|
|
674 |
|
675 |
function handleFileSelect(e) {
|
676 |
if (e.target.files && e.target.files.length > 0) {
|
677 |
+
const file = e.target.files[0];
|
678 |
+
fileName.textContent = file.name;
|
679 |
uploadBtn.style.display = 'inline-block';
|
680 |
+
|
681 |
+
const dataTransfer = new DataTransfer();
|
682 |
+
dataTransfer.items.add(file);
|
683 |
+
fileInput.files = dataTransfer.files;
|
684 |
}
|
685 |
}
|
686 |
|
687 |
+
async function uploadFile(file) {
|
688 |
progressContainer.innerHTML = '';
|
689 |
progressContainer.style.display = 'block';
|
690 |
loadingSpinner.style.display = 'block';
|
|
|
692 |
resultContainer.innerHTML = '';
|
693 |
resultContainer.style.display = 'none';
|
694 |
|
695 |
+
const progressBar = createProgressBar(file.name);
|
696 |
+
progressContainer.appendChild(progressBar);
|
697 |
+
|
698 |
+
const formData = new FormData();
|
699 |
+
formData.append('file', file);
|
700 |
+
|
701 |
+
while (true) {
|
702 |
+
try {
|
703 |
+
const xhr = new XMLHttpRequest();
|
704 |
+
xhr.open('POST', '/upload', true);
|
705 |
+
xhr.upload.onprogress = (event) => updateProgress(event, progressBar.querySelector('.progress'));
|
706 |
+
|
707 |
+
xhr.onload = function() {
|
708 |
+
if (xhr.status === 200) {
|
709 |
+
const response = JSON.parse(xhr.responseText);
|
710 |
+
if (response.url) {
|
711 |
+
addResultLink(response.url, file.name, response.originalExtension);
|
712 |
+
saveToHistory(file.name, response.url, response.originalExtension);
|
713 |
+
resetUploadState();
|
714 |
+
return;
|
|
|
|
|
715 |
} else {
|
716 |
+
throw new Error('Upload failed: ' + response.error);
|
717 |
}
|
718 |
+
} else {
|
719 |
+
throw new Error(`HTTP error! status: ${xhr.status}`);
|
720 |
+
}
|
721 |
+
};
|
722 |
|
723 |
+
xhr.onerror = function() {
|
724 |
+
throw new Error('Network error occurred');
|
725 |
+
};
|
726 |
|
727 |
+
xhr.send(formData);
|
728 |
|
729 |
+
await new Promise((resolve, reject) => {
|
730 |
+
xhr.onloadend = resolve;
|
731 |
+
xhr.onerror = reject;
|
732 |
+
});
|
733 |
|
734 |
+
break;
|
735 |
+
} catch (error) {
|
736 |
+
console.error('Upload error:', error);
|
737 |
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
|
738 |
}
|
739 |
}
|
|
|
|
|
740 |
}
|
741 |
|
742 |
function createProgressBar(fileName) {
|
|
|
858 |
copyBtn.textContent = 'Copy Link';
|
859 |
copyBtn.className = 'small-btn';
|
860 |
copyBtn.onclick = () => {
|
861 |
+
navigator.clipboard.writeText(window.location.origin + item.url).then(() => {
|
862 |
alert('Link copied to clipboard!');
|
863 |
});
|
864 |
};
|
|
|
889 |
historyModal.style.display = "block";
|
890 |
}
|
891 |
|
892 |
+
function quickOpen(url, fileName, originalExtension) {
|
893 |
quickOpenContent.innerHTML = '';
|
894 |
const fullUrl = window.location.origin + url;
|
895 |
|