Compare commits
4 Commits
836d6b0be9
...
adb5e9422d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
adb5e9422d | ||
|
|
d348acd88c | ||
|
|
e8568795b2 | ||
|
|
086a7ae640 |
@@ -3,6 +3,7 @@
|
||||
[defaults]
|
||||
signature = ""
|
||||
|
||||
|
||||
# Printer settings
|
||||
[printer]
|
||||
upload_folder = "src/static/uploads"
|
||||
@@ -14,11 +15,14 @@ waiting_time = 5
|
||||
profile = "TM-T20III"
|
||||
label_type = 80 # 80 or 58 ( label width in mm )
|
||||
align_text = "center"
|
||||
text_max_length = 4096
|
||||
signature_max_length = 256
|
||||
|
||||
[printer.brother]
|
||||
# Configurations for Brother printers
|
||||
label_type = "62" # See https://github.com/pklaus/brother_ql#usage for label types
|
||||
|
||||
text_max_length = 4096
|
||||
signature_max_length = 256
|
||||
|
||||
# Raspberry Pi Configuration
|
||||
[rpi]
|
||||
|
||||
@@ -16,10 +16,14 @@ waiting_time = 5
|
||||
profile = "TM-T20III"
|
||||
label_type = 80 # 80 or 58 ( label width in mm )
|
||||
align_text = "center"
|
||||
text_max_length = 4096
|
||||
signature_max_length = 256
|
||||
|
||||
[printer.brother]
|
||||
# Configurations for Brother printers
|
||||
label_type = 62 # See https://github.com/pklaus/brother_ql#usage for label types
|
||||
text_max_length = 4096
|
||||
signature_max_length = 256
|
||||
|
||||
# Raspberry Pi Configuration
|
||||
[rpi]
|
||||
|
||||
@@ -366,6 +366,7 @@ def api_print_image():
|
||||
|
||||
# TODO: This might not depend on the Raspberry Pi
|
||||
@app.route("/api/camera/picture", methods=["GET"])
|
||||
@limiter.limit("6/minute", override_defaults=False)
|
||||
def camera_picture():
|
||||
"""Returns a picture taken by the camera on a raspberry pi"""
|
||||
if RASPBERRY_PI_CONNECTED:
|
||||
@@ -378,24 +379,28 @@ def camera_picture():
|
||||
|
||||
|
||||
@app.route("/api/queue", methods=["GET"])
|
||||
@limiter.limit("6/minute", override_defaults=False)
|
||||
def api_queue_status():
|
||||
"""API endpoint for entire queue"""
|
||||
return jsonify(web.get_queue_state())
|
||||
|
||||
|
||||
@app.route("/api/queue/completed", methods=["GET"])
|
||||
@limiter.limit("6/minute", override_defaults=False)
|
||||
def api_queue_completed():
|
||||
"""API endpoint that returns the finished tasks"""
|
||||
return jsonify(web.get_queue_completed())
|
||||
|
||||
|
||||
@app.route("/api/worker", methods=["GET"])
|
||||
@limiter.limit("6/minute", override_defaults=False)
|
||||
def api_worker_state():
|
||||
"""API endpoint to get the worker state"""
|
||||
return jsonify(worker.current_state())
|
||||
|
||||
|
||||
@app.route("/api/worker/start")
|
||||
@limiter.limit("6/minute", override_defaults=False)
|
||||
def api_worker_start():
|
||||
"""
|
||||
Enable to worker. This starts to process the print queue.
|
||||
@@ -405,6 +410,7 @@ def api_worker_start():
|
||||
|
||||
|
||||
@app.route("/api/worker/stop")
|
||||
@limiter.limit("6/minute", override_defaults=False)
|
||||
def api_worker_stop():
|
||||
"""
|
||||
Stops the print queue. This stops the processing of the print queue.
|
||||
@@ -414,6 +420,7 @@ def api_worker_stop():
|
||||
|
||||
|
||||
@app.route("/api/printers")
|
||||
@limiter.limit("6/minute", override_defaults=False)
|
||||
def api_printers_info():
|
||||
"""Returns the current state of every printers"""
|
||||
return jsonify(printers_pool.printers_info())
|
||||
|
||||
@@ -119,6 +119,7 @@ class EscPosPrinter(Printer):
|
||||
self.usb_args = {}
|
||||
self.usb_args["idVendor"] = self.vendor_id
|
||||
self.usb_args["idProduct"] = self.device_id
|
||||
self.configuration_file = configuration_file
|
||||
|
||||
try:
|
||||
# This also calls open(), which we need to close()
|
||||
@@ -148,13 +149,13 @@ class EscPosPrinter(Printer):
|
||||
vendor_id=self.vendor_id,
|
||||
product_id=self.device_id,
|
||||
serial_number="",
|
||||
label_type=configuration_file["label_type"],
|
||||
label_type=self.configuration_file["label_type"],
|
||||
)
|
||||
|
||||
# Setting up the printing options.
|
||||
# TODO : Expose this to the web interface
|
||||
p.set(
|
||||
align=configuration_file["align_text"],
|
||||
align=self.configuration_file["align_text"],
|
||||
font="a",
|
||||
bold=False,
|
||||
underline=0,
|
||||
@@ -213,25 +214,23 @@ class EscPosPrinter(Printer):
|
||||
clean_signature = str(signature)
|
||||
|
||||
# Make checks on the size of the message being printed
|
||||
# TODO: make the max length configurable
|
||||
if len(clean_msg) > 4096:
|
||||
if len(clean_msg) > int(self.configuration_file["text_max_length"]):
|
||||
self.app.logger.warning(
|
||||
"Could not print message of this length: " + str(len(clean_msg))
|
||||
)
|
||||
raise RuntimeError(
|
||||
"Could not print message of this length :"
|
||||
+ str(len(clean_msg))
|
||||
+ ", needs to be below 4096 caracters long."
|
||||
+ ", needs to be below %s caracters long.", str(self.configuration_file["text_max_length"])
|
||||
)
|
||||
# TODO: make the max length configurable
|
||||
if len(signature) > 256:
|
||||
if len(signature) > int(self.configuration_file["signature_max_length"]):
|
||||
self.app.logger.warning(
|
||||
"Could not print signature of this length: " + str(len(clean_signature))
|
||||
)
|
||||
raise RuntimeError(
|
||||
"Could not print signature of this length :"
|
||||
+ str(len(clean_signature))
|
||||
+ ", needs to be below 256 caracters long."
|
||||
+ ", needs to be below %s caracters long.", str(self.configuration_file["signature_max_length"])
|
||||
)
|
||||
|
||||
# Do the actual printing
|
||||
@@ -256,17 +255,17 @@ class EscPosPrinter(Printer):
|
||||
def _print_img(self, path, signature="", center=True, process=False):
|
||||
clean_signature = str(signature)
|
||||
|
||||
# TODO: make the max length configurable
|
||||
if len(signature) > 256:
|
||||
if len(signature) > int(self.configuration_file["signature_max_length"]):
|
||||
self.app.logger.warning(
|
||||
"Could not print signature of this length: " + str(len(clean_signature))
|
||||
)
|
||||
raise ValueError(
|
||||
raise RuntimeError(
|
||||
"Could not print signature of this length :"
|
||||
+ str(len(clean_signature))
|
||||
+ ", needs to be below 256 caracters long."
|
||||
+ ", needs to be below %s caracters long.", str(self.configuration_file["signature_max_length"])
|
||||
)
|
||||
|
||||
|
||||
if not os.path.isfile(str(path)):
|
||||
self.app.logger.warning("File does not exist : " + str(path))
|
||||
raise OSError(
|
||||
|
||||
@@ -156,11 +156,13 @@ class Printers:
|
||||
|
||||
return None
|
||||
|
||||
# def printers_info(self):
|
||||
# """Return the current list of printers"""
|
||||
# printers_info_list = {}
|
||||
# for i in self.printers
|
||||
# return self.printers
|
||||
def printers_info(self):
|
||||
"""Return the current list of printers"""
|
||||
printers_info_list = []
|
||||
for i in self.printers:
|
||||
printers_info_list.append([i.printer_type.name,"Used: " + str(i.used), "Ready: " + str(i.ready),i.printer_info])
|
||||
|
||||
return printers_info_list
|
||||
|
||||
|
||||
class _FindClass:
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
<title>LittlePrynter API</title>
|
||||
</head>
|
||||
<body>
|
||||
"Welcome to the printing software's API. Please see the index page to get started.
|
||||
Welcome to the printing software's API. Please see the index page to get started.
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
<hr>
|
||||
|
||||
<footer class="row">
|
||||
<p class=" text-center">Little Prynter is built by <a href="https://n07070.xyz/about-me/">n07070</a> because it's fun :) | <a href="https://git.n07070.xyz/n07070/littleprynter">Source code - AGPLv3</a></p>
|
||||
<p class=" text-center">Little Prynter is built by <a href="https://n07070.xyz/about-me/">n07070</a> because it's fun :) | <a href="/api">API interface</a> | <a href="https://git.n07070.xyz/n07070/littleprynter">Source code - AGPLv3</a></p>
|
||||
</footer>
|
||||
</body>
|
||||
<script src="https://cdn.socket.io/4.0.0/socket.io.min.js"></script>
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
<hr>
|
||||
<footer>Little Prynter is built by <a href="https://n07070.xyz/about-me/">n07070</a> because it's fun :) | <a href="https://git.n07070.xyz/n07070/littleprynter/src/branch/epson-tm-t20iii">Source code - AGPLv3</a></footer>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user