feat: add basic lock
This commit is contained in:
parent
cbe2d5059e
commit
e4d6f0e20e
1 changed files with 11 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
from multiprocessing import mp
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
@ -9,6 +10,8 @@ DEVICE = "B9:26:5A:67:50:49"
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config["MAX_CONTENT_LENGTH"] = 40 * 1024 * 1024
|
app.config["MAX_CONTENT_LENGTH"] = 40 * 1024 * 1024
|
||||||
|
app.config["UPLOAD_FOLDER"] = "uploads"
|
||||||
|
app.printlock = Lock()
|
||||||
CORS(app)
|
CORS(app)
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,8 +28,10 @@ def static_helper(static):
|
||||||
@app.route("/print", methods=["POST"])
|
@app.route("/print", methods=["POST"])
|
||||||
def handle_image():
|
def handle_image():
|
||||||
try:
|
try:
|
||||||
img = Image.open(request.files["image"])
|
f = request.files["image"]
|
||||||
|
img = Image.open(f)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
return f"Error loading image: {e}", 500
|
return f"Error loading image: {e}", 500
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -65,7 +70,7 @@ class PrintImage:
|
||||||
imgborder.paste(self.image, (61, 0))
|
imgborder.paste(self.image, (61, 0))
|
||||||
self.image = imgborder
|
self.image = imgborder
|
||||||
|
|
||||||
def print(self):
|
def _print(self):
|
||||||
img = self.image.convert("1")
|
img = self.image.convert("1")
|
||||||
|
|
||||||
buf = []
|
buf = []
|
||||||
|
@ -98,3 +103,7 @@ class PrintImage:
|
||||||
sock.sendall(bytes(buf))
|
sock.sendall(bytes(buf))
|
||||||
sock.recv(1024)
|
sock.recv(1024)
|
||||||
sock.close()
|
sock.close()
|
||||||
|
|
||||||
|
def print(self):
|
||||||
|
with app.printlock:
|
||||||
|
self._print()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue