Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions backend/apps/system/api/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,26 @@ async def ui(session: SessionDep, data: str = Form(), files: List[UploadFile] =
async def clear_ui_cache(id: int):
pass

@router.get("/validate/{id}", include_in_schema=False)
async def validate(request: Request, response: Response, session: SessionDep, trans: Trans, id: int):
if not id:
raise Exception('miss assistant id')
db_model = session.get(AssistantModel, id)
if not db_model:
raise RuntimeError(f"assistant application not exist")

origin = request.headers.get("origin") or get_origin_from_referer(request)
if not origin:
raise RuntimeError(trans('i18n_embedded.invalid_origin', origin=origin or ''))
origin = origin.rstrip('/')

if not origin_match_domain(origin, db_model.domain):
raise RuntimeError(trans('i18n_embedded.invalid_origin', origin=origin or ''))

response.headers["Access-Control-Allow-Origin"] = origin
return {"valid": True, "origin": origin}


@router.get("/ds", include_in_schema=False, response_model=list[dict])
async def ds(session: SessionDep, current_assistant: CurrentAssistant):
if current_assistant.type == 0:
Expand Down
2 changes: 1 addition & 1 deletion backend/common/utils/whitelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"/sse",
"/system/appearance/ui",
"/system/appearance/picture/*",
"/system/assistant/validator*",
"/system/assistant/info/*",
"/system/assistant/app/*",
"/system/assistant/picture/*",
"/system/assistant/validate/*",
"/system/authentication/platform/status",
"/system/authentication/login/*",
"/system/authentication/sso/*",
Expand Down
Loading