28 lines
1.4 KiB
Plaintext
28 lines
1.4 KiB
Plaintext
# 场景导入(REST POST /api/scene_import.dspy)
|
||
# 参数:world_id(目标世界)+ file(上传文件,multipart)或 rows(JSON 数组)
|
||
# 返回:{status, data:{success,total,success_count,fail}};错误 {code,message,field,detail}
|
||
debug(f'scene_import.dspy: START params_kw keys={list((params_kw or {}).keys())}')
|
||
params = dict(params_kw or {})
|
||
world_id = (params.get('world_id') or '').strip()
|
||
file_name = params.get('file_name') or ''
|
||
file_obj = params.get('file')
|
||
rows = params.get('rows')
|
||
|
||
if file_obj is not None:
|
||
try:
|
||
content = file_obj.read()
|
||
except Exception:
|
||
content = file_obj
|
||
parsed = parse_scene_file(content, file_name)
|
||
if 'rows' not in parsed:
|
||
return {'status': 'error', 'data': parsed}
|
||
result = await import_scenes({'world_id': world_id, 'file_name': file_name, 'rows': parsed['rows']})
|
||
else:
|
||
if not isinstance(rows, list):
|
||
return {'status': 'error', 'data': {'code': 'PARAM_REQUIRED', 'message': '缺少导入数据(file 或 rows)', 'field': 'rows', 'detail': ''}}
|
||
result = await import_scenes({'world_id': world_id, 'file_name': file_name, 'rows': rows})
|
||
|
||
if result.get('success'):
|
||
return {'status': 'ok', 'data': {'success': True, 'total': result.get('total', 0), 'success_count': result.get('success_count', 0), 'fail': result.get('fail', 0)}}
|
||
return {'status': 'error', 'data': result}
|