Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from fastapi import FastAPI, File, UploadFile, Request, Form
|
| 2 |
from fastapi.responses import HTMLResponse, RedirectResponse, StreamingResponse
|
| 3 |
-
from typing import List
|
| 4 |
import requests
|
| 5 |
import asyncio
|
| 6 |
import uuid
|
|
@@ -15,13 +15,15 @@ app = FastAPI()
|
|
| 15 |
|
| 16 |
DENO_API_URL = "https://dataerrr99.deno.dev"
|
| 17 |
|
| 18 |
-
async def save_album_to_db(album_name: str, album_id: str, files: List[dict]):
|
| 19 |
async with httpx.AsyncClient() as client:
|
| 20 |
try:
|
| 21 |
response = await client.post(DENO_API_URL, json={
|
| 22 |
"albumName": album_name,
|
| 23 |
"albumLink": album_id,
|
| 24 |
-
"files": files
|
|
|
|
|
|
|
| 25 |
})
|
| 26 |
return response.json()
|
| 27 |
except Exception as e:
|
|
@@ -79,6 +81,7 @@ async def index():
|
|
| 79 |
text-align: center;
|
| 80 |
line-height: 30px;
|
| 81 |
color: white;
|
|
|
|
| 82 |
}
|
| 83 |
.button {
|
| 84 |
display: inline-block;
|
|
@@ -92,6 +95,9 @@ async def index():
|
|
| 92 |
.button:hover {
|
| 93 |
background-color: #0056b3;
|
| 94 |
}
|
|
|
|
|
|
|
|
|
|
| 95 |
</style>
|
| 96 |
</head>
|
| 97 |
<body>
|
|
@@ -99,6 +105,9 @@ async def index():
|
|
| 99 |
<form action="/album/create" method="post" enctype="multipart/form-data" onsubmit="showProgressBar()">
|
| 100 |
<input type="text" name="album_name" placeholder="Album Name" required><br><br>
|
| 101 |
<input type="file" name="files" accept="*/*" multiple required><br><br>
|
|
|
|
|
|
|
|
|
|
| 102 |
<div class="progress-bar">
|
| 103 |
<div class="progress-bar-inner" id="progressBar">0%</div>
|
| 104 |
</div>
|
|
@@ -117,12 +126,15 @@ async def index():
|
|
| 117 |
progressBar.style.width = '0%';
|
| 118 |
progressBar.textContent = '0%';
|
| 119 |
const interval = setInterval(() => {
|
| 120 |
-
const width =
|
| 121 |
if (width < 90) {
|
| 122 |
-
|
| 123 |
-
progressBar.
|
|
|
|
|
|
|
|
|
|
| 124 |
}
|
| 125 |
-
},
|
| 126 |
}
|
| 127 |
</script>
|
| 128 |
</body>
|
|
@@ -133,7 +145,8 @@ async def index():
|
|
| 133 |
async def create_album(
|
| 134 |
request: Request,
|
| 135 |
album_name: str = Form(...),
|
| 136 |
-
files: List[UploadFile] = File(...)
|
|
|
|
| 137 |
):
|
| 138 |
album_id = str(uuid.uuid4())
|
| 139 |
album_files = []
|
|
@@ -161,7 +174,7 @@ async def create_album(
|
|
| 161 |
print(f"Upload Progress: {progress}%")
|
| 162 |
|
| 163 |
# Save to Deno KV database
|
| 164 |
-
await save_album_to_db(album_name, album_id, album_files)
|
| 165 |
|
| 166 |
base_url = str(request.base_url).rstrip('/')
|
| 167 |
return RedirectResponse(url=f"{base_url}/album/{album_id}", status_code=303)
|
|
@@ -253,7 +266,11 @@ async def download_album(album_id: str):
|
|
| 253 |
@app.get("/search", response_class=HTMLResponse)
|
| 254 |
async def search_albums(query: str):
|
| 255 |
db_albums = await get_albums_from_db()
|
| 256 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
|
| 258 |
results_html = ""
|
| 259 |
for album in matching_albums:
|
|
|
|
| 1 |
from fastapi import FastAPI, File, UploadFile, Request, Form
|
| 2 |
from fastapi.responses import HTMLResponse, RedirectResponse, StreamingResponse
|
| 3 |
+
from typing import List, Optional
|
| 4 |
import requests
|
| 5 |
import asyncio
|
| 6 |
import uuid
|
|
|
|
| 15 |
|
| 16 |
DENO_API_URL = "https://dataerrr99.deno.dev"
|
| 17 |
|
| 18 |
+
async def save_album_to_db(album_name: str, album_id: str, files: List[dict], is_private: bool = False):
|
| 19 |
async with httpx.AsyncClient() as client:
|
| 20 |
try:
|
| 21 |
response = await client.post(DENO_API_URL, json={
|
| 22 |
"albumName": album_name,
|
| 23 |
"albumLink": album_id,
|
| 24 |
+
"files": files,
|
| 25 |
+
"isPrivate": is_private,
|
| 26 |
+
"createdAt": datetime.now().isoformat()
|
| 27 |
})
|
| 28 |
return response.json()
|
| 29 |
except Exception as e:
|
|
|
|
| 81 |
text-align: center;
|
| 82 |
line-height: 30px;
|
| 83 |
color: white;
|
| 84 |
+
transition: width 0.3s ease;
|
| 85 |
}
|
| 86 |
.button {
|
| 87 |
display: inline-block;
|
|
|
|
| 95 |
.button:hover {
|
| 96 |
background-color: #0056b3;
|
| 97 |
}
|
| 98 |
+
.private-checkbox {
|
| 99 |
+
margin: 10px 0;
|
| 100 |
+
}
|
| 101 |
</style>
|
| 102 |
</head>
|
| 103 |
<body>
|
|
|
|
| 105 |
<form action="/album/create" method="post" enctype="multipart/form-data" onsubmit="showProgressBar()">
|
| 106 |
<input type="text" name="album_name" placeholder="Album Name" required><br><br>
|
| 107 |
<input type="file" name="files" accept="*/*" multiple required><br><br>
|
| 108 |
+
<label class="private-checkbox">
|
| 109 |
+
<input type="checkbox" name="is_private"> Make this album private (exclude from search)
|
| 110 |
+
</label><br><br>
|
| 111 |
<div class="progress-bar">
|
| 112 |
<div class="progress-bar-inner" id="progressBar">0%</div>
|
| 113 |
</div>
|
|
|
|
| 126 |
progressBar.style.width = '0%';
|
| 127 |
progressBar.textContent = '0%';
|
| 128 |
const interval = setInterval(() => {
|
| 129 |
+
const width = parseFloat(progressBar.style.width);
|
| 130 |
if (width < 90) {
|
| 131 |
+
const newWidth = width + 1;
|
| 132 |
+
progressBar.style.width = newWidth + '%';
|
| 133 |
+
progressBar.textContent = Math.round(newWidth) + '%';
|
| 134 |
+
} else {
|
| 135 |
+
clearInterval(interval);
|
| 136 |
}
|
| 137 |
+
}, 30); // Update every 30ms for smoother progress
|
| 138 |
}
|
| 139 |
</script>
|
| 140 |
</body>
|
|
|
|
| 145 |
async def create_album(
|
| 146 |
request: Request,
|
| 147 |
album_name: str = Form(...),
|
| 148 |
+
files: List[UploadFile] = File(...),
|
| 149 |
+
is_private: Optional[bool] = Form(False)
|
| 150 |
):
|
| 151 |
album_id = str(uuid.uuid4())
|
| 152 |
album_files = []
|
|
|
|
| 174 |
print(f"Upload Progress: {progress}%")
|
| 175 |
|
| 176 |
# Save to Deno KV database
|
| 177 |
+
await save_album_to_db(album_name, album_id, album_files, is_private)
|
| 178 |
|
| 179 |
base_url = str(request.base_url).rstrip('/')
|
| 180 |
return RedirectResponse(url=f"{base_url}/album/{album_id}", status_code=303)
|
|
|
|
| 266 |
@app.get("/search", response_class=HTMLResponse)
|
| 267 |
async def search_albums(query: str):
|
| 268 |
db_albums = await get_albums_from_db()
|
| 269 |
+
# Exclude private albums from search results
|
| 270 |
+
matching_albums = [
|
| 271 |
+
album for album in db_albums['data']
|
| 272 |
+
if query.lower() in album.get('albumName', '').lower() and not album.get('isPrivate', False)
|
| 273 |
+
]
|
| 274 |
|
| 275 |
results_html = ""
|
| 276 |
for album in matching_albums:
|