Compare commits
No commits in common. "55a0a2dce1047bc0ba177677f368f6828aa6d377" and "b8713fcc7ebb449e30b71a575a5df70d2cad7d4b" have entirely different histories.
55a0a2dce1
...
b8713fcc7e
27
app.py
27
app.py
@ -614,14 +614,13 @@ def human_readable_size(num_bytes):
|
|||||||
num /= 1024
|
num /= 1024
|
||||||
|
|
||||||
@app.route('/icon/<string:size>.png')
|
@app.route('/icon/<string:size>.png')
|
||||||
@app.route('/icons/<string:size>.png') # legacy path
|
|
||||||
def serve_resized_icon(size):
|
def serve_resized_icon(size):
|
||||||
cached_image_bytes = get_cached_image(size)
|
cached_image_bytes = get_cached_image(size)
|
||||||
response = send_file(
|
response = send_file(
|
||||||
io.BytesIO(cached_image_bytes),
|
io.BytesIO(cached_image_bytes),
|
||||||
mimetype='image/png'
|
mimetype='image/png'
|
||||||
)
|
)
|
||||||
response.headers['Cache-Control'] = 'public, max-age=86400, immutable'
|
response.headers['Cache-Control'] = 'public, max-age=86400'
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@app.route('/custom_logo/<string:filename>.png')
|
@app.route('/custom_logo/<string:filename>.png')
|
||||||
@ -768,9 +767,6 @@ def serve_file(subpath):
|
|||||||
app.logger.error(f"File not found: {full_path}")
|
app.logger.error(f"File not found: {full_path}")
|
||||||
return "File not found", 404
|
return "File not found", 404
|
||||||
|
|
||||||
filesize = os.path.getsize(full_path)
|
|
||||||
filename = os.path.basename(full_path)
|
|
||||||
|
|
||||||
# 2) Prep request info
|
# 2) Prep request info
|
||||||
mime, _ = mimetypes.guess_type(full_path)
|
mime, _ = mimetypes.guess_type(full_path)
|
||||||
mime = mime or 'application/octet-stream'
|
mime = mime or 'application/octet-stream'
|
||||||
@ -875,12 +871,7 @@ def serve_file(subpath):
|
|||||||
cache_key = hashlib.md5(subpath.encode('utf-8')).hexdigest()
|
cache_key = hashlib.md5(subpath.encode('utf-8')).hexdigest()
|
||||||
cache_dir = os.path.join(cache.directory, cache_key[:2])
|
cache_dir = os.path.join(cache.directory, cache_key[:2])
|
||||||
os.makedirs(cache_dir, exist_ok=True)
|
os.makedirs(cache_dir, exist_ok=True)
|
||||||
fd, cache_file_path = tempfile.mkstemp(
|
cache_file_path = os.path.join(cache_dir, f"{cache_key}.tmp")
|
||||||
prefix=f"{cache_key}_",
|
|
||||||
suffix=".tmp",
|
|
||||||
dir=cache_dir
|
|
||||||
)
|
|
||||||
os.close(fd)
|
|
||||||
|
|
||||||
# Start copying to our cache file in chunks
|
# Start copying to our cache file in chunks
|
||||||
def copy_to_cache_chunked():
|
def copy_to_cache_chunked():
|
||||||
@ -895,11 +886,6 @@ def serve_file(subpath):
|
|||||||
|
|
||||||
# Once complete, register with diskcache for proper management
|
# Once complete, register with diskcache for proper management
|
||||||
try:
|
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:
|
with open(cache_file_path, 'rb') as f:
|
||||||
cache.set(subpath, f, read=True)
|
cache.set(subpath, f, read=True)
|
||||||
# Remove our temp file since diskcache now has it
|
# Remove our temp file since diskcache now has it
|
||||||
@ -938,6 +924,9 @@ def serve_file(subpath):
|
|||||||
abort(503, description="Service temporarily unavailable - cache initialization failed")
|
abort(503, description="Service temporarily unavailable - cache initialization failed")
|
||||||
|
|
||||||
# 6) Build response for non-image
|
# 6) Build response for non-image
|
||||||
|
filesize = os.path.getsize(full_path)
|
||||||
|
filename = os.path.basename(full_path)
|
||||||
|
|
||||||
if as_attachment:
|
if as_attachment:
|
||||||
download_name = filename
|
download_name = filename
|
||||||
mimetype = 'application/octet-stream'
|
mimetype = 'application/octet-stream'
|
||||||
@ -963,9 +952,6 @@ def serve_file(subpath):
|
|||||||
# No data available yet, wait a bit
|
# No data available yet, wait a bit
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
if request.method == 'HEAD':
|
|
||||||
response = make_response('', 200)
|
|
||||||
else:
|
|
||||||
response = make_response(generate())
|
response = make_response(generate())
|
||||||
response.headers['Content-Type'] = mimetype
|
response.headers['Content-Type'] = mimetype
|
||||||
response.headers['Content-Length'] = str(filesize)
|
response.headers['Content-Length'] = str(filesize)
|
||||||
@ -993,9 +979,6 @@ def serve_file(subpath):
|
|||||||
|
|
||||||
response.headers['Cache-Control'] = 'public, max-age=86400'
|
response.headers['Cache-Control'] = 'public, max-age=86400'
|
||||||
|
|
||||||
if request.method == 'HEAD':
|
|
||||||
response.set_data(b'')
|
|
||||||
|
|
||||||
# 7) Logging
|
# 7) Logging
|
||||||
if do_log:
|
if do_log:
|
||||||
a.log_file_access(
|
a.log_file_access(
|
||||||
|
|||||||
8
auth.py
8
auth.py
@ -152,17 +152,17 @@ def require_secret(f):
|
|||||||
for token_in_session in session.get('valid_tokens', []):
|
for token_in_session in session.get('valid_tokens', []):
|
||||||
try:
|
try:
|
||||||
token_item = decode_token(token_in_session)
|
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', []):
|
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']
|
session['folders'][folder_info['foldername']] = folder_info['folderpath']
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"ERROR: Failed to process token: {e}")
|
print(f"ERROR: Failed to process token: {e}")
|
||||||
|
|
||||||
# Mark session as modified to ensure it's saved
|
# Mark session as modified to ensure it's saved
|
||||||
session.modified = True
|
session.modified = True
|
||||||
# print(f"DEBUG: Final session['folders'] keys: {list(session['folders'].keys())}")
|
print(f"DEBUG: Final session['folders'] keys: {list(session['folders'].keys())}")
|
||||||
# print(f"DEBUG: session['valid_tokens']: {session.get('valid_tokens', [])}")
|
print(f"DEBUG: session['valid_tokens']: {session.get('valid_tokens', [])}")
|
||||||
|
|
||||||
# 6) If we have folders, proceed; otherwise show index
|
# 6) If we have folders, proceed; otherwise show index
|
||||||
if session['folders']:
|
if session['folders']:
|
||||||
|
|||||||
@ -197,7 +197,7 @@ class SimpleAudioPlayer {
|
|||||||
navigator.mediaSession.metadata = new MediaMetadata({
|
navigator.mediaSession.metadata = new MediaMetadata({
|
||||||
title : file.replace(/\.[^/.]+$/, ''),
|
title : file.replace(/\.[^/.]+$/, ''),
|
||||||
artist: parts.pop(),
|
artist: parts.pop(),
|
||||||
artwork: [{ src:'/icon/logo-192x192.png', sizes:'192x192', type:'image/png' }]
|
artwork: [{ src:'/icons/logo-192x192.png', sizes:'192x192', type:'image/png' }]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -266,3 +266,4 @@ class SimpleAudioPlayer {
|
|||||||
// Initialize instance
|
// Initialize instance
|
||||||
const player = new SimpleAudioPlayer();
|
const player = new SimpleAudioPlayer();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user