将内存中的快照以 JSON 文件形式下载。
()
| 1353 | |
| 1354 | @app.route('/api/snapshot/export', methods=['GET']) |
| 1355 | def snapshot_export(): |
| 1356 | """将内存中的快照以 JSON 文件形式下载。""" |
| 1357 | if _saved_snapshot is None: |
| 1358 | return error_response("NOT_FOUND", "尚未保存任何快照,请先调用 /api/snapshot/save") |
| 1359 | try: |
| 1360 | content = _SnapshotManager.to_json(_saved_snapshot) |
| 1361 | except Exception: |
| 1362 | logger.exception("快照导出失败") |
| 1363 | return error_response("INTERNAL_ERROR") |
| 1364 | label = (_saved_snapshot.get("label") or "snapshot").replace(" ", "_")[:32] |
| 1365 | filename = f"{label}.snapshot.json" |
| 1366 | return app.response_class( |
| 1367 | response=content, |
| 1368 | status=200, |
| 1369 | mimetype="application/json", |
| 1370 | headers={"Content-Disposition": f'attachment; filename="{filename}"'}, |
| 1371 | ) |
| 1372 | |
| 1373 | |
| 1374 | @app.route('/api/snapshot/import', methods=['POST']) |
nothing calls this directly
no test coverage detected