Spaces:
Running
Running
修复下载拦截,提示无效的下载链接
Browse files
app.py
CHANGED
|
@@ -382,7 +382,15 @@ class ValidateResourceRequest(BaseModel):
|
|
| 382 |
@app.post("/api/validate_resource")
|
| 383 |
def validate_resource(req_data: ValidateResourceRequest, sql_db: Session = Depends(get_db)):
|
| 384 |
target_url = req_data.url
|
| 385 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
return JSONResponse(content={"error": "无效的下载链接"}, status_code=400)
|
| 387 |
|
| 388 |
items_db = db.load_data("items.json", default_data=[])
|
|
@@ -398,6 +406,10 @@ def validate_resource(req_data: ValidateResourceRequest, sql_db: Session = Depen
|
|
| 398 |
if not owned:
|
| 399 |
return JSONResponse(content={"error": "🚨 非法下载:云端数据库未找到您的购买凭证!"}, status_code=403)
|
| 400 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
hf_token = os.environ.get("HF_TOKEN")
|
| 402 |
if not hf_token: return JSONResponse(content={"error": "云端环境变量未配置 HF_TOKEN"}, status_code=401)
|
| 403 |
|
|
|
|
| 382 |
@app.post("/api/validate_resource")
|
| 383 |
def validate_resource(req_data: ValidateResourceRequest, sql_db: Session = Depends(get_db)):
|
| 384 |
target_url = req_data.url
|
| 385 |
+
|
| 386 |
+
# 允许的链接前缀:HuggingFace数据集、GitHub仓库、内部代理URL
|
| 387 |
+
ALLOWED_URL_PREFIXES = (
|
| 388 |
+
"https://huggingface.co/datasets/",
|
| 389 |
+
"https://github.com/",
|
| 390 |
+
"https://zhiwei666-comfyui-ranking-api.hf.space/api/image_proxy",
|
| 391 |
+
)
|
| 392 |
+
|
| 393 |
+
if not any(target_url.startswith(prefix) for prefix in ALLOWED_URL_PREFIXES):
|
| 394 |
return JSONResponse(content={"error": "无效的下载链接"}, status_code=400)
|
| 395 |
|
| 396 |
items_db = db.load_data("items.json", default_data=[])
|
|
|
|
| 406 |
if not owned:
|
| 407 |
return JSONResponse(content={"error": "🚨 非法下载:云端数据库未找到您的购买凭证!"}, status_code=403)
|
| 408 |
|
| 409 |
+
# 内部代理URL直接返回成功(文件已存在于服务器本地)
|
| 410 |
+
if target_url.startswith("https://zhiwei666-comfyui-ranking-api.hf.space/api/image_proxy"):
|
| 411 |
+
return {"status": "success", "message": "资源有效"}
|
| 412 |
+
|
| 413 |
hf_token = os.environ.get("HF_TOKEN")
|
| 414 |
if not hf_token: return JSONResponse(content={"error": "云端环境变量未配置 HF_TOKEN"}, status_code=401)
|
| 415 |
|