Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -701,28 +701,38 @@ HTML_CONTENT = """
|
|
701 |
formData.append('file', file);
|
702 |
|
703 |
try {
|
704 |
-
const
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
|
|
|
|
|
|
714 |
} else {
|
715 |
-
throw new Error(
|
716 |
}
|
717 |
-
}
|
718 |
-
|
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();
|
@@ -876,7 +886,7 @@ HTML_CONTENT = """
|
|
876 |
historyList.appendChild(historyItem);
|
877 |
});
|
878 |
historyModal.style.display = "block";
|
879 |
-
|
880 |
|
881 |
function quickOpen(url, fileName, originalExtension) {
|
882 |
quickOpenContent.innerHTML = '';
|
@@ -887,7 +897,7 @@ HTML_CONTENT = """
|
|
887 |
img.src = fullUrl;
|
888 |
img.alt = fileName;
|
889 |
quickOpenContent.appendChild(img);
|
890 |
-
|
891 |
const video = document.createElement('video');
|
892 |
video.src = fullUrl;
|
893 |
video.controls = true;
|
|
|
701 |
formData.append('file', file);
|
702 |
|
703 |
try {
|
704 |
+
const xhr = new XMLHttpRequest();
|
705 |
+
xhr.open('POST', '/upload', true);
|
706 |
+
xhr.upload.onprogress = (event) => updateProgress(event, progressBar.querySelector('.progress'));
|
707 |
+
|
708 |
+
xhr.onload = function() {
|
709 |
+
if (xhr.status === 200) {
|
710 |
+
const response = JSON.parse(xhr.responseText);
|
711 |
+
if (response.url) {
|
712 |
+
addResultLink(response.url, file.name, response.originalExtension);
|
713 |
+
saveToHistory(file.name, response.url, response.originalExtension);
|
714 |
+
} else {
|
715 |
+
throw new Error('Upload failed: ' + response.error);
|
716 |
+
}
|
717 |
} else {
|
718 |
+
throw new Error(`HTTP error! status: ${xhr.status}`);
|
719 |
}
|
720 |
+
};
|
721 |
+
|
722 |
+
xhr.onerror = function() {
|
723 |
+
throw new Error('Network error occurred');
|
724 |
+
};
|
725 |
+
|
726 |
+
xhr.send(formData);
|
727 |
+
|
728 |
+
await new Promise((resolve, reject) => {
|
729 |
+
xhr.onloadend = resolve;
|
730 |
+
xhr.onerror = reject;
|
731 |
+
});
|
732 |
} catch (error) {
|
733 |
console.error('Upload error:', error);
|
734 |
alert(`Failed to upload ${file.name}: ${error.message}`);
|
735 |
}
|
|
|
|
|
736 |
}
|
737 |
|
738 |
resetUploadState();
|
|
|
886 |
historyList.appendChild(historyItem);
|
887 |
});
|
888 |
historyModal.style.display = "block";
|
889 |
+
}
|
890 |
|
891 |
function quickOpen(url, fileName, originalExtension) {
|
892 |
quickOpenContent.innerHTML = '';
|
|
|
897 |
img.src = fullUrl;
|
898 |
img.alt = fileName;
|
899 |
quickOpenContent.appendChild(img);
|
900 |
+
} else if (originalExtension.toLowerCase() === 'mp4') {
|
901 |
const video = document.createElement('video');
|
902 |
video.src = fullUrl;
|
903 |
video.controls = true;
|