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%;
|
|
@@ -698,29 +698,11 @@ HTML_CONTENT = """
|
|
| 698 |
const formData = new FormData();
|
| 699 |
formData.append('file', file);
|
| 700 |
|
| 701 |
-
const startTime = Date.now();
|
| 702 |
-
let lastUpdateTime = startTime;
|
| 703 |
-
let lastLoaded = 0;
|
| 704 |
-
|
| 705 |
while (true) {
|
| 706 |
try {
|
| 707 |
const xhr = new XMLHttpRequest();
|
| 708 |
xhr.open('POST', '/upload', true);
|
| 709 |
-
xhr.upload.onprogress = (event) =>
|
| 710 |
-
const currentTime = Date.now();
|
| 711 |
-
const elapsedTime = (currentTime - startTime) / 1000; // in seconds
|
| 712 |
-
const loadedSinceLastUpdate = event.loaded - lastLoaded;
|
| 713 |
-
const timeSinceLastUpdate = (currentTime - lastUpdateTime) / 1000; // in seconds
|
| 714 |
-
|
| 715 |
-
const uploadSpeed = loadedSinceLastUpdate / timeSinceLastUpdate; // bytes per second
|
| 716 |
-
const remainingBytes = event.total - event.loaded;
|
| 717 |
-
const estimatedTimeRemaining = remainingBytes / uploadSpeed;
|
| 718 |
-
|
| 719 |
-
updateProgress(event, progressBar.querySelector('.progress'), elapsedTime, estimatedTimeRemaining);
|
| 720 |
-
|
| 721 |
-
lastUpdateTime = currentTime;
|
| 722 |
-
lastLoaded = event.loaded;
|
| 723 |
-
};
|
| 724 |
|
| 725 |
xhr.onload = function() {
|
| 726 |
if (xhr.status === 200) {
|
|
@@ -767,34 +749,16 @@ HTML_CONTENT = """
|
|
| 767 |
label.textContent = fileName;
|
| 768 |
label.style.fontSize = '0.8rem';
|
| 769 |
label.style.marginBottom = '5px';
|
| 770 |
-
const timeEstimate = document.createElement('div');
|
| 771 |
-
timeEstimate.id = 'timeEstimate';
|
| 772 |
-
timeEstimate.style.fontSize = '0.8rem';
|
| 773 |
-
timeEstimate.style.marginTop = '5px';
|
| 774 |
const container = document.createElement('div');
|
| 775 |
container.appendChild(label);
|
| 776 |
container.appendChild(progressBarContainer);
|
| 777 |
-
container.appendChild(timeEstimate);
|
| 778 |
return container;
|
| 779 |
}
|
| 780 |
|
| 781 |
-
function updateProgress(event, progressBar
|
| 782 |
if (event.lengthComputable) {
|
| 783 |
const percentComplete = (event.loaded / event.total) * 100;
|
| 784 |
progressBar.style.width = percentComplete + '%';
|
| 785 |
-
|
| 786 |
-
const timeEstimate = document.getElementById('timeEstimate');
|
| 787 |
-
timeEstimate.textContent = `${percentComplete.toFixed(1)}% - ${formatTime(elapsedTime)} elapsed, ${formatTime(estimatedTimeRemaining)} remaining`;
|
| 788 |
-
}
|
| 789 |
-
}
|
| 790 |
-
|
| 791 |
-
function formatTime(seconds) {
|
| 792 |
-
if (seconds < 60) {
|
| 793 |
-
return `${Math.round(seconds)} seconds`;
|
| 794 |
-
} else if (seconds < 3600) {
|
| 795 |
-
return `${Math.round(seconds / 60)} minutes`;
|
| 796 |
-
} else {
|
| 797 |
-
return `${Math.round(seconds / 3600)} hours`;
|
| 798 |
}
|
| 799 |
}
|
| 800 |
|
|
@@ -875,7 +839,7 @@ HTML_CONTENT = """
|
|
| 875 |
localStorage.setItem('uploadHistory', JSON.stringify(history));
|
| 876 |
}
|
| 877 |
|
| 878 |
-
|
| 879 |
const history = JSON.parse(localStorage.getItem('uploadHistory')) || [];
|
| 880 |
historyList.innerHTML = '';
|
| 881 |
history.forEach(item => {
|
|
@@ -925,7 +889,7 @@ HTML_CONTENT = """
|
|
| 925 |
historyModal.style.display = "block";
|
| 926 |
}
|
| 927 |
|
| 928 |
-
|
| 929 |
quickOpenContent.innerHTML = '';
|
| 930 |
const fullUrl = window.location.origin + url;
|
| 931 |
|
|
@@ -1135,4 +1099,4 @@ async def retry_upload(upload_url: str, file_content: bytes, content_type: str,
|
|
| 1135 |
await asyncio.sleep(delay)
|
| 1136 |
delay = min(delay * 2, 60)
|
| 1137 |
|
| 1138 |
-
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%;
|
|
|
|
| 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) {
|
|
|
|
| 749 |
label.textContent = fileName;
|
| 750 |
label.style.fontSize = '0.8rem';
|
| 751 |
label.style.marginBottom = '5px';
|
|
|
|
|
|
|
|
|
|
|
|
|
| 752 |
const container = document.createElement('div');
|
| 753 |
container.appendChild(label);
|
| 754 |
container.appendChild(progressBarContainer);
|
|
|
|
| 755 |
return container;
|
| 756 |
}
|
| 757 |
|
| 758 |
+
function updateProgress(event, progressBar) {
|
| 759 |
if (event.lengthComputable) {
|
| 760 |
const percentComplete = (event.loaded / event.total) * 100;
|
| 761 |
progressBar.style.width = percentComplete + '%';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 762 |
}
|
| 763 |
}
|
| 764 |
|
|
|
|
| 839 |
localStorage.setItem('uploadHistory', JSON.stringify(history));
|
| 840 |
}
|
| 841 |
|
| 842 |
+
function showHistory() {
|
| 843 |
const history = JSON.parse(localStorage.getItem('uploadHistory')) || [];
|
| 844 |
historyList.innerHTML = '';
|
| 845 |
history.forEach(item => {
|
|
|
|
| 889 |
historyModal.style.display = "block";
|
| 890 |
}
|
| 891 |
|
| 892 |
+
function quickOpen(url, fileName, originalExtension) {
|
| 893 |
quickOpenContent.innerHTML = '';
|
| 894 |
const fullUrl = window.location.origin + url;
|
| 895 |
|
|
|
|
| 1099 |
await asyncio.sleep(delay)
|
| 1100 |
delay = min(delay * 2, 60)
|
| 1101 |
|
| 1102 |
+
return False
|