update_server.patch 944 B

1234567891011121314151617181920212223
  1. --- server.py
  2. +++ server.py
  3. @@ -2529,6 +2529,20 @@
  4. except Exception as e:
  5. raise HTTPException(status_code=502, detail=f"Failed to fetch pattern posts: {e}")
  6. +@app.get("/api/pattern/itemsets")
  7. +async def proxy_pattern_itemsets(execution_id: int):
  8. + """代理获取 itemsets,避免前端直接请求外部域名"""
  9. + try:
  10. + async with httpx.AsyncClient(timeout=30.0) as client:
  11. + resp = await client.get(
  12. + f"https://pattern.aiddit.com/api/pattern/itemsets?execution_id={execution_id}&page_size=1000",
  13. + )
  14. + resp.raise_for_status()
  15. + return resp.json()
  16. + except httpx.HTTPStatusError as e:
  17. + raise HTTPException(status_code=e.response.status_code, detail="Pattern itemsets API returned an error")
  18. + except Exception as e:
  19. + raise HTTPException(status_code=502, detail=f"Failed to fetch pattern itemsets: {e}")
  20. @app.get("/")
  21. def frontend():