Multi-printers #32
No files matched your search
+2
-1
@@ -85,8 +85,9 @@ class ImageTask(PrintTask):
|
|||||||
This tasks represents a image content ( in the form of it's path ), and it's signature.
|
This tasks represents a image content ( in the form of it's path ), and it's signature.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, image_path, signature, process):
|
def __init__(self, image_path, signature, process, task_id):
|
||||||
super().__init__(TaskType.IMAGE)
|
super().__init__(TaskType.IMAGE)
|
||||||
|
self.task_id = self._generate_id() if not task_id else task_id
|
||||||
self.image_path = image_path
|
self.image_path = image_path
|
||||||
self.signature = signature
|
self.signature = signature
|
||||||
self.process = process
|
self.process = process
|
||||||
|
|||||||
+14
-9
@@ -4,6 +4,7 @@ Manage all of the inputs from a web source
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
|
import uuid
|
||||||
from task import TextTask, ImageTask, CutTask
|
from task import TextTask, ImageTask, CutTask
|
||||||
|
|
||||||
|
|
||||||
@@ -47,8 +48,11 @@ class Web:
|
|||||||
"""
|
"""
|
||||||
Get an image and a signature, prints the image and cuts after that.
|
Get an image and a signature, prints the image and cuts after that.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
image_uuid = str(uuid.uuid4())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
file_uploaded = self.upload_file(image)
|
file_uploaded = self.upload_file(image, image_uuid)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.app.logger.error(e)
|
self.app.logger.error(e)
|
||||||
raise RuntimeError("Could not upload file : " + str(e)) from e
|
raise RuntimeError("Could not upload file : " + str(e)) from e
|
||||||
@@ -61,10 +65,11 @@ class Web:
|
|||||||
ImageTask(
|
ImageTask(
|
||||||
os.path.join(
|
os.path.join(
|
||||||
self.app.config["UPLOAD_FOLDER"],
|
self.app.config["UPLOAD_FOLDER"],
|
||||||
secure_filename(image.filename),
|
secure_filename(str(file_uploaded.split("/").pop()))
|
||||||
),
|
),
|
||||||
signature=sign,
|
signature=sign,
|
||||||
process=process_image,
|
process=process_image,
|
||||||
|
task_id=image_uuid
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.app.logger.info("Added a IMG task at position %s", img)
|
self.app.logger.info("Added a IMG task at position %s", img)
|
||||||
@@ -96,7 +101,7 @@ class Web:
|
|||||||
in self.app.config["ALLOWED_EXTENSIONS"]
|
in self.app.config["ALLOWED_EXTENSIONS"]
|
||||||
)
|
)
|
||||||
|
|
||||||
def upload_file(self, image) -> bool:
|
def upload_file(self, image, image_uuid) -> bool:
|
||||||
"""
|
"""
|
||||||
Save the file after executing checks on it
|
Save the file after executing checks on it
|
||||||
"""
|
"""
|
||||||
@@ -104,20 +109,20 @@ class Web:
|
|||||||
if not image is None or not image == "":
|
if not image is None or not image == "":
|
||||||
if self.allowed_file(image.filename):
|
if self.allowed_file(image.filename):
|
||||||
filename = secure_filename(image.filename)
|
filename = secure_filename(image.filename)
|
||||||
|
extension = filename.split(".").pop()
|
||||||
self.app.logger.debug("File valid")
|
self.app.logger.debug("File valid")
|
||||||
try:
|
try:
|
||||||
image.save(os.path.join(self.app.config["UPLOAD_FOLDER"], filename))
|
image_uuid_path = os.path.join(self.app.config["UPLOAD_FOLDER"], image_uuid + "." + extension)
|
||||||
|
image.save(image_uuid_path)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
self.app.logger.error("Could not save file %s", e)
|
self.app.logger.error("Could not save file %s", e)
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"An OS error occured while uploading this file : " + str(e)
|
"An OS error occured while uploading this file : " + str(e)
|
||||||
) from e
|
) from e
|
||||||
|
|
||||||
self.app.logger.debug(
|
self.app.logger.debug("File saved to %s", image_uuid_path)
|
||||||
"File saved to "
|
|
||||||
+ str(os.path.join(self.app.config["UPLOAD_FOLDER"], filename))
|
return image_uuid_path
|
||||||
)
|
|
||||||
return True
|
|
||||||
|
|
||||||
self.app.logger.error("Could not save file because the filename is forbidden")
|
self.app.logger.error("Could not save file because the filename is forbidden")
|
||||||
raise RuntimeError("This file type is forbidden.")
|
raise RuntimeError("This file type is forbidden.")
|
||||||
|
|||||||
Reference in new issue
Block a user