From 6ca3a9372a68ff3f84090fb78378b8f71b080939 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 26 May 2025 22:43:52 +0300 Subject: [PATCH] feat: add support for multiple label formats in get_label function --- routes/printing.py | 16 ++++++++++------ sipro/api/printing.py | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/routes/printing.py b/routes/printing.py index ba0b201..0cb1e23 100644 --- a/routes/printing.py +++ b/routes/printing.py @@ -1,4 +1,4 @@ -from flask import Blueprint, request, send_file +from flask import Blueprint, request, send_file, jsonify from routes.utils import jwt_protect_blueprint import sipro.api.printing @@ -9,9 +9,13 @@ printing_blueprint = jwt_protect_blueprint(Blueprint('printing', __name__)) def get_label(): args = request.args order_id = args.get('orderId') - data = sipro.api.printing.get_label(order_id) + label_format = args.get('format', 'pdf') + data = sipro.api.printing.get_label(order_id, label_format=label_format) data.seek(0) - return send_file(data, - as_attachment=True, - download_name='label.pdf', - mimetype='application/pdf') + + if label_format == 'pdf': + return send_file(data, + as_attachment=True, + download_name='label.pdf', + mimetype='application/pdf') + return jsonify(data.read().decode('utf-8')) diff --git a/sipro/api/printing.py b/sipro/api/printing.py index c16671b..d18249f 100644 --- a/sipro/api/printing.py +++ b/sipro/api/printing.py @@ -9,8 +9,8 @@ client = get_client() router = '/printing' -def get_label(order_product_id: str) -> BytesIO: - method = f'{router}/getLabel?orderId={order_product_id}' +def get_label(order_product_id: str, label_format:str='pdf') -> BytesIO: + method = f'{router}/getLabel?orderId={order_product_id}&format={label_format}' response: Response = client.method('GET', method, raw=True) data = BytesIO(response.content) return data \ No newline at end of file