Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,9 @@ import requests
|
|
4 |
import time
|
5 |
import asyncio
|
6 |
from typing import Dict
|
|
|
|
|
|
|
7 |
|
8 |
app = FastAPI()
|
9 |
|
@@ -425,7 +428,7 @@ HTML_CONTENT = """
|
|
425 |
font-size: 0.7rem;
|
426 |
}
|
427 |
|
428 |
-
|
429 |
width: 95%;
|
430 |
margin: 5% auto;
|
431 |
padding: 15px;
|
@@ -445,7 +448,7 @@ HTML_CONTENT = """
|
|
445 |
font-size: 0.9rem;
|
446 |
}
|
447 |
|
448 |
-
|
449 |
padding: 15px;
|
450 |
}
|
451 |
|
@@ -720,6 +723,17 @@ HTML_CONTENT = """
|
|
720 |
buttonsContainer.appendChild(embedBtn);
|
721 |
}
|
722 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
723 |
linkContainer.appendChild(buttonsContainer);
|
724 |
|
725 |
resultContainer.appendChild(linkContainer);
|
@@ -789,12 +803,36 @@ HTML_CONTENT = """
|
|
789 |
actionsContainer.appendChild(embedBtn);
|
790 |
}
|
791 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
792 |
historyItem.appendChild(actionsContainer);
|
793 |
historyList.appendChild(historyItem);
|
794 |
});
|
795 |
historyModal.style.display = "block";
|
796 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
797 |
</script>
|
|
|
798 |
</body>
|
799 |
</html>
|
800 |
"""
|
@@ -888,6 +926,14 @@ async def embed_video(url: str, thumbnail: str):
|
|
888 |
'''
|
889 |
return HTMLResponse(content=html)
|
890 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
891 |
async def get_cookies() -> Dict[str, str]:
|
892 |
try:
|
893 |
response = requests.get('https://replicate.com/levelsio/neon-tokyo', headers={
|
@@ -939,6 +985,10 @@ async def retry_upload(upload_url: str, file_content: bytes, content_type: str,
|
|
939 |
print(f"Error during upload: {e}")
|
940 |
|
941 |
await asyncio.sleep(delay)
|
942 |
-
delay = min(delay * 2, 60)
|
943 |
|
944 |
return False
|
|
|
|
|
|
|
|
|
|
4 |
import time
|
5 |
import asyncio
|
6 |
from typing import Dict
|
7 |
+
import base64
|
8 |
+
import hashlib
|
9 |
+
from cryptography.fernet import Fernet
|
10 |
|
11 |
app = FastAPI()
|
12 |
|
|
|
428 |
font-size: 0.7rem;
|
429 |
}
|
430 |
|
431 |
+
.modal-content, .history-modal-content {
|
432 |
width: 95%;
|
433 |
margin: 5% auto;
|
434 |
padding: 15px;
|
|
|
448 |
font-size: 0.9rem;
|
449 |
}
|
450 |
|
451 |
+
.drop-zone {
|
452 |
padding: 15px;
|
453 |
}
|
454 |
|
|
|
723 |
buttonsContainer.appendChild(embedBtn);
|
724 |
}
|
725 |
|
726 |
+
const encryptBtn = document.createElement('button');
|
727 |
+
encryptBtn.textContent = 'Encrypt Link';
|
728 |
+
encryptBtn.className = 'small-btn encrypt-btn';
|
729 |
+
encryptBtn.onclick = () => {
|
730 |
+
const encryptedUrl = encryptUrl(url);
|
731 |
+
navigator.clipboard.writeText(encryptedUrl).then(() => {
|
732 |
+
alert('Encrypted link copied to clipboard!');
|
733 |
+
});
|
734 |
+
};
|
735 |
+
buttonsContainer.appendChild(encryptBtn);
|
736 |
+
|
737 |
linkContainer.appendChild(buttonsContainer);
|
738 |
|
739 |
resultContainer.appendChild(linkContainer);
|
|
|
803 |
actionsContainer.appendChild(embedBtn);
|
804 |
}
|
805 |
|
806 |
+
const encryptBtn = document.createElement('button');
|
807 |
+
encryptBtn.textContent = 'Encrypt';
|
808 |
+
encryptBtn.className = 'small-btn';
|
809 |
+
encryptBtn.onclick = () => {
|
810 |
+
const encryptedUrl = encryptUrl(item.url);
|
811 |
+
navigator.clipboard.writeText(encryptedUrl).then(() => {
|
812 |
+
alert('Encrypted link copied to clipboard!');
|
813 |
+
});
|
814 |
+
};
|
815 |
+
actionsContainer.appendChild(encryptBtn);
|
816 |
+
|
817 |
historyItem.appendChild(actionsContainer);
|
818 |
historyList.appendChild(historyItem);
|
819 |
});
|
820 |
historyModal.style.display = "block";
|
821 |
}
|
822 |
+
|
823 |
+
function encryptUrl(url) {
|
824 |
+
const key = generateEncryptionKey();
|
825 |
+
const encryptedData = CryptoJS.AES.encrypt(url, key).toString();
|
826 |
+
const encryptedUrl = `${window.location.origin}/decrypt?data=${encodeURIComponent(encryptedData)}&key=${encodeURIComponent(key)}`;
|
827 |
+
return encryptedUrl;
|
828 |
+
}
|
829 |
+
|
830 |
+
function generateEncryptionKey() {
|
831 |
+
const browserInfo = navigator.userAgent + navigator.language + screen.width + screen.height + new Date().getTimezoneOffset();
|
832 |
+
return CryptoJS.SHA256(browserInfo).toString();
|
833 |
+
}
|
834 |
</script>
|
835 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
|
836 |
</body>
|
837 |
</html>
|
838 |
"""
|
|
|
926 |
'''
|
927 |
return HTMLResponse(content=html)
|
928 |
|
929 |
+
@app.get("/decrypt")
|
930 |
+
async def decrypt_url(data: str, key: str):
|
931 |
+
try:
|
932 |
+
decrypted_url = Fernet(key.encode()).decrypt(data.encode()).decode()
|
933 |
+
return RedirectResponse(url=decrypted_url)
|
934 |
+
except:
|
935 |
+
return HTMLResponse(content="Invalid or expired link", status_code=400)
|
936 |
+
|
937 |
async def get_cookies() -> Dict[str, str]:
|
938 |
try:
|
939 |
response = requests.get('https://replicate.com/levelsio/neon-tokyo', headers={
|
|
|
985 |
print(f"Error during upload: {e}")
|
986 |
|
987 |
await asyncio.sleep(delay)
|
988 |
+
delay = min(delay * 2, 60)
|
989 |
|
990 |
return False
|
991 |
+
|
992 |
+
if __name__ == "__main__":
|
993 |
+
import uvicorn
|
994 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|