This commit is contained in:
Michał 2023-05-29 10:41:53 +00:00
parent b30e336ae6
commit d9714da918
4 changed files with 14 additions and 10 deletions

View file

@ -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
"""

View file

@ -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"])

View file

@ -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})

View file

@ -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) + ");"