Update app.py
Browse files
app.py
CHANGED
|
@@ -55,8 +55,15 @@ def get_file_type(filename):
|
|
| 55 |
return 'image'
|
| 56 |
elif mime_type.startswith('video/'):
|
| 57 |
return 'video'
|
|
|
|
|
|
|
| 58 |
return 'other'
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
@app.get("/", response_class=HTMLResponse)
|
| 61 |
async def index():
|
| 62 |
return """
|
|
@@ -148,6 +155,24 @@ async def create_album(
|
|
| 148 |
files: List[UploadFile] = File(...),
|
| 149 |
is_private: Optional[bool] = Form(False)
|
| 150 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
album_id = str(uuid.uuid4())
|
| 152 |
album_files = []
|
| 153 |
|
|
@@ -354,4 +379,4 @@ async def retry_upload(upload_url, file_content, content_type, max_retries=5):
|
|
| 354 |
|
| 355 |
if __name__ == "__main__":
|
| 356 |
import uvicorn
|
| 357 |
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
|
| 55 |
return 'image'
|
| 56 |
elif mime_type.startswith('video/'):
|
| 57 |
return 'video'
|
| 58 |
+
elif mime_type.startswith('audio/'):
|
| 59 |
+
return 'audio'
|
| 60 |
return 'other'
|
| 61 |
|
| 62 |
+
def is_allowed_file_type(filename):
|
| 63 |
+
allowed_types = ['image', 'video', 'audio', 'application/zip']
|
| 64 |
+
mime_type, _ = mimetypes.guess_type(filename)
|
| 65 |
+
return mime_type and any(mime_type.startswith(t) for t in allowed_types)
|
| 66 |
+
|
| 67 |
@app.get("/", response_class=HTMLResponse)
|
| 68 |
async def index():
|
| 69 |
return """
|
|
|
|
| 155 |
files: List[UploadFile] = File(...),
|
| 156 |
is_private: Optional[bool] = Form(False)
|
| 157 |
):
|
| 158 |
+
for file in files:
|
| 159 |
+
if not is_allowed_file_type(file.filename):
|
| 160 |
+
return HTMLResponse(content=f"""
|
| 161 |
+
<!DOCTYPE html>
|
| 162 |
+
<html lang="en">
|
| 163 |
+
<head>
|
| 164 |
+
<meta charset="UTF-8">
|
| 165 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 166 |
+
<title>Error</title>
|
| 167 |
+
</head>
|
| 168 |
+
<body>
|
| 169 |
+
<h1>Error: Invalid File Type</h1>
|
| 170 |
+
<p>The file '{file.filename}' is not allowed. Please upload it using the <a href="https://albumup-up1.hf.space/">Single File Upload</a>.</p>
|
| 171 |
+
<a href="/" class="button">← Back to Home</a>
|
| 172 |
+
</body>
|
| 173 |
+
</html>
|
| 174 |
+
""", status_code=400)
|
| 175 |
+
|
| 176 |
album_id = str(uuid.uuid4())
|
| 177 |
album_files = []
|
| 178 |
|
|
|
|
| 379 |
|
| 380 |
if __name__ == "__main__":
|
| 381 |
import uvicorn
|
| 382 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|