From d2dedf51c7953663056dde8e839893e340018e02 Mon Sep 17 00:00:00 2001 From: lelo Date: Wed, 26 Mar 2025 17:52:16 +0000 Subject: [PATCH] allow all file types --- app.py | 52 +++++++++++++++++++++++---------------------- check_ssh_tunnel.sh | 6 ++---- static/app.js | 3 +++ 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/app.py b/app.py index 326aa35..5418f68 100755 --- a/app.py +++ b/app.py @@ -76,8 +76,8 @@ def list_directory_contents(directory, subpath): transcription_exists = os.path.isdir(transcription_dir) # Define allowed file extensions. - allowed_music_exts = ('.mp3',) - allowed_image_exts = ('.jpg', '.jpeg', '.png', '.gif', '.bmp') + music_exts = ('.mp3',) + image_exts = ('.jpg', '.jpeg', '.png', '.gif', '.bmp') try: with os.scandir(directory) as it: @@ -94,27 +94,31 @@ def list_directory_contents(directory, subpath): directories.append({'name': entry.name, 'path': rel_path.replace(os.sep, '/')}) elif entry.is_file(follow_symlinks=False): lower_name = entry.name.lower() - if lower_name.endswith(allowed_music_exts) or lower_name.endswith(allowed_image_exts): - rel_path = os.path.join(subpath, entry.name) if subpath else entry.name - if lower_name.endswith(allowed_music_exts): - file_type = 'music' - else: - file_type = 'image' - file_entry = {'name': entry.name, 'path': rel_path.replace(os.sep, '/'), 'file_type': file_type} - # Only check for transcription if it's a audio file. - if file_type == 'music' and transcription_exists: - base_name = os.path.splitext(entry.name)[0] - transcript_filename = base_name + '.md' - transcript_path = os.path.join(transcription_dir, transcript_filename) - if os.path.isfile(transcript_path): - file_entry['has_transcript'] = True - transcript_rel_path = os.path.join(subpath, "Transkription", transcript_filename) if subpath else os.path.join("Transkription", transcript_filename) - file_entry['transcript_url'] = url_for('get_transcript', subpath=transcript_rel_path.replace(os.sep, '/')) - else: - file_entry['has_transcript'] = False + + # implement file type filtering here !!! + #if lower_name.endswith(music_exts) or lower_name.endswith(image_exts): + rel_path = os.path.join(subpath, entry.name) if subpath else entry.name + if lower_name.endswith(music_exts): + file_type = 'music' + elif lower_name.endswith(image_exts): + file_type = 'image' + else: + file_type = 'other' + file_entry = {'name': entry.name, 'path': rel_path.replace(os.sep, '/'), 'file_type': file_type} + # Only check for transcription if it's a audio file. + if file_type == 'music' and transcription_exists: + base_name = os.path.splitext(entry.name)[0] + transcript_filename = base_name + '.md' + transcript_path = os.path.join(transcription_dir, transcript_filename) + if os.path.isfile(transcript_path): + file_entry['has_transcript'] = True + transcript_rel_path = os.path.join(subpath, "Transkription", transcript_filename) if subpath else os.path.join("Transkription", transcript_filename) + file_entry['transcript_url'] = url_for('get_transcript', subpath=transcript_rel_path.replace(os.sep, '/')) else: file_entry['has_transcript'] = False - files.append(file_entry) + else: + file_entry['has_transcript'] = False + files.append(file_entry) except PermissionError: pass @@ -191,10 +195,8 @@ def serve_file(subpath): mime, _ = mimetypes.guess_type(full_path) mime = mime or 'application/octet-stream' - if mime and mime.startswith('image/'): - pass # do not log access to images - - else: + # logging only for mp3 + if mime and mime.startswith('audio/mpeg'): # HEAD request are coming in to initiate server caching. # only log initial hits and not the reload of further file parts range_header = request.headers.get('Range') diff --git a/check_ssh_tunnel.sh b/check_ssh_tunnel.sh index 17b4e60..e560d62 100755 --- a/check_ssh_tunnel.sh +++ b/check_ssh_tunnel.sh @@ -16,15 +16,13 @@ SERVER1_MOUNT_POINTS=( "/mnt/Gottesdienste Speyer" "/mnt/Besondere Gottesdienste" "/mnt/Liedersammlung" - "/mnt/Jungschar" - "/mnt/Jugend" + "/mnt/app_share" ) SERVER1_NFS_SHARES=( "/volume1/Aufnahme-stereo/010 Gottesdienste ARCHIV" "/volume1/Aufnahme-stereo/013 Besondere Gottesdienste" "/volume1/Aufnahme-stereo/014 Liedersammlung" - "/volume1/app.share/Jungschar" - "/volume1/app.share/Jugend" + "/volume1/app_share" ) # Server 2 Configuration diff --git a/static/app.js b/static/app.js index 415b06a..2ed3b39 100644 --- a/static/app.js +++ b/static/app.js @@ -300,6 +300,9 @@ document.querySelectorAll('.play-file').forEach(link => { } else if (fileType === 'image') { // Open the gallery modal for image files. openGalleryModal(relUrl); + } else { + // serve like a download + window.location.href = `/media/${relUrl}`; } }); });