Fix QZ Tray library loading and add pairing keys API endpoint
- Fix QZ Tray library loading errors (net::ERR_NAME_NOT_RESOLVED) by switching from CDN to local static file - Add /labels/api/pairing-keys endpoint to fetch valid printer pairing keys - Update print_labels.html to use local js/qz-tray.js - Update print_lost_labels.html to use local js/qz-tray.js - Update print_lost_labels_new.html to use correct path js/qz-tray.js - Update fg_scan.html to use local js/qz-tray.js - API returns active pairing keys from qz_pairing_keys table for printer selection
This commit is contained in:
@@ -488,3 +488,38 @@ def api_generate_batch_pdf(order_id):
|
||||
except Exception as e:
|
||||
logger.error(f"Error generating batch PDF: {e}")
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
|
||||
@labels_bp.route('/api/pairing-keys', methods=['GET'], endpoint='api_pairing_keys')
|
||||
def api_pairing_keys():
|
||||
"""Get QZ Tray pairing keys for printer selection"""
|
||||
if 'user_id' not in session:
|
||||
return jsonify({'error': 'Unauthorized'}), 401
|
||||
|
||||
try:
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("""
|
||||
SELECT id, printer_name, pairing_key, valid_until
|
||||
FROM qz_pairing_keys
|
||||
WHERE valid_until >= CURDATE()
|
||||
ORDER BY printer_name ASC
|
||||
""")
|
||||
|
||||
pairing_keys = []
|
||||
for row in cursor.fetchall():
|
||||
pairing_keys.append({
|
||||
'id': row[0],
|
||||
'printer_name': row[1],
|
||||
'pairing_key': row[2]
|
||||
})
|
||||
|
||||
cursor.close()
|
||||
|
||||
logger.info(f"Retrieved {len(pairing_keys)} valid pairing keys")
|
||||
return jsonify(pairing_keys), 200
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error fetching pairing keys: {e}")
|
||||
return jsonify({'error': str(e)}), 500
|
||||
@@ -290,8 +290,11 @@
|
||||
<!-- Add html2canvas library for capturing preview as image -->
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
|
||||
<!-- PATCHED QZ Tray library - works with custom server using pairing key authentication -->
|
||||
<script src="{{ url_for('static', filename='js/qz-tray.js') }}"></script>
|
||||
<!-- CDN versions (disabled):
|
||||
<script src="https://qz.glyphtree.com/api/latest/qz-tray.js"></script>
|
||||
<!-- Original CDN version (disabled): <script src="https://cdn.jsdelivr.net/npm/qz-tray@2.2.4/qz-tray.js"></script> -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/qz-tray@2.2.4/qz-tray.js"></script>
|
||||
-->
|
||||
|
||||
<script>
|
||||
// Simplified notification system
|
||||
|
||||
@@ -237,7 +237,7 @@
|
||||
<!-- Add html2canvas library for capturing preview as image -->
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
|
||||
<!-- PATCHED QZ Tray library - works with custom server using pairing key authentication -->
|
||||
<script src="https://qz.glyphtree.com/api/latest/qz-tray.js"></script>
|
||||
<script src="{{ url_for('static', filename='js/qz-tray.js') }}"></script>
|
||||
<script>
|
||||
|
||||
// Store all orders data for searching (will be populated by API fetch on page load)
|
||||
|
||||
@@ -230,7 +230,7 @@
|
||||
<!-- Add html2canvas library for capturing preview as image -->
|
||||
<script src="{{ url_for('static', filename='html2canvas.min.js') }}"></script>
|
||||
<!-- PATCHED QZ Tray library - works with custom server using pairing key authentication -->
|
||||
<script src="{{ url_for('static', filename='qz-tray.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='js/qz-tray.js') }}"></script>
|
||||
<script>
|
||||
|
||||
// Store all orders data for searching
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
{% block extra_css %}
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/fg_scan.css') }}">
|
||||
<script src="https://cdn.jsdelivr.net/npm/qz-tray@2.1.0/qz-tray.js"></script>
|
||||
<script src="{{ url_for('static', filename='js/qz-tray.js') }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
Reference in New Issue
Block a user