diff --git a/src/main.py b/src/main.py index 8999435..e68399a 100644 --- a/src/main.py +++ b/src/main.py @@ -101,9 +101,6 @@ app.config["TEMPLATES_AUTO_RELOAD"] = True # Printer connection # Uses the class defined in the printer.py file printer = Printer(app, 0x04B8, 0x0E28) -# printers = Printer(app) -# printers.discover_printers() -# printers.init() printer.init_printer() # Find out if we are running on a Raspberry Pi @@ -122,20 +119,19 @@ RASPBERRY_PI_CONNECTED = rpi.is_raspberry_pi() # Queue creation print_queue = PrintQueue(app) -# Web & API routes +# Web & API management web = Web(app, print_queue) # Start worker thread worker = PrintWorker(app, print_queue, printer, socketio) worker.start() +# The rate limit limiter = Limiter( get_remote_address, app=app, default_limits=["1500 per day", "500 per hour"] ) # General routes - - @app.route("/") @limiter.limit("1/second", override_defaults=False) def index(): @@ -153,8 +149,6 @@ def webcam(): # Form treatement - - @app.route("/web/print/sms", methods=["POST"]) @limiter.limit("6/minute", override_defaults=False) def web_print_sms(): @@ -185,7 +179,7 @@ def web_print_sms(): return redirect(url_for("index")) # end try - flash("The SMS has been printed !", "info") + flash("The SMS has been added to the print queue !", "info") return redirect(url_for("index")) @@ -227,7 +221,7 @@ def web_print_img(): flash("The image could not be printed because : " + str(e), "error") return redirect(url_for("index")) - flash("Picture printed !", "info") + flash("Picture added to the print queue !", "info") return redirect(url_for("index")) @@ -296,8 +290,7 @@ def api_print_image(): return "No image submitted", 400 file = request.files["img"] - # If the user does not select a file, the browser submits an - # empty file without a filename. + # If the user submits an empty file without a filename. if file.filename == "": app.logger.error("Submitted file has no filename !") return "Submitted file has no filename !", 400 @@ -337,12 +330,18 @@ def api_worker_state(): @app.route("/api/worker/start") def api_worker_start(): + """ + Enable to worker. This starts to process the print queue. + """ worker.start_worker() return jsonify(worker.current_state()) @app.route("/api/worker/stop") def api_worker_stop(): + """ + Stops the print queue. This stops the processing of the print queue. + """ worker.stop_worker() return jsonify(worker.current_state())