Compare commits

...

2 Commits

Author SHA1 Message Date
55a0a2dce1 fix icon loading 2025-12-22 15:27:49 +00:00
036ab856eb fix caching 2025-12-22 15:23:08 +00:00
3 changed files with 28 additions and 12 deletions

29
app.py
View File

@ -614,13 +614,14 @@ def human_readable_size(num_bytes):
num /= 1024
@app.route('/icon/<string:size>.png')
@app.route('/icons/<string:size>.png') # legacy path
def serve_resized_icon(size):
cached_image_bytes = get_cached_image(size)
response = send_file(
io.BytesIO(cached_image_bytes),
mimetype='image/png'
)
response.headers['Cache-Control'] = 'public, max-age=86400'
response.headers['Cache-Control'] = 'public, max-age=86400, immutable'
return response
@app.route('/custom_logo/<string:filename>.png')
@ -766,6 +767,9 @@ def serve_file(subpath):
if not os.path.isfile(full_path):
app.logger.error(f"File not found: {full_path}")
return "File not found", 404
filesize = os.path.getsize(full_path)
filename = os.path.basename(full_path)
# 2) Prep request info
mime, _ = mimetypes.guess_type(full_path)
@ -871,7 +875,12 @@ def serve_file(subpath):
cache_key = hashlib.md5(subpath.encode('utf-8')).hexdigest()
cache_dir = os.path.join(cache.directory, cache_key[:2])
os.makedirs(cache_dir, exist_ok=True)
cache_file_path = os.path.join(cache_dir, f"{cache_key}.tmp")
fd, cache_file_path = tempfile.mkstemp(
prefix=f"{cache_key}_",
suffix=".tmp",
dir=cache_dir
)
os.close(fd)
# Start copying to our cache file in chunks
def copy_to_cache_chunked():
@ -886,6 +895,11 @@ def serve_file(subpath):
# Once complete, register with diskcache for proper management
try:
if subpath in cache:
if os.path.exists(cache_file_path):
os.remove(cache_file_path)
app.logger.info(f"Cache already populated for {subpath}, skipped duplicate registration")
return
with open(cache_file_path, 'rb') as f:
cache.set(subpath, f, read=True)
# Remove our temp file since diskcache now has it
@ -924,9 +938,6 @@ def serve_file(subpath):
abort(503, description="Service temporarily unavailable - cache initialization failed")
# 6) Build response for non-image
filesize = os.path.getsize(full_path)
filename = os.path.basename(full_path)
if as_attachment:
download_name = filename
mimetype = 'application/octet-stream'
@ -952,7 +963,10 @@ def serve_file(subpath):
# No data available yet, wait a bit
time.sleep(0.1)
response = make_response(generate())
if request.method == 'HEAD':
response = make_response('', 200)
else:
response = make_response(generate())
response.headers['Content-Type'] = mimetype
response.headers['Content-Length'] = str(filesize)
response.headers['Accept-Ranges'] = 'bytes'
@ -978,6 +992,9 @@ def serve_file(subpath):
response.headers['Content-Disposition'] = 'inline'
response.headers['Cache-Control'] = 'public, max-age=86400'
if request.method == 'HEAD':
response.set_data(b'')
# 7) Logging
if do_log:

View File

@ -152,17 +152,17 @@ def require_secret(f):
for token_in_session in session.get('valid_tokens', []):
try:
token_item = decode_token(token_in_session)
print(f"DEBUG: Decoded token: {token_item}")
# print(f"DEBUG: Decoded token: {token_item}")
for folder_info in token_item.get('folders', []):
print(f"DEBUG: Adding folder '{folder_info['foldername']}' -> '{folder_info['folderpath']}'")
# print(f"DEBUG: Adding folder '{folder_info['foldername']}' -> '{folder_info['folderpath']}'")
session['folders'][folder_info['foldername']] = folder_info['folderpath']
except Exception as e:
print(f"ERROR: Failed to process token: {e}")
# Mark session as modified to ensure it's saved
session.modified = True
print(f"DEBUG: Final session['folders'] keys: {list(session['folders'].keys())}")
print(f"DEBUG: session['valid_tokens']: {session.get('valid_tokens', [])}")
# print(f"DEBUG: Final session['folders'] keys: {list(session['folders'].keys())}")
# print(f"DEBUG: session['valid_tokens']: {session.get('valid_tokens', [])}")
# 6) If we have folders, proceed; otherwise show index
if session['folders']:

View File

@ -197,7 +197,7 @@ class SimpleAudioPlayer {
navigator.mediaSession.metadata = new MediaMetadata({
title : file.replace(/\.[^/.]+$/, ''),
artist: parts.pop(),
artwork: [{ src:'/icons/logo-192x192.png', sizes:'192x192', type:'image/png' }]
artwork: [{ src:'/icon/logo-192x192.png', sizes:'192x192', type:'image/png' }]
});
}
} catch (err) {
@ -266,4 +266,3 @@ class SimpleAudioPlayer {
// Initialize instance
const player = new SimpleAudioPlayer();