fix: use exact match instead of LIKE for api_key lookup, reuse ids branch flow
This commit is contained in:
@@ -74,19 +74,16 @@ def list_apps(
|
||||
workspace_id = current_user.current_workspace_id
|
||||
service = app_service.AppService(db)
|
||||
|
||||
# 通过 API Key 搜索:查出关联的 app id,复用 ids 分支返回
|
||||
# 通过 API Key 搜索:精确匹配,将 resource_id 注入 ids 走统一分页流程
|
||||
if api_key:
|
||||
matched = db.execute(
|
||||
matched_id = db.execute(
|
||||
sa_select(ApiKey.resource_id).where(
|
||||
ApiKey.workspace_id == workspace_id,
|
||||
ApiKey.api_key.like(f"%{api_key}%"),
|
||||
ApiKey.api_key == api_key,
|
||||
ApiKey.resource_id.isnot(None),
|
||||
)
|
||||
).scalars().all()
|
||||
app_ids = [str(rid) for rid in matched]
|
||||
items_orm = app_service.get_apps_by_ids(db, app_ids, workspace_id) if app_ids else []
|
||||
items = [service._convert_to_schema(app, workspace_id) for app in items_orm]
|
||||
return success(data=items)
|
||||
).scalar_one_or_none()
|
||||
ids = str(matched_id) if matched_id else ""
|
||||
|
||||
# 当 ids 存在且不为 None 时,根据 ids 获取应用
|
||||
if ids is not None:
|
||||
|
||||
Reference in New Issue
Block a user