Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -437,7 +437,7 @@ HTML_CONTENT = """
|
|
| 437 |
overflow: auto;
|
| 438 |
}
|
| 439 |
|
| 440 |
-
|
| 441 |
margin: 5% auto;
|
| 442 |
padding: 20px;
|
| 443 |
width: 90%;
|
|
@@ -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>
|
|
@@ -607,7 +607,7 @@ HTML_CONTENT = """
|
|
| 607 |
uploadForm.addEventListener('submit', (e) => {
|
| 608 |
e.preventDefault();
|
| 609 |
if (fileInput.files.length > 0) {
|
| 610 |
-
|
| 611 |
}
|
| 612 |
});
|
| 613 |
|
|
@@ -674,17 +674,17 @@ HTML_CONTENT = """
|
|
| 674 |
|
| 675 |
function handleFileSelect(e) {
|
| 676 |
if (e.target.files && e.target.files.length > 0) {
|
| 677 |
-
const
|
| 678 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 688 |
progressContainer.innerHTML = '';
|
| 689 |
progressContainer.style.display = 'block';
|
| 690 |
loadingSpinner.style.display = 'block';
|
|
@@ -692,51 +692,40 @@ HTML_CONTENT = """
|
|
| 692 |
resultContainer.innerHTML = '';
|
| 693 |
resultContainer.style.display = 'none';
|
| 694 |
|
| 695 |
-
|
| 696 |
-
|
|
|
|
|
|
|
| 697 |
|
| 698 |
-
|
| 699 |
-
|
| 700 |
|
| 701 |
-
while (true) {
|
| 702 |
try {
|
| 703 |
-
const
|
| 704 |
-
|
| 705 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 735 |
} catch (error) {
|
| 736 |
console.error('Upload error:', error);
|
| 737 |
-
|
| 738 |
}
|
|
|
|
|
|
|
| 739 |
}
|
|
|
|
|
|
|
| 740 |
}
|
| 741 |
|
| 742 |
function createProgressBar(fileName) {
|
|
@@ -881,7 +870,7 @@ HTML_CONTENT = """
|
|
| 881 |
historyModal.style.display = "none";
|
| 882 |
};
|
| 883 |
actionsContainer.appendChild(embedBtn);
|
| 884 |
-
|
| 885 |
|
| 886 |
historyItem.appendChild(actionsContainer);
|
| 887 |
historyList.appendChild(historyItem);
|
|
@@ -898,7 +887,7 @@ HTML_CONTENT = """
|
|
| 898 |
img.src = fullUrl;
|
| 899 |
img.alt = fileName;
|
| 900 |
quickOpenContent.appendChild(img);
|
| 901 |
-
|
| 902 |
const video = document.createElement('video');
|
| 903 |
video.src = fullUrl;
|
| 904 |
video.controls = true;
|
|
@@ -1099,4 +1088,4 @@ async def retry_upload(upload_url: str, file_content: bytes, content_type: str,
|
|
| 1099 |
await asyncio.sleep(delay)
|
| 1100 |
delay = min(delay * 2, 60)
|
| 1101 |
|
| 1102 |
-
return False
|
|
|
|
| 437 |
overflow: auto;
|
| 438 |
}
|
| 439 |
|
| 440 |
+
.quick-open-content {
|
| 441 |
margin: 5% auto;
|
| 442 |
padding: 20px;
|
| 443 |
width: 90%;
|
|
|
|
| 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="*" multiple required>
|
| 541 |
+
<label for="file" class="btn">Choose Files</label>
|
| 542 |
+
<p>or drag and drop files 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 Files</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 |
+
uploadFiles(fileInput.files);
|
| 611 |
}
|
| 612 |
});
|
| 613 |
|
|
|
|
| 674 |
|
| 675 |
function handleFileSelect(e) {
|
| 676 |
if (e.target.files && e.target.files.length > 0) {
|
| 677 |
+
const files = e.target.files;
|
| 678 |
+
let fileNames = [];
|
| 679 |
+
for (let i = 0; i < files.length; i++) {
|
| 680 |
+
fileNames.push(files[i].name);
|
| 681 |
+
}
|
| 682 |
+
fileName.textContent = fileNames.join(', ');
|
| 683 |
uploadBtn.style.display = 'inline-block';
|
|
|
|
|
|
|
|
|
|
|
|
|
| 684 |
}
|
| 685 |
}
|
| 686 |
|
| 687 |
+
async function uploadFiles(files) {
|
| 688 |
progressContainer.innerHTML = '';
|
| 689 |
progressContainer.style.display = 'block';
|
| 690 |
loadingSpinner.style.display = 'block';
|
|
|
|
| 692 |
resultContainer.innerHTML = '';
|
| 693 |
resultContainer.style.display = 'none';
|
| 694 |
|
| 695 |
+
for (let i = 0; i < files.length; i++) {
|
| 696 |
+
const file = files[i];
|
| 697 |
+
const progressBar = createProgressBar(file.name);
|
| 698 |
+
progressContainer.appendChild(progressBar);
|
| 699 |
|
| 700 |
+
const formData = new FormData();
|
| 701 |
+
formData.append('file', file);
|
| 702 |
|
|
|
|
| 703 |
try {
|
| 704 |
+
const response = await fetch('/upload', {
|
| 705 |
+
method: 'POST',
|
| 706 |
+
body: formData
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 707 |
});
|
| 708 |
|
| 709 |
+
if (response.ok) {
|
| 710 |
+
const result = await response.json();
|
| 711 |
+
if (result.url) {
|
| 712 |
+
addResultLink(result.url, file.name, result.originalExtension);
|
| 713 |
+
saveToHistory(file.name, result.url, result.originalExtension);
|
| 714 |
+
} else {
|
| 715 |
+
throw new Error('Upload failed: ' + result.error);
|
| 716 |
+
}
|
| 717 |
+
} else {
|
| 718 |
+
throw new Error(`HTTP error! status: ${response.status}`);
|
| 719 |
+
}
|
| 720 |
} catch (error) {
|
| 721 |
console.error('Upload error:', error);
|
| 722 |
+
alert(`Failed to upload ${file.name}: ${error.message}`);
|
| 723 |
}
|
| 724 |
+
|
| 725 |
+
updateProgress({ loaded: 1, total: 1 }, progressBar.querySelector('.progress'));
|
| 726 |
}
|
| 727 |
+
|
| 728 |
+
resetUploadState();
|
| 729 |
}
|
| 730 |
|
| 731 |
function createProgressBar(fileName) {
|
|
|
|
| 870 |
historyModal.style.display = "none";
|
| 871 |
};
|
| 872 |
actionsContainer.appendChild(embedBtn);
|
| 873 |
+
}
|
| 874 |
|
| 875 |
historyItem.appendChild(actionsContainer);
|
| 876 |
historyList.appendChild(historyItem);
|
|
|
|
| 887 |
img.src = fullUrl;
|
| 888 |
img.alt = fileName;
|
| 889 |
quickOpenContent.appendChild(img);
|
| 890 |
+
} else if (originalExtension.toLowerCase() === 'mp4') {
|
| 891 |
const video = document.createElement('video');
|
| 892 |
video.src = fullUrl;
|
| 893 |
video.controls = true;
|
|
|
|
| 1088 |
await asyncio.sleep(delay)
|
| 1089 |
delay = min(delay * 2, 60)
|
| 1090 |
|
| 1091 |
+
return False
|