Skip to content

Commit 4c5c758

Browse files
committed
Add help search endpoint to system controller and define HelpSearchRequestJson model
- Introduced a new POST endpoint `/help-search` in the system controller to facilitate help center searches while avoiding CORS issues. - Added HelpSearchRequestJson model to handle the request structure for help searches. - Implemented logic to validate authorization tokens and manage requests to the help center API, including error handling for failed requests.
1 parent 9945f55 commit 4c5c758

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

jesse/controllers/system_controller.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from fastapi.responses import JSONResponse
44

55
from jesse.services import auth as authenticator
6-
from jesse.services.web import FeedbackRequestJson, ReportExceptionRequestJson
6+
from jesse.services.web import FeedbackRequestJson, ReportExceptionRequestJson, HelpSearchRequestJson
77
from jesse.services.multiprocessing import process_manager
88
import jesse.helpers as jh
99

@@ -79,3 +79,41 @@ def active_workers(authorization: Optional[str] = Header(None)) -> JSONResponse:
7979
return JSONResponse({
8080
'data': list(process_manager.active_workers)
8181
}, 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)

jesse/services/web.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ class ReportExceptionRequestJson(BaseModel):
170170
email: Optional[str] = None
171171

172172

173+
class HelpSearchRequestJson(BaseModel):
174+
query: str
175+
176+
173177
class DeleteCandlesRequestJson(BaseModel):
174178
exchange: str
175179
symbol: str

0 commit comments

Comments
 (0)