MCPcopy Index your code
hub / github.com/Tong89/smartNode / scenario_export

Function scenario_export

backend/api.py:924–955  ·  view source on GitHub ↗

导出最近一次保存的场景为 JSON 或 YAML 文件。 查询参数:``format=json``(默认)或 ``format=yaml``

()

Source from the content-addressed store, hash-verified

922
923@app.route('/api/scenario/export', methods=['GET'])
924def scenario_export():
925 """导出最近一次保存的场景为 JSON 或 YAML 文件。
926
927 查询参数:``format=json``(默认)或 ``format=yaml``
928 """
929 if _saved_scene is None:
930 return error_response("NOT_FOUND", "尚未保存任何场景,请先调用 /api/scenario/save")
931 fmt = request.args.get("format", "json").lower().strip()
932 if fmt == "yaml":
933 try:
934 content = _ScenarioManager.to_yaml(_saved_scene)
935 except Exception:
936 logger.exception("YAML 导出失败")
937 return error_response("INTERNAL_ERROR")
938 return app.response_class(
939 response=content,
940 status=200,
941 mimetype="application/x-yaml",
942 headers={"Content-Disposition": 'attachment; filename="scenario.yaml"'},
943 )
944 # 默认 JSON
945 try:
946 content = _ScenarioManager.to_json(_saved_scene)
947 except Exception:
948 logger.exception("JSON 导出失败")
949 return error_response("INTERNAL_ERROR")
950 return app.response_class(
951 response=content,
952 status=200,
953 mimetype="application/json",
954 headers={"Content-Disposition": 'attachment; filename="scenario.json"'},
955 )
956
957
958@app.route('/api/scenario/import', methods=['POST'])

Callers

nothing calls this directly

Calls 4

error_responseFunction · 0.90
to_yamlMethod · 0.80
getMethod · 0.45
to_jsonMethod · 0.45

Tested by

no test coverage detected