43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, Header, HTTPException
|
|
|
|
from app.schemas.feishu_external import FeishuExternalQueryRequest
|
|
from app.services.feishu_service import FeishuService
|
|
from app.services.huobanyun_service import HuobanyunService
|
|
|
|
router = APIRouter()
|
|
feishu_service = FeishuService()
|
|
huobanyun_service = HuobanyunService()
|
|
|
|
|
|
@router.post("/feishu/approval/external-data/query")
|
|
async def feishu_external_query(
|
|
req: FeishuExternalQueryRequest, x_feishu_token: str | None = Header(default=None)
|
|
):
|
|
if not feishu_service.verify_token(x_feishu_token or req.token):
|
|
raise HTTPException(status_code=403, detail="invalid token")
|
|
result = await huobanyun_service.query(req)
|
|
options = result.get("options", [])
|
|
texts = result.get("texts", {})
|
|
has_more = result.get("has_more", False)
|
|
next_page_token = result.get("next_page_token", "")
|
|
return {
|
|
"code": 0,
|
|
"msg": "success!",
|
|
"data": {
|
|
"result": {
|
|
"options": options,
|
|
"i18nResources": [
|
|
{
|
|
"locale": "zh_cn",
|
|
"isDefault": True,
|
|
"texts": texts,
|
|
}
|
|
],
|
|
"hasMore": has_more,
|
|
"nextPageToken": next_page_token if has_more else "",
|
|
}
|
|
},
|
|
}
|