llmage/wwwroot/api/llm_api_map_delete.dspy
yumoqing 1060cac2de feat: llm_api_map CRUD management and ownerid-based data isolation
- Update json/llm.json subtable from llm_catelog_rel to llm_api_map
- Rewrite json/llm_api_map.json as standard CRUD format (tblname+params)
- Add models/llm_api_map.json table definition (summary/fields/indexes/codes)
- Add independent management UI (llm_api_map_manage.ui)
- Add CRUD DSPY APIs (list/create/delete/options) with ownerid filtering
- All operations verify l.ownerid for data isolation
- Add uapi_options.dspy for API selection dropdown
2026-05-20 17:29:27 +08:00

32 lines
1.3 KiB
Python

#!/usr/bin/env python3
import json
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
try:
dbname = get_module_dbname('llmage')
map_id = params_kw.get('id', '')
if not map_id:
result['options'] = {'title': 'Error', 'message': '缺少ID参数', 'type': 'error'}
else:
user_orgid = await get_userorgid()
async with DBPools().sqlorContext(dbname) as sor:
# 验证映射记录对应的模型属于当前用户的机构
check = await sor.sqlExe(
"""select m.id from llm_api_map m
join llm l on m.llmid = l.id
where m.id = ${id}$ and l.ownerid = ${ownerid}$""",
{'id': map_id, 'ownerid': user_orgid}
)
if not check:
result['options'] = {'title': 'Error', 'message': '无权删除该映射', 'type': 'error'}
else:
await sor.sqlExe("delete from llm_api_map where id = ${id}$", {'id': map_id})
result['options'] = {'title': 'Success', 'message': '删除成功', 'type': 'success'}
except Exception as e:
result['options'] = {'title': 'Error', 'message': f'删除失败: {str(e)}', 'type': 'error'}
return json.dumps(result, ensure_ascii=False)