Spaces:
Running
Running
Upload app.py
Browse files
app.py
CHANGED
|
@@ -24,6 +24,9 @@ from models_sql import Ownership
|
|
| 24 |
|
| 25 |
app = FastAPI(title="ComfyUI Ranking Community API")
|
| 26 |
|
|
|
|
|
|
|
|
|
|
| 27 |
@app.get("/")
|
| 28 |
def health_check():
|
| 29 |
return {"status": "ok", "message": "ComfyUI Ranking API is running perfectly!"}
|
|
@@ -54,8 +57,16 @@ app.include_router(proxy_router)
|
|
| 54 |
def upload_file(file: UploadFile = File(...), file_type: str = Form(...)):
|
| 55 |
# 同步读取文件内容
|
| 56 |
content = file.file.read()
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
ext = file.filename.split(".")[-1].lower()
|
| 61 |
if ext not in ["jpg", "jpeg", "png", "gif", "webp", "json", "mp4"]:
|
|
|
|
| 24 |
|
| 25 |
app = FastAPI(title="ComfyUI Ranking Community API")
|
| 26 |
|
| 27 |
+
# ==========================================
|
| 28 |
+
# 增加一个根目录健康检查接口,专治 HF Spaces 的 "Restarting" 误判
|
| 29 |
+
# ==========================================
|
| 30 |
@app.get("/")
|
| 31 |
def health_check():
|
| 32 |
return {"status": "ok", "message": "ComfyUI Ranking API is running perfectly!"}
|
|
|
|
| 57 |
def upload_file(file: UploadFile = File(...), file_type: str = Form(...)):
|
| 58 |
# 同步读取文件内容
|
| 59 |
content = file.file.read()
|
| 60 |
+
|
| 61 |
+
# 🟢 动态文件大小风控
|
| 62 |
+
max_size = 10 * 1024 * 1024 # 默认兜底 10MB
|
| 63 |
+
if file_type == "avatar":
|
| 64 |
+
max_size = 2 * 1024 * 1024 # 头像严格限制为 2MB
|
| 65 |
+
elif file_type == "cover":
|
| 66 |
+
max_size = 5 * 1024 * 1024 # 封面图限制为 5MB
|
| 67 |
+
|
| 68 |
+
if len(content) > max_size:
|
| 69 |
+
raise HTTPException(status_code=400, detail=f"文件过大,{file_type} 类型请限制在 {max_size // (1024*1024)}MB 以内")
|
| 70 |
|
| 71 |
ext = file.filename.split(".")[-1].lower()
|
| 72 |
if ext not in ["jpg", "jpeg", "png", "gif", "webp", "json", "mp4"]:
|