修改部分参数

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-05-08 01:16:40 +08:00
parent 40b8cc8023
commit a26f7214f9
30 changed files with 341 additions and 3206 deletions

View File

@@ -14,19 +14,19 @@ from app import i18n_dict
# import trimesh.repair
from app.utils.stl_simplifier import simplify_stl
from app.routes.admin_routes import get_gcode_dir
from app.utils.slice_engines import get_slicer_engine
from app.models import UserSession
from flask_login import logout_user
main_bp = Blueprint('main', __name__)
@main_bp.before_app_request
def check_user_session():
if current_user.is_authenticated and not current_user.is_guest:
from app.models import UserSession
session_token = session.get('user_session_token')
if session_token:
user_session = UserSession.query.filter_by(session_token=session_token).first()
if not user_session or not user_session.is_active:
from flask_login import logout_user
logout_user()
session.pop('user_session_token', None)
flash('Your session has been terminated.', 'warning')
@@ -305,8 +305,11 @@ def preview_gcode(file_id):
content = "".join(lines[:500]) # Preview first 500 lines
if line_count > 500:
content += f"\n... \n[Preview truncated. Total lines: {line_count}. Please download to view full file.]"
w, h, hd = get_bed_dimensions()
engine_name = SystemConfig.query.filter_by(key='slicer_engine').first()
if engine_name:
engine = get_slicer_engine(str(engine_name.value), current_app.config['PRINT_CONFIG_FOLDER'])
w, h, hd = engine.get_bed_dimensions()
configs = {c.key: c.value for c in SystemConfig.query.all()}
offset_x = float(configs.get('offset_x', '0.0'))
offset_y = float(configs.get('offset_y', '0.0'))
@@ -344,25 +347,17 @@ def delete_file(file_id):
# --- Auth Routes ---
def get_bed_dimensions():
try:
path = os.path.join(current_app.root_path, '..', 'print_config', 'printers', 'creality_ender3v3se.def.json')
with open(path, 'r', encoding='utf-8') as f:
data = json.load(f)
w = data['overrides']['machine_width']['default_value']
h = data['overrides']['machine_depth']['default_value']
hd = data['overrides']['machine_height']['default_value']
return w, h, hd
except:
return 200, 200, 200
@main_bp.route('/plater')
@login_required
def plater():
quota_mb, current_size = get_quota_info(current_user, 'gcode')
quota_exceeded = (quota_mb > 0 and current_size >= quota_mb * 1024 * 1024)
w, h, hd = get_bed_dimensions()
engine_name = SystemConfig.query.filter_by(key='slicer_engine').first()
if engine_name:
engine = get_slicer_engine(str(engine_name.value), current_app.config['PRINT_CONFIG_FOLDER'])
w, h, hd = engine.get_bed_dimensions()
print(f"Bed dimensions: {w}x{h}x{hd}")
configs = {c.key: c.value for c in SystemConfig.query.all()}
@@ -574,12 +569,12 @@ def build_plate_model():
@main_bp.route('/api/engine_options/<engine_name>')
@login_required
def engine_options(engine_name):
from app.utils.slice_engines import get_slicer_engine
engine = get_slicer_engine(engine_name)
presets = engine.get_quality_presets(current_app)
patterns = engine.get_support_patterns(current_app)
materials = engine.get_materials(current_app) if hasattr(engine, 'get_materials') else []
return jsonify({'presets': presets, 'support_patterns': patterns, 'materials': materials})
engine = get_slicer_engine(engine_name, current_app.config['PRINT_CONFIG_FOLDER'])
presets = engine.get_quality_presets()
patterns = engine.get_support_patterns()
materials = engine.get_materials() if hasattr(engine, 'get_materials') else []
printers = engine.get_all_printers() if hasattr(engine, 'get_all_printers') else []
return jsonify({'presets': presets, 'support_patterns': patterns, 'materials': materials, 'printers': printers})
@main_bp.route('/account', methods=['GET', 'POST'])
@login_required