not mixing dump file with cached file

This commit is contained in:
Kenny Cheng 2024-10-26 01:18:01 +08:00
parent 5706377a31
commit 8bad36271a
2 changed files with 14 additions and 13 deletions

23
app.py
View File

@ -60,16 +60,6 @@ def create_cache():
if is_image_valid(image_path): if is_image_valid(image_path):
cached_images.append(image) cached_images.append(image)
for image in os.listdir(app.config['DUMP_FOLDER']):
image_path = os.path.join(app.config['DUMP_FOLDER'], image)
cache_path = os.path.join(app.config['CACHE_FOLDER'], image)
if not os.path.exists(cache_path) and is_image_valid(image_path):
resize_image(image_path, cache_path)
if is_image_valid(image_path):
cached_images.append(image)
return cached_images return cached_images
@ -149,6 +139,17 @@ def cached_file(filename):
else: else:
return "Invalid image", 404 return "Invalid image", 404
@app.route('/dump/<filename>')
def dump_file(filename):
if not session.get('logged_in'):
return redirect(url_for('login'))
image_path = os.path.join(app.config['DUMP_FOLDER'], filename)
if is_image_valid(image_path):
return send_from_directory(app.config['DUMP_FOLDER'], filename)
else:
return "Invalid image", 404
@app.route('/api/images') @app.route('/api/images')
def api_images(): def api_images():
if not session.get('logged_in'): if not session.get('logged_in'):
@ -167,7 +168,7 @@ def dump():
if not session.get('logged_in'): if not session.get('logged_in'):
return redirect(url_for('login')) return redirect(url_for('login'))
cached_images = create_cache() #cached_images = create_cache()
dump_folder = app.config['DUMP_FOLDER'] # Folder to store dump images dump_folder = app.config['DUMP_FOLDER'] # Folder to store dump images
images = sorted( images = sorted(
os.listdir(dump_folder), os.listdir(dump_folder),

View File

@ -13,8 +13,8 @@
<h1>Pumpkin Gallery🎃</h1> <h1>Pumpkin Gallery🎃</h1>
<div class="gallery-container" style="flex-direction: row; flex-wrap: wrap;"> <div class="gallery-container" style="flex-direction: row; flex-wrap: wrap;">
{% for image in images %} {% for image in images %}
<a href="{{ url_for('cached_file', filename=image) }}" data-original="{{ url_for('cached_file', filename=image) }}" target="_blank" style="flex: 1 0 25%;"> <a href="{{ url_for('dump_file', filename=image) }}" data-original="{{ url_for('dump_file', filename=image) }}" target="_blank" style="flex: 1 0 25%;">
<img class="responsive-img loaded" src="{{ url_for('cached_file', filename=image) }}" alt="{{ image }}" style="max-width:33vw;"> <img class="responsive-img loaded" src="{{ url_for('dump_file', filename=image) }}" alt="{{ image }}" style="max-width:33vw;">
</a> </a>
{% endfor %} {% endfor %}
</div> </div>