From bf8142623e71aebffbe403afeccfe8f893d34194 Mon Sep 17 00:00:00 2001 From: Fluffy-Bean Date: Tue, 4 Apr 2023 14:21:16 +0000 Subject: [PATCH] Fix lazyLoading script --- gallery/static/js/pre/main.js | 6 ++---- gallery/templates/groups/group.html | 2 +- gallery/templates/groups/list.html | 2 +- gallery/templates/index.html | 2 +- gallery/views/api.py | 2 +- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/gallery/static/js/pre/main.js b/gallery/static/js/pre/main.js index c5ba3cf..11a1163 100644 --- a/gallery/static/js/pre/main.js +++ b/gallery/static/js/pre/main.js @@ -5,14 +5,12 @@ function imgFade(obj, time = 250) { } // Lazy load images when they are in view function loadOnView() { - let lazyLoad = document.querySelectorAll('#lazy-load'); + const lazyLoad = document.querySelectorAll('#lazy-load'); for (let i = 0; i < lazyLoad.length; i++) { let image = lazyLoad[i]; if (image.getBoundingClientRect().top < window.innerHeight && image.getBoundingClientRect().bottom > 0) { - if (!image.src) { - image.src = `/api/file/${image.getAttribute('data-src')}?r=thumb` // e=webp - } + if (!image.src) { image.src = image.getAttribute('data-src') } } } } diff --git a/gallery/templates/groups/group.html b/gallery/templates/groups/group.html index 9376051..e0378ad 100644 --- a/gallery/templates/groups/group.html +++ b/gallery/templates/groups/group.html @@ -68,7 +68,7 @@

{{ image.created_at }}

- {{ image.post_alt }} + {{ image.post_alt }} {% endfor %} diff --git a/gallery/templates/groups/list.html b/gallery/templates/groups/list.html index ef726f8..9a89232 100644 --- a/gallery/templates/groups/list.html +++ b/gallery/templates/groups/list.html @@ -31,7 +31,7 @@
{% if group.images|length > 0 %} {% for image in group.images %} - + {% endfor %} {% else %} diff --git a/gallery/templates/index.html b/gallery/templates/index.html index 2a91c77..e4289ac 100644 --- a/gallery/templates/index.html +++ b/gallery/templates/index.html @@ -21,7 +21,7 @@

{{ image.created_at }}

- {{ image.post_alt }} + {{ image.post_alt }} {% endfor %} diff --git a/gallery/views/api.py b/gallery/views/api.py index 0bbacaa..bb3faa2 100644 --- a/gallery/views/api.py +++ b/gallery/views/api.py @@ -38,7 +38,7 @@ def file(file_name): file_name = secure_filename(file_name) # Sanitize file name # if no args are passed, return the raw file - if not request.args: + if not res and not ext: if not os.path.exists(os.path.join(current_app.config['UPLOAD_FOLDER'], file_name)): abort(404) return send_from_directory(current_app.config['UPLOAD_FOLDER'], file_name)