Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ from fastapi.responses import HTMLResponse, JSONResponse, StreamingResponse, Fil
|
|
3 |
import requests
|
4 |
import time
|
5 |
import asyncio
|
6 |
-
from typing import Dict
|
7 |
import os
|
8 |
import mimetypes
|
9 |
|
@@ -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,13 @@ HTML_CONTENT = """
|
|
674 |
|
675 |
function handleFileSelect(e) {
|
676 |
if (e.target.files && e.target.files.length > 0) {
|
677 |
-
const
|
678 |
-
fileName.textContent =
|
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 +688,53 @@ HTML_CONTENT = """
|
|
692 |
resultContainer.innerHTML = '';
|
693 |
resultContainer.style.display = 'none';
|
694 |
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
|
|
|
|
715 |
} else {
|
716 |
-
throw new Error(
|
717 |
}
|
718 |
-
}
|
719 |
-
throw new Error(`HTTP error! status: ${xhr.status}`);
|
720 |
-
}
|
721 |
-
};
|
722 |
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
|
727 |
-
|
728 |
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
|
|
738 |
}
|
739 |
}
|
|
|
|
|
740 |
}
|
741 |
|
742 |
function createProgressBar(fileName) {
|
@@ -883,13 +881,13 @@ HTML_CONTENT = """
|
|
883 |
actionsContainer.appendChild(embedBtn);
|
884 |
}
|
885 |
|
886 |
-
|
887 |
historyList.appendChild(historyItem);
|
888 |
});
|
889 |
historyModal.style.display = "block";
|
890 |
}
|
891 |
|
892 |
-
|
893 |
quickOpenContent.innerHTML = '';
|
894 |
const fullUrl = window.location.origin + url;
|
895 |
|
|
|
3 |
import requests
|
4 |
import time
|
5 |
import asyncio
|
6 |
+
from typing import Dict, List
|
7 |
import os
|
8 |
import mimetypes
|
9 |
|
|
|
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="*" required multiple>
|
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 fileNames = Array.from(e.target.files).map(file => file.name).join(', ');
|
678 |
+
fileName.textContent = fileNames;
|
679 |
uploadBtn.style.display = 'inline-block';
|
|
|
|
|
|
|
|
|
680 |
}
|
681 |
}
|
682 |
|
683 |
+
async function uploadFiles(files) {
|
684 |
progressContainer.innerHTML = '';
|
685 |
progressContainer.style.display = 'block';
|
686 |
loadingSpinner.style.display = 'block';
|
|
|
688 |
resultContainer.innerHTML = '';
|
689 |
resultContainer.style.display = 'none';
|
690 |
|
691 |
+
for (let file of files) {
|
692 |
+
const progressBar = createProgressBar(file.name);
|
693 |
+
progressContainer.appendChild(progressBar);
|
694 |
+
|
695 |
+
const formData = new FormData();
|
696 |
+
formData.append('file', file);
|
697 |
+
|
698 |
+
while (true) {
|
699 |
+
try {
|
700 |
+
const xhr = new XMLHttpRequest();
|
701 |
+
xhr.open('POST', '/upload', true);
|
702 |
+
xhr.upload.onprogress = (event) => updateProgress(event, progressBar.querySelector('.progress'));
|
703 |
+
|
704 |
+
xhr.onload = function() {
|
705 |
+
if (xhr.status === 200) {
|
706 |
+
const response = JSON.parse(xhr.responseText);
|
707 |
+
if (response.url) {
|
708 |
+
addResultLink(response.url, file.name, response.originalExtension);
|
709 |
+
saveToHistory(file.name, response.url, response.originalExtension);
|
710 |
+
} else {
|
711 |
+
throw new Error('Upload failed: ' + response.error);
|
712 |
+
}
|
713 |
} else {
|
714 |
+
throw new Error(`HTTP error! status: ${xhr.status}`);
|
715 |
}
|
716 |
+
};
|
|
|
|
|
|
|
717 |
|
718 |
+
xhr.onerror = function() {
|
719 |
+
throw new Error('Network error occurred');
|
720 |
+
};
|
721 |
|
722 |
+
xhr.send(formData);
|
723 |
|
724 |
+
await new Promise((resolve, reject) => {
|
725 |
+
xhr.onloadend = resolve;
|
726 |
+
xhr.onerror = reject;
|
727 |
+
});
|
728 |
|
729 |
+
break;
|
730 |
+
} catch (error) {
|
731 |
+
console.error('Upload error:', error);
|
732 |
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
733 |
+
}
|
734 |
}
|
735 |
}
|
736 |
+
|
737 |
+
resetUploadState();
|
738 |
}
|
739 |
|
740 |
function createProgressBar(fileName) {
|
|
|
881 |
actionsContainer.appendChild(embedBtn);
|
882 |
}
|
883 |
|
884 |
+
historyItem.appendChild(actionsContainer);
|
885 |
historyList.appendChild(historyItem);
|
886 |
});
|
887 |
historyModal.style.display = "block";
|
888 |
}
|
889 |
|
890 |
+
function quickOpen(url, fileName, originalExtension) {
|
891 |
quickOpenContent.innerHTML = '';
|
892 |
const fullUrl = window.location.origin + url;
|
893 |
|