补充遗漏翻译,新增启动脚本,整理import
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import functools
|
||||
from flask import Blueprint, request, jsonify
|
||||
from app.models import ApiKey
|
||||
from app.models import ApiKey, PrintFile, SystemConfig
|
||||
from app.utils.octoprint_client import OctoPrintClient
|
||||
from app.models import SystemConfig
|
||||
|
||||
api_bp = Blueprint('api_handle', __name__, url_prefix='/api/v1')
|
||||
|
||||
@@ -13,6 +12,17 @@ def get_octo_client():
|
||||
return OctoPrintClient(url.value, apikey.value)
|
||||
return None
|
||||
|
||||
def _enrich_job_data(job_data):
|
||||
if job_data and job_data.get('job', {}).get('file', {}).get('name'):
|
||||
internal_name = job_data['job']['file']['name']
|
||||
internal_stl_name = str(internal_name)[:-5]+"stl"
|
||||
pf = PrintFile.query.filter_by(filename=internal_stl_name).first()
|
||||
if pf:
|
||||
job_data['job']['file']['display_name'] = pf.original_filename
|
||||
else:
|
||||
job_data['job']['file']['display_name'] = internal_name
|
||||
return job_data
|
||||
|
||||
def require_api_key(f):
|
||||
@functools.wraps(f)
|
||||
def decorated(*args, **kwargs):
|
||||
@@ -30,15 +40,60 @@ def require_api_key(f):
|
||||
@api_bp.route('/status', methods=['GET'])
|
||||
@require_api_key
|
||||
def get_status():
|
||||
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()
|
||||
return jsonify({'status': status_data, 'job': job_data})
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)}), 500
|
||||
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
|
||||
|
||||
@api_bp.route('/octoprint_client', methods=['POST'])
|
||||
@require_api_key
|
||||
|
||||
@@ -143,7 +143,6 @@ class ConfParse:
|
||||
if evaluated != field_val and not isinstance(evaluated, type):
|
||||
if val_dict.get("type") == "str" and not isinstance(evaluated, str):
|
||||
if isinstance(evaluated, (list, dict)):
|
||||
import json
|
||||
val_dict[field] = json.dumps(evaluated).replace(" ", "")
|
||||
else:
|
||||
val_dict[field] = str(evaluated)
|
||||
|
||||
@@ -4,6 +4,7 @@ import json
|
||||
import uuid
|
||||
import configparser
|
||||
from app.utils.conf_parse import ConfParse
|
||||
from app.models import SystemConfig
|
||||
|
||||
class CuraEngine:
|
||||
def __init__(self, print_config_folder=None):
|
||||
@@ -44,8 +45,6 @@ class CuraEngine:
|
||||
env = os.environ.copy()
|
||||
env["CURA_ENGINE_SEARCH_PATH"] = f"{printers_path}:{extruders_path}:{materials_path}:{presets_path}:{variants_path}"
|
||||
|
||||
|
||||
from app.models import SystemConfig
|
||||
db_printer = SystemConfig.query.filter_by(key='default_printer').first()
|
||||
p_val = db_printer.value if db_printer and db_printer.value else 'creality_ender3v3se.def.json'
|
||||
if not p_val.endswith('.def.json'): p_val += '.def.json'
|
||||
@@ -232,8 +231,6 @@ class CuraEngine:
|
||||
return []
|
||||
|
||||
def get_bed_dimensions(self):
|
||||
from app.models import SystemConfig
|
||||
import json
|
||||
try:
|
||||
db_printer = SystemConfig.query.filter_by(key='default_printer').first()
|
||||
p_val = db_printer.value if db_printer and db_printer.value else 'creality_ender3v3se.def.json'
|
||||
|
||||
@@ -2,6 +2,7 @@ import os
|
||||
import subprocess
|
||||
import configparser
|
||||
import uuid
|
||||
from app.models import SystemConfig
|
||||
|
||||
class PrusaSlicerEngine:
|
||||
def __init__(self, print_config_folder=None):
|
||||
@@ -47,8 +48,6 @@ class PrusaSlicerEngine:
|
||||
|
||||
# print(support_pattern)
|
||||
all_configs = {}
|
||||
|
||||
from app.models import SystemConfig
|
||||
db_printer = SystemConfig.query.filter_by(key='default_printer').first()
|
||||
p_val = db_printer.value if db_printer and db_printer.value else 'Ender3_V3_SE'
|
||||
if not p_val.endswith('.ini'): p_val += '.ini'
|
||||
@@ -156,8 +155,6 @@ class PrusaSlicerEngine:
|
||||
|
||||
|
||||
def get_bed_dimensions(self):
|
||||
from app.models import SystemConfig
|
||||
import configparser
|
||||
try:
|
||||
db_printer = SystemConfig.query.filter_by(key='default_printer').first()
|
||||
p_val = db_printer.value if db_printer and db_printer.value else 'Ender3_V3_SE.ini'
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
from huey import SqliteHuey
|
||||
import subprocess
|
||||
import os
|
||||
from app.models import db, PrintFile, SystemConfig
|
||||
from app.utils.conf_parse import ConfParse
|
||||
import json
|
||||
import uuid
|
||||
import configparser
|
||||
from huey import SqliteHuey
|
||||
from app import create_app
|
||||
from app.models import db, PrintFile, SystemConfig
|
||||
from app.utils.conf_parse import ConfParse
|
||||
from app.utils.slice_engines import get_slicer_engine
|
||||
from app.utils.stl_merger import merge_stls
|
||||
from app.utils.stl_simplifier import simplify_stl
|
||||
|
||||
import os
|
||||
|
||||
# Ensure instance directory exists
|
||||
instance_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), '..', 'instance')
|
||||
@@ -29,7 +31,6 @@ def get_gcode_dir(app):
|
||||
def slice_stl_task(file_id, stl_filepath, quality_preset=None, material_preset=None, infill_density=None, support_enable=None, support_pattern=None, delete_stl=False):
|
||||
# This is run by the Huey worker
|
||||
# We need to create an app context to interact with the database
|
||||
from app import create_app
|
||||
app = create_app()
|
||||
with app.app_context():
|
||||
print_file = PrintFile.query.get(file_id)
|
||||
@@ -95,10 +96,8 @@ def slice_stl_task(file_id, stl_filepath, quality_preset=None, material_preset=N
|
||||
|
||||
@huey.task()
|
||||
def merge_and_slice_task(file_id, inputs, merged_filepath, quality_preset=None, material_preset=None, infill_density=None, support_enable=None, support_pattern=None, delete_stl=False):
|
||||
from app import create_app
|
||||
app = create_app()
|
||||
with app.app_context():
|
||||
from app.models import PrintFile, db
|
||||
print_file = PrintFile.query.get(file_id)
|
||||
if not print_file:
|
||||
return
|
||||
@@ -106,7 +105,6 @@ def merge_and_slice_task(file_id, inputs, merged_filepath, quality_preset=None,
|
||||
db.session.remove()
|
||||
|
||||
try:
|
||||
from app.utils.stl_merger import merge_stls
|
||||
merge_stls(inputs, merged_filepath)
|
||||
|
||||
# Now trigger the regular slicing task
|
||||
@@ -123,13 +121,8 @@ def merge_and_slice_task(file_id, inputs, merged_filepath, quality_preset=None,
|
||||
|
||||
@huey.task()
|
||||
def simplify_stl_task(file_id, filepath):
|
||||
from app import create_app
|
||||
app = create_app()
|
||||
with app.app_context():
|
||||
from app.models import PrintFile, SystemConfig, db
|
||||
import os
|
||||
from app.utils.stl_simplifier import simplify_stl
|
||||
|
||||
print_file = PrintFile.query.get(file_id)
|
||||
if not print_file:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user