Skip to content

Commit c2ebcf2

Browse files
feat: Add a verification interface for the assistant
1 parent 016b803 commit c2ebcf2

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

backend/apps/system/api/assistant.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,26 @@ async def ui(session: SessionDep, data: str = Form(), files: List[UploadFile] =
221221
async def clear_ui_cache(id: int):
222222
pass
223223

224+
@router.get("/validate/{id}", include_in_schema=False)
225+
async def validate(request: Request, response: Response, session: SessionDep, trans: Trans, id: int):
226+
if not id:
227+
raise Exception('miss assistant id')
228+
db_model = session.get(AssistantModel, id)
229+
if not db_model:
230+
raise RuntimeError(f"assistant application not exist")
231+
232+
origin = request.headers.get("origin") or get_origin_from_referer(request)
233+
if not origin:
234+
raise RuntimeError(trans('i18n_embedded.invalid_origin', origin=origin or ''))
235+
origin = origin.rstrip('/')
236+
237+
if not origin_match_domain(origin, db_model.domain):
238+
raise RuntimeError(trans('i18n_embedded.invalid_origin', origin=origin or ''))
239+
240+
response.headers["Access-Control-Allow-Origin"] = origin
241+
return {"valid": True, "origin": origin}
242+
243+
224244
@router.get("/ds", include_in_schema=False, response_model=list[dict])
225245
async def ds(session: SessionDep, current_assistant: CurrentAssistant):
226246
if current_assistant.type == 0:

backend/common/utils/whitelist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
"/sse",
3030
"/system/appearance/ui",
3131
"/system/appearance/picture/*",
32-
"/system/assistant/validator*",
3332
"/system/assistant/info/*",
3433
"/system/assistant/app/*",
3534
"/system/assistant/picture/*",
35+
"/system/assistant/validate/*",
3636
"/system/authentication/platform/status",
3737
"/system/authentication/login/*",
3838
"/system/authentication/sso/*",

0 commit comments

Comments
 (0)