albumup commited on
Commit
8424f41
·
verified ·
1 Parent(s): 8985d12

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -26
app.py CHANGED
@@ -9,25 +9,12 @@ import mimetypes
9
  import httpx
10
  import io
11
  import zipfile
 
12
 
13
  app = FastAPI()
14
 
15
  DENO_API_URL = "https://dataerrr99.deno.dev"
16
 
17
- # Define allowed media types
18
- ALLOWED_MEDIA_TYPES = {
19
- "image": ["image/jpeg", "image/png", "image/gif", "image/webp", "image/svg+xml"],
20
- "video": ["video/mp4", "video/mkv", "video/webm", "video/quicktime"],
21
- "audio": ["audio/mpeg", "audio/wav", "audio/ogg", "audio/webm"]
22
- }
23
-
24
- def is_media_file(content_type: str) -> bool:
25
- """Check if the file is a media type (image, video, or audio)."""
26
- for category, types in ALLOWED_MEDIA_TYPES.items():
27
- if content_type in types:
28
- return True
29
- return False
30
-
31
  async def save_album_to_db(album_name: str, album_id: str, files: List[dict], is_private: bool = False):
32
  async with httpx.AsyncClient() as client:
33
  try:
@@ -68,8 +55,6 @@ def get_file_type(filename):
68
  return 'image'
69
  elif mime_type.startswith('video/'):
70
  return 'video'
71
- elif mime_type.startswith('audio/'):
72
- return 'audio'
73
  return 'other'
74
 
75
  @app.get("/", response_class=HTMLResponse)
@@ -171,10 +156,6 @@ async def create_album(
171
  uploaded_files = 0
172
 
173
  for file in files:
174
- if not is_media_file(file.content_type):
175
- # Redirect to single file upload for non-media files
176
- return RedirectResponse(url="https://albumup-up1.hf.space/", status_code=303)
177
-
178
  file_content = await file.read()
179
  upload_result = await initiate_upload(cookies, file.filename, file.content_type)
180
 
@@ -226,13 +207,10 @@ async def view_album(album_id: str):
226
  </video>
227
  </div>
228
  """
229
- elif file_type == 'audio':
230
  preview_html = f"""
231
  <div class="preview-container">
232
- <audio controls>
233
- <source src="{file_url}" type="{file['content_type']}">
234
- Your browser does not support the audio tag.
235
- </audio>
236
  </div>
237
  """
238
 
@@ -376,4 +354,4 @@ async def retry_upload(upload_url, file_content, content_type, max_retries=5):
376
 
377
  if __name__ == "__main__":
378
  import uvicorn
379
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
9
  import httpx
10
  import io
11
  import zipfile
12
+ import math
13
 
14
  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], is_private: bool = False):
19
  async with httpx.AsyncClient() as client:
20
  try:
 
55
  return 'image'
56
  elif mime_type.startswith('video/'):
57
  return 'video'
 
 
58
  return 'other'
59
 
60
  @app.get("/", response_class=HTMLResponse)
 
156
  uploaded_files = 0
157
 
158
  for file in files:
 
 
 
 
159
  file_content = await file.read()
160
  upload_result = await initiate_upload(cookies, file.filename, file.content_type)
161
 
 
207
  </video>
208
  </div>
209
  """
210
+ else:
211
  preview_html = f"""
212
  <div class="preview-container">
213
+ <p>No preview available for {file['filename']}</p>
 
 
 
214
  </div>
215
  """
216
 
 
354
 
355
  if __name__ == "__main__":
356
  import uvicorn
357
+ uvicorn.run(app, host="0.0.0.0", port=8000)