diff --git a/onlylegs/__init__.py b/onlylegs/__init__.py index 6da1ef1..d424fcb 100644 --- a/onlylegs/__init__.py +++ b/onlylegs/__init__.py @@ -56,7 +56,7 @@ def create_app(): # pylint: disable=R0914 print( """ #################################################### -# DEFAULY ADMIN USER GENERATED WITH GIVEN USERNAME # +# DEFAULT ADMIN USER GENERATED WITH GIVEN USERNAME # # THE DEFAULT PASSWORD "changeme!" HAS BEEN USED, # # PLEASE UPDATE IT IN THE SETTINGS! # #################################################### @@ -76,18 +76,18 @@ def create_app(): # pylint: disable=R0914 login_manager.login_view = "onlylegs.index" @login_manager.user_loader - def load_user(user_id): # skipcq: PTC-W0065 + def load_user(user_id): return User.query.filter_by(alt_id=user_id).first() @login_manager.unauthorized_handler - def unauthorized(): # skipcq: PTC-W0065 + def unauthorized(): error = 401 msg = "You are not authorized to view this page!!!!" return render_template("error.html", error=error, msg=msg), error # ERROR HANDLERS @app.errorhandler(Exception) - def error_page(err): # skipcq: PTC-W0065 + def error_page(err): """ Error handlers, if the error is not a HTTP error, return 500 """ diff --git a/onlylegs/api/media.py b/onlylegs/api/media.py index 2ce774b..3ddd2c4 100644 --- a/onlylegs/api/media.py +++ b/onlylegs/api/media.py @@ -32,13 +32,12 @@ blueprint = Blueprint("media_api", __name__, url_prefix="/api/media") @blueprint.route("/<path:path>", methods=["GET"]) def media(path): """ - Returns a file from the uploads folder + Returns image from media folder r for resolution, thumb for thumbnail etc e for extension, jpg, png etc """ res = request.args.get("r", default=None, type=str) ext = request.args.get("e", default=None, type=str) - # path = secure_filename(path) # if no args are passed, return the raw file if not res and not ext: @@ -46,11 +45,16 @@ def media(path): abort(404) return send_from_directory(current_app.config["MEDIA_FOLDER"], path) + # Generate thumbnail, if None is returned a server error occured thumb = generate_thumbnail(path, res, ext) if not thumb: abort(500) - return send_from_directory(os.path.dirname(thumb), os.path.basename(thumb)) + response = send_from_directory(os.path.dirname(thumb), os.path.basename(thumb)) + response.headers["Cache-Control"] = "public, max-age=31536000" + response.headers["Expires"] = "31536000" + + return response @blueprint.route("/upload", methods=["POST"]) diff --git a/onlylegs/extensions.py b/onlylegs/extensions.py index 0b27ca4..90ef9ab 100644 --- a/onlylegs/extensions.py +++ b/onlylegs/extensions.py @@ -13,4 +13,4 @@ migrate = Migrate() login_manager = LoginManager() assets = Environment() compress = Compress() -cache = Cache(config={"CACHE_TYPE": "SimpleCache", "CACHE_DEFAULT_TIMEOUT": 300}) +cache = Cache(config={'CACHE_TYPE': 'simple', "CACHE_DEFAULT_TIMEOUT": 300}) diff --git a/onlylegs/filters.py b/onlylegs/filters.py index 6a869e2..d8f2dd4 100644 --- a/onlylegs/filters.py +++ b/onlylegs/filters.py @@ -3,7 +3,7 @@ OnlyLegs filters Custom Jinja2 filters """ from flask import Blueprint -from onlylegs.utils import contrast +from onlylegs.utils.colour import contrast blueprint = Blueprint("filters", __name__) @@ -19,4 +19,4 @@ def colour_contrast(colour): bright = "var(--fg-white)" dark = "var(--fg-black)" - return "color: RGB(" + contrast.contrast(colour, dark, bright) + ");" + return "color: RGB(" + contrast(colour, dark, bright) + ");"