Close #11 : Make the signature optionnal, lint file
This commit is contained in:
31
src/main.py
31
src/main.py
@@ -44,7 +44,7 @@ from web import Web # Wrapper for the web routes and API
|
||||
|
||||
app = Flask(__name__)
|
||||
socketio = SocketIO(app)
|
||||
ALLOWED_EXTENSIONS = {"png", "jpg", "jpeg", "gif","webp"}
|
||||
ALLOWED_EXTENSIONS = {"png", "jpg", "jpeg", "gif", "webp"}
|
||||
|
||||
# Load the configuration file
|
||||
try:
|
||||
@@ -82,6 +82,7 @@ except FileExistsError:
|
||||
app.logger.debug("Directory %s already exists.", UPLOAD_FOLDER)
|
||||
except PermissionError:
|
||||
app.logger.error("Permission denied: Unable to create %s", UPLOAD_FOLDER)
|
||||
exit(77)
|
||||
|
||||
# Output the config file
|
||||
if os.getenv("LIPY_DEBUG") is True:
|
||||
@@ -165,14 +166,20 @@ def api_print_sms():
|
||||
app.logger.debug("Printing an sms")
|
||||
try:
|
||||
txt = request.form["txt"]
|
||||
sign = request.form["signature"]
|
||||
except werkzeug.exceptions.BadRequestKeyError as e:
|
||||
app.logger.error(
|
||||
"Whoops, no forms submitted or missing signature : %s ", str(e)
|
||||
)
|
||||
app.logger.error("Whoops, we are missing the txt input field. : %s ", str(e))
|
||||
flash("Whoops, no forms submitted or missing signature : %s", str(e))
|
||||
return redirect(url_for("index"))
|
||||
|
||||
try:
|
||||
# comment: We try to get a signature
|
||||
sign = request.form["signature"]
|
||||
except werkzeug.exceptions.BadRequestKeyError as e:
|
||||
app.logger.warning(
|
||||
"No signature found for this print, using default signature.", str(e)
|
||||
)
|
||||
sign = configuration_file["defaults"]["signature"]
|
||||
|
||||
web.print_sms(txt, sign)
|
||||
return redirect(url_for("index"))
|
||||
|
||||
@@ -184,11 +191,13 @@ def api_print_image():
|
||||
app.logger.debug("Printing an image")
|
||||
|
||||
try:
|
||||
# comment: We try to get a signature
|
||||
sign = request.form["signature"]
|
||||
except Exception as e:
|
||||
app.logger.error("Whoops, no forms submitted or missing signature : %s", str(e))
|
||||
flash("Whoops, no forms submitted or missing signature : %s ", str(e))
|
||||
return redirect(url_for("index"))
|
||||
except werkzeug.exceptions.BadRequestKeyError as e:
|
||||
app.logger.warning(
|
||||
"No signature found for this print, using default signature.", str(e)
|
||||
)
|
||||
sign = configuration_file["defaults"]["signature"]
|
||||
|
||||
if request.method == "POST":
|
||||
# check if the post request has the file part
|
||||
@@ -258,7 +267,7 @@ def ratelimit_handler(e):
|
||||
"Rate limit reached, please slow down :) ( Currently at " + e.description + ")",
|
||||
"error",
|
||||
)
|
||||
app.logger.debug("Rate limit reached %s " , str(e.description))
|
||||
app.logger.debug("Rate limit reached %s ", str(e.description))
|
||||
return redirect(url_for("index"))
|
||||
|
||||
|
||||
@@ -274,7 +283,7 @@ def ping():
|
||||
@socketio.on("ping")
|
||||
def handle_message(data):
|
||||
"""Handle sockets pings"""
|
||||
app.logger.debug("Received : %s " , str(data))
|
||||
app.logger.debug("Received : %s ", str(data))
|
||||
socketio.emit("pong", "Pong !")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user