Spaces:
Paused
Paused
github-actions[bot]
commited on
Commit
·
9cf7a5c
1
Parent(s):
9779927
Update from GitHub Actions
Browse files
main.py
CHANGED
|
@@ -29,8 +29,12 @@ async def stream_generator(response):
|
|
| 29 |
yield chunk
|
| 30 |
await asyncio.sleep(0.001) # 让出控制权,保持异步特性
|
| 31 |
|
| 32 |
-
@app.
|
| 33 |
-
async def
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
"""
|
| 35 |
通用代理端点,转发所有请求到目标URL,支持流式响应
|
| 36 |
"""
|
|
@@ -38,13 +42,10 @@ async def proxy(request: Request, path: str, target_url: Optional[str] = None):
|
|
| 38 |
# 获取请求方法
|
| 39 |
method = request.method
|
| 40 |
|
| 41 |
-
|
| 42 |
if not target_url:
|
| 43 |
-
|
| 44 |
-
if not target_url:
|
| 45 |
-
raise HTTPException(status_code=400, detail="必须提供目标URL")
|
| 46 |
|
| 47 |
-
|
| 48 |
# 检查是否请求流式响应
|
| 49 |
stream_request = "stream" in request.query_params and request.query_params["stream"].lower() in ["true", "1", "yes"]
|
| 50 |
|
|
@@ -167,9 +168,7 @@ async def proxy(request: Request, path: str, target_url: Optional[str] = None):
|
|
| 167 |
except Exception as e:
|
| 168 |
raise HTTPException(status_code=500, detail=f"代理请求失败: {str(e)}")
|
| 169 |
|
| 170 |
-
|
| 171 |
-
async def root():
|
| 172 |
-
return {"message": "欢迎使用ScraperProxy API,访问 /docs 查看API文档"}
|
| 173 |
|
| 174 |
if __name__ == "__main__":
|
| 175 |
uvicorn.run("main:app", host="0.0.0.0", port=7860, reload=True)
|
|
|
|
| 29 |
yield chunk
|
| 30 |
await asyncio.sleep(0.001) # 让出控制权,保持异步特性
|
| 31 |
|
| 32 |
+
@app.get("/")
|
| 33 |
+
async def root():
|
| 34 |
+
return {"message": "欢迎使用ScraperProxy API,访问 /docs 查看API文档"}
|
| 35 |
+
|
| 36 |
+
@app.api_route("/proxy", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "PATCH"])
|
| 37 |
+
async def proxy(request: Request):
|
| 38 |
"""
|
| 39 |
通用代理端点,转发所有请求到目标URL,支持流式响应
|
| 40 |
"""
|
|
|
|
| 42 |
# 获取请求方法
|
| 43 |
method = request.method
|
| 44 |
|
| 45 |
+
target_url = request.query_params.get("url")
|
| 46 |
if not target_url:
|
| 47 |
+
raise HTTPException(status_code=400, detail="必须提供目标URL")
|
|
|
|
|
|
|
| 48 |
|
|
|
|
| 49 |
# 检查是否请求流式响应
|
| 50 |
stream_request = "stream" in request.query_params and request.query_params["stream"].lower() in ["true", "1", "yes"]
|
| 51 |
|
|
|
|
| 168 |
except Exception as e:
|
| 169 |
raise HTTPException(status_code=500, detail=f"代理请求失败: {str(e)}")
|
| 170 |
|
| 171 |
+
|
|
|
|
|
|
|
| 172 |
|
| 173 |
if __name__ == "__main__":
|
| 174 |
uvicorn.run("main:app", host="0.0.0.0", port=7860, reload=True)
|