Skip to content

Commit 869fb70

Browse files
perf: Assistant info api
1 parent cbc7bfa commit 869fb70

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

backend/apps/system/api/assistant.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,25 @@
1515
router = APIRouter(tags=["system/assistant"], prefix="/system/assistant")
1616

1717
@router.get("/info/{id}")
18-
async def info(request: Request, response: Response, session: SessionDep, id: int) -> dict:
18+
async def info(request: Request, response: Response, session: SessionDep, id: int) -> AssistantModel:
19+
if not id:
20+
raise Exception('miss assistant id')
1921
db_model = await get_assistant_info(session=session, assistant_id=id)
2022
if not db_model:
2123
raise RuntimeError(f"assistant application not exist")
2224
db_model = AssistantModel.model_validate(db_model)
2325
response.headers["Access-Control-Allow-Origin"] = db_model.domain
2426
origin = request.headers.get("origin") or request.headers.get("referer")
2527
origin = origin.rstrip('/')
26-
""" if origin != db_model.domain:
27-
raise RuntimeError("invalid domain [{origin}]") """
28-
return db_model.model_dump()
28+
if origin != db_model.domain:
29+
raise RuntimeError("invalid domain [{origin}]")
30+
return db_model
2931

3032
@router.get("/validator", response_model=AssistantValidator)
31-
async def info(session: SessionDep, id: str, virtual: Optional[int] = Query(None), online: Optional[bool] = Query(default=False)):
33+
async def validator(session: SessionDep, id: int, virtual: Optional[int] = Query(None)):
34+
if not id:
35+
raise Exception('miss assistant id')
36+
3237
db_model = await get_assistant_info(session=session, assistant_id=id)
3338
if not db_model:
3439
return AssistantValidator()

frontend/src/views/embedded/index.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ onMounted(() => {
9393
})
9494
onBeforeMount(async () => {
9595
const assistantId = route.query.id
96+
if (!assistantId) {
97+
ElMessage.error('Miss assistant id, please check assistant url')
98+
return
99+
}
96100
const online = route.query.online
97101
setFormatOnline(online)
98102
const now = Date.now()

0 commit comments

Comments
 (0)