Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -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="*"
|
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>
|
@@ -607,7 +607,7 @@ HTML_CONTENT = """
|
|
607 |
uploadForm.addEventListener('submit', (e) => {
|
608 |
e.preventDefault();
|
609 |
if (fileInput.files.length > 0) {
|
610 |
-
|
611 |
}
|
612 |
});
|
613 |
|
@@ -627,15 +627,11 @@ HTML_CONTENT = """
|
|
627 |
});
|
628 |
|
629 |
document.addEventListener('paste', (e) => {
|
630 |
-
e.preventDefault();
|
631 |
const items = e.clipboardData.items;
|
632 |
for (let i = 0; i < items.length; i++) {
|
633 |
if (items[i].kind === 'file') {
|
634 |
const file = items[i].getAsFile();
|
635 |
-
|
636 |
-
dT.items.add(file);
|
637 |
-
fileInput.files = dT.files;
|
638 |
-
handleFileSelect({ target: { files: dT.files } });
|
639 |
break;
|
640 |
}
|
641 |
}
|
@@ -678,17 +674,17 @@ HTML_CONTENT = """
|
|
678 |
|
679 |
function handleFileSelect(e) {
|
680 |
if (e.target.files && e.target.files.length > 0) {
|
681 |
-
const
|
682 |
-
|
683 |
-
for (let i = 0; i < files.length; i++) {
|
684 |
-
fileNames.push(files[i].name);
|
685 |
-
}
|
686 |
-
fileName.textContent = fileNames.join(', ');
|
687 |
uploadBtn.style.display = 'inline-block';
|
|
|
|
|
|
|
|
|
688 |
}
|
689 |
}
|
690 |
|
691 |
-
async function
|
692 |
progressContainer.innerHTML = '';
|
693 |
progressContainer.style.display = 'block';
|
694 |
loadingSpinner.style.display = 'block';
|
@@ -696,14 +692,13 @@ HTML_CONTENT = """
|
|
696 |
resultContainer.innerHTML = '';
|
697 |
resultContainer.style.display = 'none';
|
698 |
|
699 |
-
|
700 |
-
|
701 |
-
const progressBar = createProgressBar(file.name);
|
702 |
-
progressContainer.appendChild(progressBar);
|
703 |
|
704 |
-
|
705 |
-
|
706 |
|
|
|
707 |
try {
|
708 |
const xhr = new XMLHttpRequest();
|
709 |
xhr.open('POST', '/upload', true);
|
@@ -715,6 +710,8 @@ HTML_CONTENT = """
|
|
715 |
if (response.url) {
|
716 |
addResultLink(response.url, file.name, response.originalExtension);
|
717 |
saveToHistory(file.name, response.url, response.originalExtension);
|
|
|
|
|
718 |
} else {
|
719 |
throw new Error('Upload failed: ' + response.error);
|
720 |
}
|
@@ -733,13 +730,13 @@ HTML_CONTENT = """
|
|
733 |
xhr.onloadend = resolve;
|
734 |
xhr.onerror = reject;
|
735 |
});
|
|
|
|
|
736 |
} catch (error) {
|
737 |
console.error('Upload error:', error);
|
738 |
-
|
739 |
}
|
740 |
}
|
741 |
-
|
742 |
-
resetUploadState();
|
743 |
}
|
744 |
|
745 |
function createProgressBar(fileName) {
|
@@ -886,13 +883,13 @@ HTML_CONTENT = """
|
|
886 |
actionsContainer.appendChild(embedBtn);
|
887 |
}
|
888 |
|
889 |
-
|
890 |
historyList.appendChild(historyItem);
|
891 |
});
|
892 |
historyModal.style.display = "block";
|
893 |
}
|
894 |
|
895 |
-
|
896 |
quickOpenContent.innerHTML = '';
|
897 |
const fullUrl = window.location.origin + url;
|
898 |
|
|
|
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>
|
|
|
607 |
uploadForm.addEventListener('submit', (e) => {
|
608 |
e.preventDefault();
|
609 |
if (fileInput.files.length > 0) {
|
610 |
+
uploadFile(fileInput.files[0]);
|
611 |
}
|
612 |
});
|
613 |
|
|
|
627 |
});
|
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 |
}
|
|
|
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);
|
|
|
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 |
}
|
|
|
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) {
|
|
|
883 |
actionsContainer.appendChild(embedBtn);
|
884 |
}
|
885 |
|
886 |
+
historyItem.appendChild(actionsContainer);
|
887 |
historyList.appendChild(historyItem);
|
888 |
});
|
889 |
historyModal.style.display = "block";
|
890 |
}
|
891 |
|
892 |
+
function quickOpen(url, fileName, originalExtension) {
|
893 |
quickOpenContent.innerHTML = '';
|
894 |
const fullUrl = window.location.origin + url;
|
895 |
|