Multi-printers #32

Open
n07070 wants to merge 80 commits from multi-printers into master
pull from: multi-printers
2 changed files with 16 additions and 10 deletions
Showing only changes of commit 584a3cf13c - Show all commits

No files matched your search

+2 -1
View File
@@ -85,8 +85,9 @@ class ImageTask(PrintTask):
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)
self.task_id = self._generate_id() if not task_id else task_id
self.image_path = image_path
self.signature = signature
self.process = process
+14 -9
View File
@@ -4,6 +4,7 @@ Manage all of the inputs from a web source
import os
from werkzeug.utils import secure_filename
import uuid
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.
"""
image_uuid = str(uuid.uuid4())
try:
file_uploaded = self.upload_file(image)
file_uploaded = self.upload_file(image, image_uuid)
except Exception as e:
self.app.logger.error(e)
raise RuntimeError("Could not upload file : " + str(e)) from e
@@ -61,10 +65,11 @@ class Web:
ImageTask(
os.path.join(
self.app.config["UPLOAD_FOLDER"],
secure_filename(image.filename),
secure_filename(str(file_uploaded.split("/").pop()))
),
signature=sign,
process=process_image,
task_id=image_uuid
)
)
self.app.logger.info("Added a IMG task at position %s", img)
@@ -96,7 +101,7 @@ class Web:
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
"""
@@ -104,20 +109,20 @@ class Web:
if not image is None or not image == "":
if self.allowed_file(image.filename):
filename = secure_filename(image.filename)
extension = filename.split(".").pop()
self.app.logger.debug("File valid")
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:
self.app.logger.error("Could not save file %s", e)
raise RuntimeError(
"An OS error occured while uploading this file : " + str(e)
) from e
self.app.logger.debug(
"File saved to "
+ str(os.path.join(self.app.config["UPLOAD_FOLDER"], filename))
)
return True
self.app.logger.debug("File saved to %s", image_uuid_path)
return image_uuid_path
self.app.logger.error("Could not save file because the filename is forbidden")
raise RuntimeError("This file type is forbidden.")