allow all file types

This commit is contained in:
lelo 2025-03-26 17:52:16 +00:00
parent b348b4444f
commit d2dedf51c7
3 changed files with 32 additions and 29 deletions

52
app.py
View File

@ -76,8 +76,8 @@ def list_directory_contents(directory, subpath):
transcription_exists = os.path.isdir(transcription_dir) transcription_exists = os.path.isdir(transcription_dir)
# Define allowed file extensions. # Define allowed file extensions.
allowed_music_exts = ('.mp3',) music_exts = ('.mp3',)
allowed_image_exts = ('.jpg', '.jpeg', '.png', '.gif', '.bmp') image_exts = ('.jpg', '.jpeg', '.png', '.gif', '.bmp')
try: try:
with os.scandir(directory) as it: 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, '/')}) directories.append({'name': entry.name, 'path': rel_path.replace(os.sep, '/')})
elif entry.is_file(follow_symlinks=False): elif entry.is_file(follow_symlinks=False):
lower_name = entry.name.lower() 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 # implement file type filtering here !!!
if lower_name.endswith(allowed_music_exts): #if lower_name.endswith(music_exts) or lower_name.endswith(image_exts):
file_type = 'music' rel_path = os.path.join(subpath, entry.name) if subpath else entry.name
else: if lower_name.endswith(music_exts):
file_type = 'image' file_type = 'music'
file_entry = {'name': entry.name, 'path': rel_path.replace(os.sep, '/'), 'file_type': file_type} elif lower_name.endswith(image_exts):
# Only check for transcription if it's a audio file. file_type = 'image'
if file_type == 'music' and transcription_exists: else:
base_name = os.path.splitext(entry.name)[0] file_type = 'other'
transcript_filename = base_name + '.md' file_entry = {'name': entry.name, 'path': rel_path.replace(os.sep, '/'), 'file_type': file_type}
transcript_path = os.path.join(transcription_dir, transcript_filename) # Only check for transcription if it's a audio file.
if os.path.isfile(transcript_path): if file_type == 'music' and transcription_exists:
file_entry['has_transcript'] = True base_name = os.path.splitext(entry.name)[0]
transcript_rel_path = os.path.join(subpath, "Transkription", transcript_filename) if subpath else os.path.join("Transkription", transcript_filename) transcript_filename = base_name + '.md'
file_entry['transcript_url'] = url_for('get_transcript', subpath=transcript_rel_path.replace(os.sep, '/')) transcript_path = os.path.join(transcription_dir, transcript_filename)
else: if os.path.isfile(transcript_path):
file_entry['has_transcript'] = False 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: else:
file_entry['has_transcript'] = False file_entry['has_transcript'] = False
files.append(file_entry) else:
file_entry['has_transcript'] = False
files.append(file_entry)
except PermissionError: except PermissionError:
pass pass
@ -191,10 +195,8 @@ def serve_file(subpath):
mime, _ = mimetypes.guess_type(full_path) mime, _ = mimetypes.guess_type(full_path)
mime = mime or 'application/octet-stream' mime = mime or 'application/octet-stream'
if mime and mime.startswith('image/'): # logging only for mp3
pass # do not log access to images if mime and mime.startswith('audio/mpeg'):
else:
# HEAD request are coming in to initiate server caching. # HEAD request are coming in to initiate server caching.
# only log initial hits and not the reload of further file parts # only log initial hits and not the reload of further file parts
range_header = request.headers.get('Range') range_header = request.headers.get('Range')

View File

@ -16,15 +16,13 @@ SERVER1_MOUNT_POINTS=(
"/mnt/Gottesdienste Speyer" "/mnt/Gottesdienste Speyer"
"/mnt/Besondere Gottesdienste" "/mnt/Besondere Gottesdienste"
"/mnt/Liedersammlung" "/mnt/Liedersammlung"
"/mnt/Jungschar" "/mnt/app_share"
"/mnt/Jugend"
) )
SERVER1_NFS_SHARES=( SERVER1_NFS_SHARES=(
"/volume1/Aufnahme-stereo/010 Gottesdienste ARCHIV" "/volume1/Aufnahme-stereo/010 Gottesdienste ARCHIV"
"/volume1/Aufnahme-stereo/013 Besondere Gottesdienste" "/volume1/Aufnahme-stereo/013 Besondere Gottesdienste"
"/volume1/Aufnahme-stereo/014 Liedersammlung" "/volume1/Aufnahme-stereo/014 Liedersammlung"
"/volume1/app.share/Jungschar" "/volume1/app_share"
"/volume1/app.share/Jugend"
) )
# Server 2 Configuration # Server 2 Configuration

View File

@ -300,6 +300,9 @@ document.querySelectorAll('.play-file').forEach(link => {
} else if (fileType === 'image') { } else if (fileType === 'image') {
// Open the gallery modal for image files. // Open the gallery modal for image files.
openGalleryModal(relUrl); openGalleryModal(relUrl);
} else {
// serve like a download
window.location.href = `/media/${relUrl}`;
} }
}); });
}); });