Multi-printers #32
+18
-17
@@ -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.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER
|
||||
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
|
||||
|
||||
# Queue creation
|
||||
@@ -127,7 +127,7 @@ except Exception as e:
|
||||
|
||||
# The rate limit
|
||||
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
|
||||
@app.route("/")
|
||||
@limiter.limit("1/second", override_defaults=False)
|
||||
@limiter.limit("2/second", override_defaults=False)
|
||||
def index():
|
||||
"""Return the web interface index"""
|
||||
app.logger.debug("Loading index")
|
||||
@@ -144,7 +144,7 @@ def index():
|
||||
|
||||
|
||||
@app.route("/webcam")
|
||||
@limiter.limit("1/second", override_defaults=False)
|
||||
@limiter.limit("2/second", override_defaults=False)
|
||||
def webcam():
|
||||
"""Returns the webcam web interface"""
|
||||
app.logger.debug("Loading webcam interface")
|
||||
@@ -152,12 +152,11 @@ def webcam():
|
||||
|
||||
# General routes
|
||||
@app.route("/queue")
|
||||
@limiter.limit("1/second", override_defaults=False)
|
||||
@limiter.limit("3/second", override_defaults=False)
|
||||
def queue():
|
||||
"""Return the web interface index"""
|
||||
app.logger.debug("Loading queue")
|
||||
current_queue = print_queue.get_queue_state()
|
||||
app.logger.debug(current_queue)
|
||||
completed_queue = print_queue.get_queue_completed()
|
||||
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
|
||||
# The api has the following methods
|
||||
# api/print/{sms,img,letter,qr,barcode}
|
||||
# api/camera/picture
|
||||
# api/queue
|
||||
# api/auth/{login,logout}
|
||||
# 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.
|
||||
@app.route("/api")
|
||||
@app.route("/api/print")
|
||||
@limiter.limit("1/second", override_defaults=False)
|
||||
@limiter.limit("6/minute", override_defaults=False)
|
||||
def api_index():
|
||||
"""Returns a how-to for the API"""
|
||||
app.logger.debug("Loading API")
|
||||
@@ -377,7 +378,7 @@ def api_print_image():
|
||||
|
||||
# TODO: This might not depend on the Raspberry Pi
|
||||
@app.route("/api/camera/picture", methods=["GET"])
|
||||
@limiter.limit("6/minute", override_defaults=False)
|
||||
@limiter.limit("6/minute")
|
||||
def camera_picture():
|
||||
"""Returns a picture taken by the camera on a raspberry pi"""
|
||||
if RASPBERRY_PI_CONNECTED:
|
||||
@@ -390,28 +391,29 @@ def camera_picture():
|
||||
|
||||
|
||||
@app.route("/api/queue", methods=["GET"])
|
||||
@limiter.limit("60/minute", override_defaults=False)
|
||||
@limiter.limit("160/minute", override_defaults=True)
|
||||
def api_queue_status():
|
||||
"""API endpoint for entire queue"""
|
||||
return jsonify(web.get_queue_state())
|
||||
|
||||
|
||||
@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():
|
||||
"""API endpoint that returns the finished tasks"""
|
||||
return jsonify(web.get_queue_completed())
|
||||
|
||||
|
||||
@app.route("/api/worker", methods=["GET"])
|
||||
@limiter.limit("6/minute", override_defaults=False)
|
||||
@limiter.limit("160/minute", override_defaults=True)
|
||||
def api_worker_state():
|
||||
"""API endpoint to get the worker state"""
|
||||
return jsonify(worker.current_state())
|
||||
|
||||
|
||||
# TODO : Auth
|
||||
@app.route("/api/worker/start")
|
||||
@limiter.limit("6/minute", override_defaults=False)
|
||||
@limiter.limit("6/minute")
|
||||
def api_worker_start():
|
||||
"""
|
||||
Enable to worker. This starts to process the print queue.
|
||||
@@ -419,9 +421,9 @@ def api_worker_start():
|
||||
worker.start_worker()
|
||||
return jsonify(worker.current_state())
|
||||
|
||||
|
||||
# TODO : Auth
|
||||
@app.route("/api/worker/stop")
|
||||
@limiter.limit("6/minute", override_defaults=False)
|
||||
@limiter.limit("6/minute")
|
||||
def api_worker_stop():
|
||||
"""
|
||||
Stops the print queue. This stops the processing of the print queue.
|
||||
@@ -429,9 +431,9 @@ def api_worker_stop():
|
||||
worker.stop_worker()
|
||||
return jsonify(worker.current_state())
|
||||
|
||||
|
||||
# TODO : Auth
|
||||
@app.route("/api/printers")
|
||||
@limiter.limit("6/minute", override_defaults=False)
|
||||
@limiter.limit("160/minute", override_defaults=True)
|
||||
def api_printers_info():
|
||||
"""Returns the current state of every printers"""
|
||||
return jsonify(printers_pool.printers_info())
|
||||
@@ -439,7 +441,6 @@ def api_printers_info():
|
||||
|
||||
## Authentification
|
||||
|
||||
|
||||
@app.route("/login")
|
||||
@limiter.limit("1/second", override_defaults=False)
|
||||
def login_page():
|
||||
|
||||
Reference in new issue
Block a user