From 42e3050fa2056d4c3bf5a961f15d6d72c8b9eb6c Mon Sep 17 00:00:00 2001 From: lhye200 Date: Sat, 9 May 2026 16:44:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=81=97=E6=BC=8F=E7=9A=84ap?= =?UTF-8?q?i=20test=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/utils/api_handle.py | 64 +++++++---------------------------------- 1 file changed, 10 insertions(+), 54 deletions(-) diff --git a/app/utils/api_handle.py b/app/utils/api_handle.py index e74f251..40e03ff 100644 --- a/app/utils/api_handle.py +++ b/app/utils/api_handle.py @@ -40,60 +40,16 @@ def require_api_key(f): @api_bp.route('/status', methods=['GET']) @require_api_key def get_status(): - test_data = { - 'job': { - 'job': { - 'estimatedPrintTime': 1234, - 'filament': {'length': 765, 'volume': 24356}, - 'file': {'display_name': 'Test File','date': None, 'name': '20260414135441_42bff5215c6148b8b5f4d8c4f15d5ddc.gcode', 'origin': 'local', 'path': None, 'size': 1468987}, - 'lastPrintTime': None, - 'user': None - }, - 'progress': { - 'completion': 74.8, - 'filepos': 1234, - 'printTime': 1235, - 'printTimeLeft': 6353, - 'printTimeLeftOrigin': 5366 - }, - 'state': 'Operational' - }, - 'status': { - 'sd': {'ready': False}, - 'state': { - 'error': '', - 'flags': { - 'cancelling': False, - 'closedOrError': False, - 'error': False, - 'finishing': False, - 'operational': True, - 'paused': False, - 'pausing': False, - 'printing': False, - 'ready': True, - 'resuming': False, - 'sdReady': False - }, - 'text': 'Operational test' - }, - 'temperature': { - 'bed': {'actual': 85, 'offset': 0, 'target': 56}, - 'tool0': {'actual': 0.0, 'offset': 0, 'target': 340} - } - } - } - return jsonify(test_data) - # client = get_octo_client() - # if not client: - # return jsonify({'error': 'Printer not configured'}), 503 - # try: - # status_data = client.get_printer_status() - # job_data = client.get_job_info() - # job_data = _enrich_job_data(job_data) - # return jsonify({'status': status_data, 'job': job_data}) - # except Exception as e: - # return jsonify({'error': str(e)}), 500 + client = get_octo_client() + if not client: + return jsonify({'error': 'Printer not configured'}), 503 + try: + status_data = client.get_printer_status() + job_data = client.get_job_info() + job_data = _enrich_job_data(job_data) + return jsonify({'status': status_data, 'job': job_data}) + except Exception as e: + return jsonify({'error': str(e)}), 500 @api_bp.route('/octoprint_client', methods=['POST']) @require_api_key