补充遗漏翻译,新增启动脚本,整理import
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
import json
|
||||
import trimesh
|
||||
import uuid
|
||||
import os
|
||||
import configparser
|
||||
import secrets
|
||||
from datetime import datetime
|
||||
from flask import Blueprint, render_template, request, redirect, url_for, flash, current_app, session, make_response, send_file, abort, jsonify
|
||||
from flask_login import login_user, logout_user, login_required, current_user
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
from werkzeug.utils import secure_filename
|
||||
from app.models import db, User, PrintFile, SystemConfig
|
||||
from app.models import db, User, PrintFile, SystemConfig, ApiKey
|
||||
from app.utils.tasks import merge_and_slice_task, slice_stl_task, simplify_stl_task
|
||||
from app import i18n_dict
|
||||
# import trimesh.repair
|
||||
from app.utils.stl_simplifier import simplify_stl
|
||||
from app.utils.slice_engines import get_all_engines
|
||||
|
||||
@@ -194,14 +193,11 @@ def delete_user(user_id):
|
||||
|
||||
@admin_bp.route('/api_keys')
|
||||
def api_keys():
|
||||
from app.models import ApiKey
|
||||
keys = ApiKey.query.order_by(ApiKey.created_at.desc()).all()
|
||||
return render_template('admin/api_keys.html', keys=keys)
|
||||
|
||||
@admin_bp.route('/api_key/add', methods=['POST'])
|
||||
def add_api_key():
|
||||
from app.models import ApiKey
|
||||
import secrets
|
||||
name = request.form.get('name')
|
||||
if not name:
|
||||
flash("Name is required", "danger")
|
||||
@@ -216,7 +212,6 @@ def add_api_key():
|
||||
|
||||
@admin_bp.route('/api_key/<int:key_id>/delete', methods=['POST'])
|
||||
def delete_api_key(key_id):
|
||||
from app.models import ApiKey
|
||||
key = ApiKey.query.get_or_404(key_id)
|
||||
db.session.delete(key)
|
||||
db.session.commit()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import json
|
||||
import trimesh
|
||||
import uuid
|
||||
import os
|
||||
import configparser
|
||||
@@ -8,11 +7,12 @@ from flask import Blueprint, render_template, request, redirect, url_for, flash,
|
||||
from flask_login import login_user, logout_user, login_required, current_user
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
from werkzeug.utils import secure_filename
|
||||
from app.models import db, User, PrintFile, SystemConfig
|
||||
from app.models import db, User, PrintFile, SystemConfig, UserSession
|
||||
from app.utils.tasks import merge_and_slice_task, slice_stl_task, simplify_stl_task
|
||||
from app import i18n_dict
|
||||
# import trimesh.repair
|
||||
from app.utils.stl_simplifier import simplify_stl
|
||||
from app.routes.main_routes import get_quota_info
|
||||
from app.routes.admin_routes import get_gcode_dir
|
||||
|
||||
|
||||
main_bp = Blueprint('main', __name__)
|
||||
@@ -36,8 +36,6 @@ def login():
|
||||
|
||||
if user and check_password_hash(user.password_hash, password):
|
||||
login_user(user, remember=remember)
|
||||
|
||||
from app.models import UserSession
|
||||
session_token = str(uuid.uuid4())
|
||||
# 尝试获取反向代理传递的真实 IP
|
||||
client_ip = request.headers.get('X-Real-IP')
|
||||
@@ -59,7 +57,6 @@ def login():
|
||||
if guest_id:
|
||||
guest_user = User.query.filter_by(guest_cookie_id=guest_id, is_guest=True).first()
|
||||
if guest_user:
|
||||
from app.routes.main_routes import get_quota_info
|
||||
guest_files = PrintFile.query.filter_by(user_id=guest_user.id).all()
|
||||
|
||||
stl_quota, stl_used = get_quota_info(user, 'stl')
|
||||
@@ -68,7 +65,6 @@ def login():
|
||||
stl_quota_bytes = stl_quota * 1024 * 1024 if stl_quota > 0 else float('inf')
|
||||
gcode_quota_bytes = gcode_quota * 1024 * 1024 if gcode_quota > 0 else float('inf')
|
||||
|
||||
from app.routes.admin_routes import get_gcode_dir
|
||||
upload_dir = current_app.config.get('UPLOAD_FOLDER', 'uploads')
|
||||
gcode_dir = get_gcode_dir()
|
||||
|
||||
@@ -135,7 +131,6 @@ def login():
|
||||
def logout():
|
||||
session_token = session.get('user_session_token')
|
||||
if session_token:
|
||||
from app.models import UserSession
|
||||
user_session = UserSession.query.filter_by(session_token=session_token).first()
|
||||
if user_session:
|
||||
user_session.is_active = False
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import json
|
||||
import trimesh
|
||||
import uuid
|
||||
import os
|
||||
import configparser
|
||||
@@ -8,15 +7,13 @@ from flask import Blueprint, render_template, request, redirect, url_for, flash,
|
||||
from flask_login import login_user, logout_user, login_required, current_user
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
from werkzeug.utils import secure_filename
|
||||
from app.models import db, User, PrintFile, SystemConfig
|
||||
from app.models import db, User, PrintFile, SystemConfig, UserSession
|
||||
from app.utils.tasks import merge_and_slice_task, slice_stl_task, simplify_stl_task
|
||||
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
|
||||
from app.utils.gcode_parser import get_gcode_metadata
|
||||
|
||||
main_bp = Blueprint('main', __name__)
|
||||
|
||||
@@ -90,6 +87,8 @@ def check_quota(user, file_type, size_bytes):
|
||||
# Guest User Middleware
|
||||
@main_bp.before_app_request
|
||||
def assign_guest_cookie():
|
||||
if request.path.startswith('/api/'):
|
||||
return
|
||||
if not current_user.is_authenticated:
|
||||
guest_id = request.cookies.get('guest_id')
|
||||
if not guest_id:
|
||||
@@ -304,7 +303,6 @@ def preview_gcode(file_id):
|
||||
filament_used = "-"
|
||||
|
||||
if os.path.exists(filepath):
|
||||
from app.utils.gcode_parser import get_gcode_metadata
|
||||
metadata = get_gcode_metadata(filepath)
|
||||
time_info = metadata.get('print_time', '-')
|
||||
layer1_time = metadata.get('first_layer_time', '-')
|
||||
@@ -595,8 +593,6 @@ def account():
|
||||
flash('Guests cannot manage accounts.', 'danger')
|
||||
return redirect(url_for('main.index'))
|
||||
|
||||
from app.models import UserSession
|
||||
|
||||
if request.method == 'POST':
|
||||
action = request.form.get('action')
|
||||
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
from flask import Blueprint, render_template, request, jsonify, flash, redirect, url_for, current_app, Response
|
||||
from flask_login import login_required, current_user
|
||||
from websockets.sync.client import connect as ws_connect
|
||||
import os
|
||||
import websockets.exceptions
|
||||
import threading
|
||||
import requests
|
||||
from urllib.parse import urlparse
|
||||
from app.models import SystemConfig, db
|
||||
import uuid
|
||||
import traceback
|
||||
from werkzeug.utils import secure_filename
|
||||
from flask import Blueprint, render_template, request, jsonify, flash, redirect, url_for, current_app, Response
|
||||
from flask_login import login_required, current_user
|
||||
from flask_sock import Server, ConnectionClosed
|
||||
from websockets.sync.client import connect as ws_connect
|
||||
from urllib.parse import urlparse, urlencode
|
||||
from app.models import SystemConfig, db, PrintFile
|
||||
from app.utils.octoprint_client import OctoPrintClient
|
||||
from app.models import PrintFile
|
||||
import os
|
||||
from app.utils.gcode_parser import get_gcode_metadata
|
||||
|
||||
printer_bp = Blueprint('printer', __name__, url_prefix='/printer')
|
||||
|
||||
@@ -21,17 +25,17 @@ def get_octo_client():
|
||||
|
||||
def _enrich_job_data(job_data):
|
||||
if job_data and job_data.get('job', {}).get('file', {}).get('name'):
|
||||
from app.models import PrintFile
|
||||
internal_name = job_data['job']['file']['name']
|
||||
internal_stl_name = str(internal_name)[:-5]+"stl"
|
||||
user_files = {}
|
||||
print_file = None
|
||||
for f in PrintFile.query.filter_by(user_id=current_user.id, status='sliced').all():
|
||||
user_files[f.filename] = f.original_filename
|
||||
if internal_stl_name in user_files.keys():
|
||||
print_file = user_files[str(internal_name)[:-5]+"stl"]
|
||||
if print_file:
|
||||
job_data['job']['file']['display_name'] = print_file
|
||||
if current_user.is_authenticated and current_user.is_admin:
|
||||
pf = PrintFile.query.filter_by(filename=internal_stl_name).first()
|
||||
elif current_user.is_authenticated:
|
||||
pf = PrintFile.query.filter_by(filename=internal_stl_name, user_id=current_user.id).first()
|
||||
else:
|
||||
pf = None
|
||||
|
||||
if pf:
|
||||
job_data['job']['file']['display_name'] = pf.original_filename
|
||||
else:
|
||||
job_data['job']['file']['display_name'] = internal_name
|
||||
return job_data
|
||||
@@ -81,9 +85,6 @@ def get_gcode_dir():
|
||||
@printer_bp.route('/prepare')
|
||||
@login_required
|
||||
def prepare():
|
||||
from app.models import PrintFile
|
||||
import os
|
||||
from app.utils.gcode_parser import get_gcode_metadata
|
||||
|
||||
# Query only the sliced GCode files belonging to the current user
|
||||
user_files = PrintFile.query.filter_by(user_id=current_user.id, status='sliced').order_by(PrintFile.created_at.desc()).all()
|
||||
@@ -151,7 +152,6 @@ def prepare():
|
||||
|
||||
|
||||
def check_printer_control_permission(client):
|
||||
from flask_login import current_user
|
||||
if current_user.is_admin:
|
||||
return True, None
|
||||
|
||||
@@ -167,7 +167,6 @@ def check_printer_control_permission(client):
|
||||
if not internal_name:
|
||||
return False, "现在有任务正在运行,非管理员无法进行控制。"
|
||||
|
||||
from app.models import PrintFile
|
||||
pf = PrintFile.query.filter_by(filename=internal_name).first()
|
||||
if pf and pf.user_id == current_user.id:
|
||||
return True, None
|
||||
@@ -204,7 +203,6 @@ def control():
|
||||
try:
|
||||
raw_url = client.get_webcam_stream_url()
|
||||
# If it's an absolute url pointing to the base url, strip it or proxy it via octo_proxy
|
||||
from urllib.parse import urlparse, urlencode
|
||||
parsed_raw = urlparse(raw_url)
|
||||
base_config = SystemConfig.query.filter_by(key='octoprint_url').first()
|
||||
if base_config and base_config.value:
|
||||
@@ -256,11 +254,6 @@ def api_command():
|
||||
@printer_bp.route('/api/upload_gcode', methods=['POST'])
|
||||
@login_required
|
||||
def upload_gcode():
|
||||
from app.models import PrintFile
|
||||
import os
|
||||
import uuid
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
if 'file' not in request.files:
|
||||
return jsonify({"success": False, "error": "No file part"}), 400
|
||||
|
||||
@@ -366,8 +359,6 @@ def octo_proxy(path):
|
||||
|
||||
# --- WebSocket Proxy Logic ---
|
||||
if request.headers.get('Upgrade', '').lower() == 'websocket':
|
||||
from flask_sock import Server, ConnectionClosed
|
||||
|
||||
# Check if environment supports WebSockets
|
||||
try:
|
||||
ws = Server(request.environ)
|
||||
@@ -413,7 +404,6 @@ def octo_proxy(path):
|
||||
remote_ws = ws_connect(target_url, additional_headers=ws_headers)
|
||||
print("WS Proxy connected to remote.")
|
||||
except Exception as e:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
print(f"Remote WS Connection Error: {e}")
|
||||
ws.close(1011, str(e))
|
||||
@@ -473,7 +463,6 @@ def octo_proxy(path):
|
||||
return WebSocketResponse()
|
||||
|
||||
# --- Standard HTTP Proxy Logic ---
|
||||
# from urllib.parse import urlparse
|
||||
target_url = f"{base_url}/{path}"
|
||||
|
||||
if request.query_string:
|
||||
|
||||
Reference in New Issue
Block a user