25 lines
		
	
	
		
			759 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
		
			759 B
		
	
	
	
		
			Python
		
	
	
	
	
	
import json
 | 
						|
 | 
						|
from flask import Blueprint, request, send_file, jsonify
 | 
						|
from routes.utils import jwt_protect_blueprint
 | 
						|
import sipro.api.printing
 | 
						|
 | 
						|
printing_blueprint = jwt_protect_blueprint(Blueprint('printing', __name__))
 | 
						|
 | 
						|
 | 
						|
@printing_blueprint.get('/getLabel')
 | 
						|
def get_label():
 | 
						|
    args = request.args
 | 
						|
    order_id = args.get('orderId')
 | 
						|
    label_format = args.get('format', 'pdf')
 | 
						|
    data = sipro.api.printing.get_label(order_id, label_format=label_format)
 | 
						|
    data.seek(0)
 | 
						|
 | 
						|
    if label_format == 'pdf':
 | 
						|
        return send_file(data,
 | 
						|
                         as_attachment=True,
 | 
						|
                         download_name='label.pdf',
 | 
						|
                         mimetype='application/pdf')
 | 
						|
    data= json.loads(str(data.read(), 'ascii'))
 | 
						|
    return jsonify(data)
 |