|
3 | 3 | from fastapi.responses import JSONResponse |
4 | 4 |
|
5 | 5 | from jesse.services import auth as authenticator |
6 | | -from jesse.services.web import FeedbackRequestJson, ReportExceptionRequestJson |
| 6 | +from jesse.services.web import FeedbackRequestJson, ReportExceptionRequestJson, HelpSearchRequestJson |
7 | 7 | from jesse.services.multiprocessing import process_manager |
8 | 8 | import jesse.helpers as jh |
9 | 9 |
|
@@ -79,3 +79,41 @@ def active_workers(authorization: Optional[str] = Header(None)) -> JSONResponse: |
79 | 79 | return JSONResponse({ |
80 | 80 | 'data': list(process_manager.active_workers) |
81 | 81 | }, status_code=200) |
| 82 | + |
| 83 | + |
| 84 | +@router.post("/help-search") |
| 85 | +def help_search(json_request: HelpSearchRequestJson, authorization: Optional[str] = Header(None)) -> JSONResponse: |
| 86 | + """ |
| 87 | + Proxy endpoint for help center search to avoid CORS issues |
| 88 | + """ |
| 89 | + if not authenticator.is_valid_token(authorization): |
| 90 | + return authenticator.unauthorized_response() |
| 91 | + |
| 92 | + import requests |
| 93 | + from jesse.info import JESSE_API_URL |
| 94 | + from jesse.services.auth import get_access_token |
| 95 | + |
| 96 | + try: |
| 97 | + url = f'{JESSE_API_URL}/help/search?item={json_request.query}' |
| 98 | + |
| 99 | + access_token = get_access_token() |
| 100 | + headers = { |
| 101 | + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', |
| 102 | + 'Accept': 'application/json, text/plain, */*' |
| 103 | + } |
| 104 | + |
| 105 | + if access_token: |
| 106 | + headers['Authorization'] = f'Bearer {access_token}' |
| 107 | + |
| 108 | + res = requests.get(url, headers=headers, timeout=10) |
| 109 | + |
| 110 | + if res.status_code == 200: |
| 111 | + return JSONResponse(res.json(), status_code=200) |
| 112 | + else: |
| 113 | + return JSONResponse({ |
| 114 | + 'error': f'Search request failed with status {res.status_code}' |
| 115 | + }, status_code=res.status_code) |
| 116 | + except Exception as e: |
| 117 | + return JSONResponse({ |
| 118 | + 'error': str(e) |
| 119 | + }, status_code=500) |
0 commit comments