Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -17,11 +17,6 @@ HTML_CONTENT = """
|
|
17 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
18 |
<title>Radd PRO Uploader</title>
|
19 |
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
|
20 |
-
<link rel="manifest" href="/manifest.json">
|
21 |
-
<meta name="apple-mobile-web-app-capable" content="yes">
|
22 |
-
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
23 |
-
<meta name="apple-mobile-web-app-title" content="Radd PRO">
|
24 |
-
<link rel="apple-touch-icon" href="/icon-192x192.png">
|
25 |
<style>
|
26 |
body {
|
27 |
font-family: 'Poppins', sans-serif;
|
@@ -425,117 +420,117 @@ HTML_CONTENT = """
|
|
425 |
word-break: break-all;
|
426 |
}
|
427 |
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
}
|
432 |
-
|
433 |
-
.quick-open-modal {
|
434 |
-
display: none;
|
435 |
-
position: fixed;
|
436 |
-
z-index: 4;
|
437 |
-
left: 0;
|
438 |
-
top: 0;
|
439 |
-
width: 100%;
|
440 |
-
height: 100%;
|
441 |
-
background-color: rgba(0,0,0,0.9);
|
442 |
-
overflow: auto;
|
443 |
-
}
|
444 |
-
|
445 |
-
.quick-open-content {
|
446 |
-
margin: 5% auto;
|
447 |
-
padding: 20px;
|
448 |
-
width: 90%;
|
449 |
-
max-width: 800px;
|
450 |
-
text-align: center;
|
451 |
-
}
|
452 |
-
|
453 |
-
.quick-open-content img,
|
454 |
-
.quick-open-content video,
|
455 |
-
.quick-open-content audio {
|
456 |
-
max-width: 100%;
|
457 |
-
max-height: 70vh;
|
458 |
-
margin-bottom: 20px;
|
459 |
-
}
|
460 |
-
|
461 |
-
.quick-open-content iframe {
|
462 |
-
width: 100%;
|
463 |
-
height: 70vh;
|
464 |
-
border: none;
|
465 |
-
}
|
466 |
-
|
467 |
-
@media (max-width: 480px) {
|
468 |
-
.container {
|
469 |
-
padding: 1.5rem;
|
470 |
}
|
471 |
|
472 |
-
|
473 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
474 |
}
|
475 |
|
476 |
-
.
|
477 |
-
|
478 |
-
padding:
|
479 |
-
|
|
|
|
|
480 |
}
|
481 |
|
482 |
-
|
483 |
-
|
|
|
|
|
|
|
|
|
484 |
}
|
485 |
|
486 |
-
.
|
487 |
-
width:
|
488 |
-
|
489 |
-
|
490 |
}
|
491 |
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
}
|
501 |
|
502 |
-
|
503 |
-
|
504 |
-
|
|
|
|
|
505 |
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
|
510 |
-
|
511 |
-
|
512 |
-
|
|
|
|
|
513 |
|
514 |
-
|
515 |
-
|
516 |
-
|
|
|
517 |
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
font-size: 24px;
|
531 |
-
}
|
532 |
|
533 |
-
|
534 |
-
|
535 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
536 |
}
|
537 |
-
|
538 |
-
</style>
|
539 |
</head>
|
540 |
<body>
|
541 |
<div class="container">
|
@@ -642,18 +637,26 @@ HTML_CONTENT = """
|
|
642 |
}
|
643 |
});
|
644 |
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
|
|
|
|
|
|
|
|
651 |
}
|
652 |
|
653 |
window.onclick = function(event) {
|
654 |
-
if (event.target == modal
|
655 |
modal.style.display = "none";
|
|
|
|
|
656 |
historyModal.style.display = "none";
|
|
|
|
|
657 |
quickOpenModal.style.display = "none";
|
658 |
}
|
659 |
}
|
@@ -674,6 +677,10 @@ HTML_CONTENT = """
|
|
674 |
const file = e.target.files[0];
|
675 |
fileName.textContent = file.name;
|
676 |
uploadBtn.style.display = 'inline-block';
|
|
|
|
|
|
|
|
|
677 |
}
|
678 |
}
|
679 |
|
@@ -691,29 +698,44 @@ HTML_CONTENT = """
|
|
691 |
const formData = new FormData();
|
692 |
formData.append('file', file);
|
693 |
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
699 |
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
|
704 |
-
|
705 |
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
|
|
|
|
|
|
|
|
711 |
}
|
712 |
-
} catch (error) {
|
713 |
-
console.error('Upload error:', error);
|
714 |
-
alert('Upload failed. Please try again.');
|
715 |
-
} finally {
|
716 |
-
resetUploadState();
|
717 |
}
|
718 |
}
|
719 |
|
@@ -733,13 +755,19 @@ HTML_CONTENT = """
|
|
733 |
return container;
|
734 |
}
|
735 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
736 |
function resetUploadState() {
|
737 |
fileInput.value = '';
|
738 |
fileName.textContent = '';
|
739 |
uploadBtn.style.display = 'none';
|
740 |
uploadBtn.disabled = false;
|
741 |
loadingSpinner.style.display = 'none';
|
742 |
-
progressContainer.style.display = 'none';
|
743 |
}
|
744 |
|
745 |
function addResultLink(url, fileName, originalExtension) {
|
@@ -861,7 +889,7 @@ HTML_CONTENT = """
|
|
861 |
historyModal.style.display = "block";
|
862 |
}
|
863 |
|
864 |
-
|
865 |
quickOpenContent.innerHTML = '';
|
866 |
const fullUrl = window.location.origin + url;
|
867 |
|
@@ -903,17 +931,7 @@ HTML_CONTENT = """
|
|
903 |
|
904 |
quickOpenModal.style.display = "block";
|
905 |
}
|
906 |
-
|
907 |
-
if ('serviceWorker' in navigator) {
|
908 |
-
window.addEventListener('load', () => {
|
909 |
-
navigator.serviceWorker.register('/sw.js').then(registration => {
|
910 |
-
console.log('ServiceWorker registration successful with scope: ', registration.scope);
|
911 |
-
}, err => {
|
912 |
-
console.log('ServiceWorker registration failed: ', err);
|
913 |
-
});
|
914 |
-
});
|
915 |
-
}
|
916 |
-
</script>
|
917 |
</body>
|
918 |
</html>
|
919 |
"""
|
@@ -929,7 +947,7 @@ async def handle_upload(file: UploadFile = File(...)):
|
|
929 |
|
930 |
cookies = await get_cookies()
|
931 |
if 'csrftoken' not in cookies or 'sessionid' not in cookies:
|
932 |
-
return JSONResponse(content={"error": "Failed
|
933 |
|
934 |
original_extension = os.path.splitext(file.filename)[1][1:]
|
935 |
supported_types = ['mp4', 'png', 'jpg', 'jpeg', 'gif', 'mp3', 'pdf', 'txt']
|
@@ -943,12 +961,12 @@ async def handle_upload(file: UploadFile = File(...)):
|
|
943 |
|
944 |
upload_result = await initiate_upload(cookies, temp_filename, content_type)
|
945 |
if not upload_result or 'upload_url' not in upload_result:
|
946 |
-
return JSONResponse(content={"error": "Failed to
|
947 |
|
948 |
file_content = await file.read()
|
949 |
upload_success = await retry_upload(upload_result['upload_url'], file_content, content_type)
|
950 |
if not upload_success:
|
951 |
-
return JSONResponse(content={"error": "
|
952 |
|
953 |
original_url = upload_result['serving_url']
|
954 |
mirrored_url = f"/rbxg/{original_url.split('/pbxt/')[1]}"
|
@@ -1069,7 +1087,7 @@ async def upload_file(upload_url: str, file_content: bytes, content_type: str) -
|
|
1069 |
return False
|
1070 |
|
1071 |
async def retry_upload(upload_url: str, file_content: bytes, content_type: str, max_retries: int = 5, delay: int = 1) -> bool:
|
1072 |
-
|
1073 |
try:
|
1074 |
success = await upload_file(upload_url, file_content, content_type)
|
1075 |
if success:
|
|
|
17 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
18 |
<title>Radd PRO Uploader</title>
|
19 |
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
|
|
|
|
|
|
|
|
|
|
|
20 |
<style>
|
21 |
body {
|
22 |
font-family: 'Poppins', sans-serif;
|
|
|
420 |
word-break: break-all;
|
421 |
}
|
422 |
|
423 |
+
.history-item-actions {
|
424 |
+
display: flex;
|
425 |
+
gap: 5px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
426 |
}
|
427 |
|
428 |
+
.quick-open-modal {
|
429 |
+
display: none;
|
430 |
+
position: fixed;
|
431 |
+
z-index: 4;
|
432 |
+
left: 0;
|
433 |
+
top: 0;
|
434 |
+
width: 100%;
|
435 |
+
height: 100%;
|
436 |
+
background-color: rgba(0,0,0,0.9);
|
437 |
+
overflow: auto;
|
438 |
}
|
439 |
|
440 |
+
.quick-open-content {
|
441 |
+
margin: 5% auto;
|
442 |
+
padding: 20px;
|
443 |
+
width: 90%;
|
444 |
+
max-width: 800px;
|
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%;
|
452 |
+
max-height: 70vh;
|
453 |
+
margin-bottom: 20px;
|
454 |
}
|
455 |
|
456 |
+
.quick-open-content iframe {
|
457 |
+
width: 100%;
|
458 |
+
height: 70vh;
|
459 |
+
border: none;
|
460 |
}
|
461 |
|
462 |
+
@media (max-width: 480px) {
|
463 |
+
.container {
|
464 |
+
padding: 1.5rem;
|
465 |
+
}
|
466 |
|
467 |
+
h1 {
|
468 |
+
font-size: 1.5rem;
|
469 |
+
}
|
|
|
470 |
|
471 |
+
.btn, .small-btn {
|
472 |
+
font-size: 0.9rem;
|
473 |
+
padding: 10px 20px;
|
474 |
+
margin: 0.25rem;
|
475 |
+
}
|
476 |
|
477 |
+
.file-types {
|
478 |
+
font-size: 0.7rem;
|
479 |
+
}
|
480 |
|
481 |
+
.modal-content, .history-modal-content {
|
482 |
+
width: 95%;
|
483 |
+
margin: 5% auto;
|
484 |
+
padding: 15px;
|
485 |
+
}
|
486 |
|
487 |
+
.history-item {
|
488 |
+
flex-direction: column;
|
489 |
+
align-items: flex-start;
|
490 |
+
}
|
491 |
|
492 |
+
.history-item-actions {
|
493 |
+
margin-top: 10px;
|
494 |
+
flex-wrap: wrap;
|
495 |
+
}
|
496 |
|
497 |
+
.history-item-name {
|
498 |
+
font-size: 0.9rem;
|
499 |
+
}
|
500 |
|
501 |
+
.drop-zone {
|
502 |
+
padding: 15px;
|
503 |
+
}
|
|
|
|
|
504 |
|
505 |
+
.drop-zone p {
|
506 |
+
font-size: 0.9rem;
|
507 |
+
}
|
508 |
+
|
509 |
+
.result-link {
|
510 |
+
font-size: 0.9rem;
|
511 |
+
}
|
512 |
+
|
513 |
+
.link-buttons {
|
514 |
+
flex-direction: column;
|
515 |
+
align-items: stretch;
|
516 |
+
}
|
517 |
+
|
518 |
+
.link-buttons .small-btn {
|
519 |
+
margin: 0.25rem 0;
|
520 |
+
}
|
521 |
+
|
522 |
+
.close {
|
523 |
+
top: 5px;
|
524 |
+
right: 10px;
|
525 |
+
font-size: 24px;
|
526 |
+
}
|
527 |
+
|
528 |
+
.quick-open-content {
|
529 |
+
margin: 10% auto;
|
530 |
+
padding: 10px;
|
531 |
+
}
|
532 |
}
|
533 |
+
</style>
|
|
|
534 |
</head>
|
535 |
<body>
|
536 |
<div class="container">
|
|
|
637 |
}
|
638 |
});
|
639 |
|
640 |
+
span[0].onclick = function() {
|
641 |
+
modal.style.display = "none";
|
642 |
+
}
|
643 |
+
|
644 |
+
span[1].onclick = function() {
|
645 |
+
historyModal.style.display = "none";
|
646 |
+
}
|
647 |
+
|
648 |
+
span[2].onclick = function() {
|
649 |
+
quickOpenModal.style.display = "none";
|
650 |
}
|
651 |
|
652 |
window.onclick = function(event) {
|
653 |
+
if (event.target == modal) {
|
654 |
modal.style.display = "none";
|
655 |
+
}
|
656 |
+
if (event.target == historyModal) {
|
657 |
historyModal.style.display = "none";
|
658 |
+
}
|
659 |
+
if (event.target == quickOpenModal) {
|
660 |
quickOpenModal.style.display = "none";
|
661 |
}
|
662 |
}
|
|
|
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 |
|
|
|
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) {
|
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 |
+
break;
|
735 |
+
} catch (error) {
|
736 |
+
console.error('Upload error:', error);
|
737 |
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
738 |
}
|
|
|
|
|
|
|
|
|
|
|
739 |
}
|
740 |
}
|
741 |
|
|
|
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 |
+
|
765 |
function resetUploadState() {
|
766 |
fileInput.value = '';
|
767 |
fileName.textContent = '';
|
768 |
uploadBtn.style.display = 'none';
|
769 |
uploadBtn.disabled = false;
|
770 |
loadingSpinner.style.display = 'none';
|
|
|
771 |
}
|
772 |
|
773 |
function addResultLink(url, fileName, originalExtension) {
|
|
|
889 |
historyModal.style.display = "block";
|
890 |
}
|
891 |
|
892 |
+
function quickOpen(url, fileName, originalExtension) {
|
893 |
quickOpenContent.innerHTML = '';
|
894 |
const fullUrl = window.location.origin + url;
|
895 |
|
|
|
931 |
|
932 |
quickOpenModal.style.display = "block";
|
933 |
}
|
934 |
+
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
935 |
</body>
|
936 |
</html>
|
937 |
"""
|
|
|
947 |
|
948 |
cookies = await get_cookies()
|
949 |
if 'csrftoken' not in cookies or 'sessionid' not in cookies:
|
950 |
+
return JSONResponse(content={"error": "Failed"}, status_code=500)
|
951 |
|
952 |
original_extension = os.path.splitext(file.filename)[1][1:]
|
953 |
supported_types = ['mp4', 'png', 'jpg', 'jpeg', 'gif', 'mp3', 'pdf', 'txt']
|
|
|
961 |
|
962 |
upload_result = await initiate_upload(cookies, temp_filename, content_type)
|
963 |
if not upload_result or 'upload_url' not in upload_result:
|
964 |
+
return JSONResponse(content={"error": "Failed to upload"}, status_code=500)
|
965 |
|
966 |
file_content = await file.read()
|
967 |
upload_success = await retry_upload(upload_result['upload_url'], file_content, content_type)
|
968 |
if not upload_success:
|
969 |
+
return JSONResponse(content={"error": "FAILED GOD MAN AFTER alot of attempts"}, status_code=500)
|
970 |
|
971 |
original_url = upload_result['serving_url']
|
972 |
mirrored_url = f"/rbxg/{original_url.split('/pbxt/')[1]}"
|
|
|
1087 |
return False
|
1088 |
|
1089 |
async def retry_upload(upload_url: str, file_content: bytes, content_type: str, max_retries: int = 5, delay: int = 1) -> bool:
|
1090 |
+
while True:
|
1091 |
try:
|
1092 |
success = await upload_file(upload_url, file_content, content_type)
|
1093 |
if success:
|