Multi-printers #32

Open
n07070 wants to merge 80 commits from multi-printers into master
pull from: multi-printers
Showing only changes of commit de517bfaaa - Show all commits
+18 -17
View File
@@ -94,7 +94,7 @@ if not os.getenv("FLASK_DEBUG") is None and os.getenv("FLASK_DEBUG") is True:
app.secret_key = configuration_file["secrets"]["flask_secret_key"] app.secret_key = configuration_file["secrets"]["flask_secret_key"]
app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER
app.config["ALLOWED_EXTENSIONS"] = ALLOWED_EXTENSIONS app.config["ALLOWED_EXTENSIONS"] = ALLOWED_EXTENSIONS
app.config["MAX_CONTENT_LENGTH"] = 10 * 1000 * 1000 # Maximum 10Mb for a file upload app.config["MAX_CONTENT_LENGTH"] = 30 * 1000 * 1000 # Maximum 10Mb for a file upload
app.config["TEMPLATES_AUTO_RELOAD"] = True app.config["TEMPLATES_AUTO_RELOAD"] = True
# Queue creation # Queue creation
@@ -127,7 +127,7 @@ except Exception as e:
# The rate limit # The rate limit
limiter = Limiter( limiter = Limiter(
get_remote_address, app=app, default_limits=["86460 per day", "3660 per hour"] get_remote_address, app=app, default_limits=["104800 per day", "10200 per hour"]
) )
@@ -136,7 +136,7 @@ app.logger.info("🖶 Welcome to LittlePrynter !")
# General routes # General routes
@app.route("/") @app.route("/")
@limiter.limit("1/second", override_defaults=False) @limiter.limit("2/second", override_defaults=False)
def index(): def index():
"""Return the web interface index""" """Return the web interface index"""
app.logger.debug("Loading index") app.logger.debug("Loading index")
@@ -144,7 +144,7 @@ def index():
@app.route("/webcam") @app.route("/webcam")
@limiter.limit("1/second", override_defaults=False) @limiter.limit("2/second", override_defaults=False)
def webcam(): def webcam():
"""Returns the webcam web interface""" """Returns the webcam web interface"""
app.logger.debug("Loading webcam interface") app.logger.debug("Loading webcam interface")
@@ -152,12 +152,11 @@ def webcam():
# General routes # General routes
@app.route("/queue") @app.route("/queue")
@limiter.limit("1/second", override_defaults=False) @limiter.limit("3/second", override_defaults=False)
def queue(): def queue():
"""Return the web interface index""" """Return the web interface index"""
app.logger.debug("Loading queue") app.logger.debug("Loading queue")
current_queue = print_queue.get_queue_state() current_queue = print_queue.get_queue_state()
app.logger.debug(current_queue)
completed_queue = print_queue.get_queue_completed() completed_queue = print_queue.get_queue_completed()
return render_template("queue.html", tasks=current_queue, completed_tasks=completed_queue, worker_state=worker.current_state()) return render_template("queue.html", tasks=current_queue, completed_tasks=completed_queue, worker_state=worker.current_state())
@@ -271,6 +270,8 @@ def web_print_img():
# API routes # API routes
# The api has the following methods # The api has the following methods
# api/print/{sms,img,letter,qr,barcode} # api/print/{sms,img,letter,qr,barcode}
# api/camera/picture
# api/queue
# api/auth/{login,logout} # api/auth/{login,logout}
# api/status/{paper,ping,stats} # api/status/{paper,ping,stats}
@@ -278,7 +279,7 @@ def web_print_img():
# If you just call the api route, you get a help back. # If you just call the api route, you get a help back.
@app.route("/api") @app.route("/api")
@app.route("/api/print") @app.route("/api/print")
@limiter.limit("1/second", override_defaults=False) @limiter.limit("6/minute", override_defaults=False)
def api_index(): def api_index():
"""Returns a how-to for the API""" """Returns a how-to for the API"""
app.logger.debug("Loading API") app.logger.debug("Loading API")
@@ -377,7 +378,7 @@ def api_print_image():
# TODO: This might not depend on the Raspberry Pi # TODO: This might not depend on the Raspberry Pi
@app.route("/api/camera/picture", methods=["GET"]) @app.route("/api/camera/picture", methods=["GET"])
@limiter.limit("6/minute", override_defaults=False) @limiter.limit("6/minute")
def camera_picture(): def camera_picture():
"""Returns a picture taken by the camera on a raspberry pi""" """Returns a picture taken by the camera on a raspberry pi"""
if RASPBERRY_PI_CONNECTED: if RASPBERRY_PI_CONNECTED:
@@ -390,28 +391,29 @@ def camera_picture():
@app.route("/api/queue", methods=["GET"]) @app.route("/api/queue", methods=["GET"])
@limiter.limit("60/minute", override_defaults=False) @limiter.limit("160/minute", override_defaults=True)
def api_queue_status(): def api_queue_status():
"""API endpoint for entire queue""" """API endpoint for entire queue"""
return jsonify(web.get_queue_state()) return jsonify(web.get_queue_state())
@app.route("/api/queue/completed", methods=["GET"]) @app.route("/api/queue/completed", methods=["GET"])
@limiter.limit("6/minute", override_defaults=False) @limiter.limit("160/minute", override_defaults=True)
def api_queue_completed(): def api_queue_completed():
"""API endpoint that returns the finished tasks""" """API endpoint that returns the finished tasks"""
return jsonify(web.get_queue_completed()) return jsonify(web.get_queue_completed())
@app.route("/api/worker", methods=["GET"]) @app.route("/api/worker", methods=["GET"])
@limiter.limit("6/minute", override_defaults=False) @limiter.limit("160/minute", override_defaults=True)
def api_worker_state(): def api_worker_state():
"""API endpoint to get the worker state""" """API endpoint to get the worker state"""
return jsonify(worker.current_state()) return jsonify(worker.current_state())
# TODO : Auth
@app.route("/api/worker/start") @app.route("/api/worker/start")
@limiter.limit("6/minute", override_defaults=False) @limiter.limit("6/minute")
def api_worker_start(): def api_worker_start():
""" """
Enable to worker. This starts to process the print queue. Enable to worker. This starts to process the print queue.
@@ -419,9 +421,9 @@ def api_worker_start():
worker.start_worker() worker.start_worker()
return jsonify(worker.current_state()) return jsonify(worker.current_state())
# TODO : Auth
@app.route("/api/worker/stop") @app.route("/api/worker/stop")
@limiter.limit("6/minute", override_defaults=False) @limiter.limit("6/minute")
def api_worker_stop(): def api_worker_stop():
""" """
Stops the print queue. This stops the processing of the print queue. Stops the print queue. This stops the processing of the print queue.
@@ -429,9 +431,9 @@ def api_worker_stop():
worker.stop_worker() worker.stop_worker()
return jsonify(worker.current_state()) return jsonify(worker.current_state())
# TODO : Auth
@app.route("/api/printers") @app.route("/api/printers")
@limiter.limit("6/minute", override_defaults=False) @limiter.limit("160/minute", override_defaults=True)
def api_printers_info(): def api_printers_info():
"""Returns the current state of every printers""" """Returns the current state of every printers"""
return jsonify(printers_pool.printers_info()) return jsonify(printers_pool.printers_info())
@@ -439,7 +441,6 @@ def api_printers_info():
## Authentification ## Authentification
@app.route("/login") @app.route("/login")
@limiter.limit("1/second", override_defaults=False) @limiter.limit("1/second", override_defaults=False)
def login_page(): def login_page():