From 211b628c7815059f39f544cd0236cac4d8db7305 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 29 May 2026 23:40:19 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20API=E5=93=8D=E5=BA=94=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E6=A0=87=E5=87=86=E6=A0=BC=E5=BC=8F{status,data},=20?= =?UTF-8?q?=E5=89=8D=E7=AB=AFForm=E5=88=86=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - rl_verify.dspy: 返回{status:ok/data:{id,h5_link,byted_token}} - rl_upload.dspy: 返回{status:ok/data:{id,vendor_asset_id,status}} - rl_query_groups.dspy: 返回{status:ok/data:{groups:[...]}} - rl_status.dspy: 返回{status:ok/data:{status,url}} - rl_callback.dspy: 返回{status:ok/data:{vendor_group_id}} - 新增submit_create_validate.dspy: 前端专用,返回bricks Message/Error widget - create_validate.ui: Form指向新dspy + submited事件绑定 - api_downapp.md: 文档同步更新 --- docs/api_downapp.md | 52 ++++++++++++++----------- wwwroot/api/rl_callback.dspy | 8 +++- wwwroot/api/rl_query_groups.dspy | 8 +++- wwwroot/api/rl_status.dspy | 19 ++++++++- wwwroot/api/rl_upload.dspy | 27 ++++++------- wwwroot/api/rl_verify.dspy | 38 ++++++------------ wwwroot/api/submit_create_validate.dspy | 42 ++++++++++++++++++++ wwwroot/create_validate.ui | 12 +++++- 8 files changed, 136 insertions(+), 70 deletions(-) create mode 100644 wwwroot/api/submit_create_validate.dspy diff --git a/docs/api_downapp.md b/docs/api_downapp.md index cc7c5e1..cc5c86c 100644 --- a/docs/api_downapp.md +++ b/docs/api_downapp.md @@ -48,17 +48,19 @@ Content-Type: application/json **成功**: ```json { - "success": true, - "id": "local_group_id_xxx", - "h5_link": "https://... (H5页面链接,120秒有效)", - "byted_token": "..." + "status": "ok", + "data": { + "id": "local_group_id_xxx", + "h5_link": "https://... (H5页面链接,120秒有效)", + "byted_token": "..." + } } ``` **失败**(未配置): ```json { - "success": false, - "message": "供应商配置不存在" + "status": "error", + "data": {"message": "供应商配置不存在"} } ``` @@ -84,15 +86,17 @@ Authorization: Bearer **成功**: ```json { - "success": true, - "groups": [ - { - "vendor_group_id": "volc-asset-group-xxx", - "vendor": "volcengine", - "status": "active", - "create_time": "2026-05-28 15:30:00" - } - ] + "status": "ok", + "data": { + "groups": [ + { + "vendor_group_id": "volc-asset-group-xxx", + "vendor": "volcengine", + "status": "active", + "create_time": "2026-05-28 15:30:00" + } + ] + } } ``` @@ -145,10 +149,12 @@ Content-Type: application/json **成功**: ```json { - "success": true, - "id": "asset_record_id_xxx", - "vendor_asset_id": "asset-2026...", - "status": "Processing" + "status": "ok", + "data": { + "id": "asset_record_id_xxx", + "vendor_asset_id": "asset-2026...", + "status": "Processing" + } } ``` @@ -183,9 +189,11 @@ Content-Type: application/json **成功**: ```json { - "success": true, - "status": "Active", - "url": "https://... (临时下载链接,12小时有效)" + "status": "ok", + "data": { + "status": "Active", + "url": "https://... (临时下载链接,12小时有效)" + } } ``` diff --git a/wwwroot/api/rl_callback.dspy b/wwwroot/api/rl_callback.dspy index 6f428d0..3cd7134 100644 --- a/wwwroot/api/rl_callback.dspy +++ b/wwwroot/api/rl_callback.dspy @@ -21,8 +21,12 @@ if not byted_token: byted_token = params_kw.get("BytedToken", params_kw.get("byted_token", "")) if not byted_token: - return {"success": False, "message": "缺少 BytedToken 参数"} + return json.dumps({"status": "error", "data": {"message": "缺少 BytedToken 参数"}}, ensure_ascii=False) # vendor is determined by looking up the session record result = await rl_handle_callback(byted_token, project_name="default") -return result + +if result.get('success'): + return json.dumps({"status": "ok", "data": {"vendor_group_id": result.get('vendor_group_id', '')}}, ensure_ascii=False) +else: + return json.dumps({"status": "error", "data": {"message": result.get('message', '回调处理失败')}}, ensure_ascii=False) diff --git a/wwwroot/api/rl_query_groups.dspy b/wwwroot/api/rl_query_groups.dspy index 129ae71..80b2259 100644 --- a/wwwroot/api/rl_query_groups.dspy +++ b/wwwroot/api/rl_query_groups.dspy @@ -1,4 +1,10 @@ +import json + org_id = (await get_userorgid()) or '0' result = await rl_query_groups(org_id) -return result + +if result.get('success'): + return json.dumps({"status": "ok", "data": {"groups": result.get('groups', [])}}, ensure_ascii=False) +else: + return json.dumps({"status": "error", "data": {"message": result.get('message', '查询失败')}}, ensure_ascii=False) diff --git a/wwwroot/api/rl_status.dspy b/wwwroot/api/rl_status.dspy index 94395c4..3e7169b 100644 --- a/wwwroot/api/rl_status.dspy +++ b/wwwroot/api/rl_status.dspy @@ -1,7 +1,22 @@ +import json + asset_id = params_kw.get('asset_id', '') if not asset_id: - return {"success": False, "message": "asset_id 不能为空"} + return json.dumps({"status": "error", "data": {"message": "asset_id 不能为空"}}, ensure_ascii=False) result = await rl_sync_asset_status_user((await get_userorgid()) or '0', asset_id, (await get_user())) -return result + +if result.get('success'): + return json.dumps({ + "status": "ok", + "data": { + "status": result.get('status', ''), + "url": result.get('url', ''), + } + }, ensure_ascii=False) +else: + return json.dumps({ + "status": "error", + "data": {"message": result.get('message', '查询失败')} + }, ensure_ascii=False) diff --git a/wwwroot/api/rl_upload.dspy b/wwwroot/api/rl_upload.dspy index 2941913..ddc3f08 100644 --- a/wwwroot/api/rl_upload.dspy +++ b/wwwroot/api/rl_upload.dspy @@ -6,19 +6,13 @@ asset_type = params_kw.get('asset_type', 'Image') name = params_kw.get('name', '') if not vendor_group_id or not source_url: - return json.dumps({ - "widgettype": "Message", - "options": {"message": "请选择认证组合并提供素材URL", "type": "error"} - }) + return json.dumps({"status": "error", "data": {"message": "请选择认证组合并提供素材URL"}}, ensure_ascii=False) # If source_url is base64 data or local path, convert to public URL if source_url.startswith('data:') or (not source_url.startswith('http') and len(source_url) < 8000): source_url = await b64media2url(request, source_url) if not source_url: - return json.dumps({ - "widgettype": "Message", - "options": {"message": "素材文件转换失败", "type": "error"} - }) + return json.dumps({"status": "error", "data": {"message": "素材文件转换失败"}}, ensure_ascii=False) org_id = (await get_userorgid()) or '0' user_id = (await get_user()) or '' @@ -26,13 +20,16 @@ user_id = (await get_user()) or '' result = await rl_upload_user(org_id, vendor_group_id, source_url, asset_type, name, user_id) if result.get('success'): - asset_id = result.get('vendor_asset_id', '') return json.dumps({ - "widgettype": "Message", - "options": {"message": f"素材上传成功!资产ID: {asset_id}", "type": "success"} - }) + "status": "ok", + "data": { + "id": result.get('id', ''), + "vendor_asset_id": result.get('vendor_asset_id', ''), + "status": result.get('status', 'Processing'), + } + }, ensure_ascii=False) else: return json.dumps({ - "widgettype": "Message", - "options": {"message": result.get('message', '上传失败'), "type": "error"} - }) + "status": "error", + "data": {"message": result.get('message', '上传失败')} + }, ensure_ascii=False) diff --git a/wwwroot/api/rl_verify.dspy b/wwwroot/api/rl_verify.dspy index 2a240e2..6916dcf 100644 --- a/wwwroot/api/rl_verify.dspy +++ b/wwwroot/api/rl_verify.dspy @@ -1,41 +1,27 @@ import json vendor = params_kw.get('vendor', '') +project_name = params_kw.get('project_name', 'default') if not vendor: - return json.dumps({ - "widgettype": "Message", - "options": {"message": "请选择供应商", "type": "error"} - }) + return json.dumps({"status": "error", "data": {"message": "请选择供应商"}}, ensure_ascii=False) org_id = (await get_userorgid()) or '0' user_id = (await get_user()) or '' -project_name = "default" result = await rl_verify_user(org_id, user_id, vendor, project_name) if result.get('success'): - h5_link = result.get('h5_link', '') - msg = "认证会话已创建,请在新窗口中完成真人认证" return json.dumps({ - "widgettype": "Message", - "options": {"title": "真人认证", "message": msg}, - "subwidgets": [ - { - "widgettype": "Button", - "options": { - "label": "打开认证页面", - "action": { - "actiontype": "urlwidget", - "target": "NewWindow", - "url": h5_link - } - } - } - ] - }) + "status": "ok", + "data": { + "id": result.get('id', ''), + "h5_link": result.get('h5_link', ''), + "byted_token": result.get('byted_token', ''), + } + }, ensure_ascii=False) else: return json.dumps({ - "widgettype": "Message", - "options": {"message": result.get('message', '认证创建失败'), "type": "error"} - }) + "status": "error", + "data": {"message": result.get('message', '认证创建失败')} + }, ensure_ascii=False) diff --git a/wwwroot/api/submit_create_validate.dspy b/wwwroot/api/submit_create_validate.dspy new file mode 100644 index 0000000..5779441 --- /dev/null +++ b/wwwroot/api/submit_create_validate.dspy @@ -0,0 +1,42 @@ +import json + +vendor = params_kw.get('vendor', '') + +if not vendor: + return json.dumps({ + "widgettype": "Error", + "options": {"title": "错误", "message": "请选择供应商"} + }) + +org_id = (await get_userorgid()) or '0' +user_id = (await get_user()) or '' +project_name = "default" + +result = await rl_verify_user(org_id, user_id, vendor, project_name) + +if result.get('success'): + h5_link = result.get('h5_link', '') + return json.dumps({ + "widgettype": "Message", + "options": {"title": "真人认证", "message": "认证会话已创建,请点击按钮在新窗口中完成真人认证"}, + "subwidgets": [ + { + "widgettype": "Button", + "options": {"label": "打开认证页面"}, + "binds": [ + { + "wid": "self", + "event": "click", + "actiontype": "script", + "target": "self", + "script": "window.open('" + h5_link + "', '_blank')" + } + ] + } + ] + }) +else: + return json.dumps({ + "widgettype": "Error", + "options": {"title": "错误", "message": result.get('message', '认证创建失败')} + }) diff --git a/wwwroot/create_validate.ui b/wwwroot/create_validate.ui index 91ed3da..4f3194f 100644 --- a/wwwroot/create_validate.ui +++ b/wwwroot/create_validate.ui @@ -24,7 +24,7 @@ "widgettype": "Form", "id": "validate_form", "options": { - "submit_url": "{{entire_url('api/rl_verify.dspy')}}", + "submit_url": "{{entire_url('api/submit_create_validate.dspy')}}", "fields": [ { "uitype": "code", @@ -36,7 +36,15 @@ "required": true } ] - } + }, + "binds": [ + { + "wid": "self", + "event": "submited", + "actiontype": "script", + "script": "await bricks.show_resp_message_or_error(event.params)" + } + ] } ] }