Make image upload anonymous
This commit is contained in:
1 parent
a5dc4697de
commit
584a3cf13c
2 files changed
+16
-10
No files matched your search
+14
-9
@@ -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.")
|
||||
|
||||
Reference in new issue
Block a user