From 3be069d9ecb384f06d6c4c63920020080b9e9435 Mon Sep 17 00:00:00 2001 From: lelo Date: Fri, 2 May 2025 16:14:17 +0200 Subject: [PATCH] improve sharing links --- app.py | 22 +++++++++++++++++++--- static/app.js | 34 ++-------------------------------- static/functions.js | 28 ++++++++++++++++++++++++++++ templates/app.html | 1 + templates/mylinks.html | 17 +++++++---------- 5 files changed, 57 insertions(+), 45 deletions(-) create mode 100644 static/functions.js diff --git a/app.py b/app.py index be8c101..a9a0e8a 100755 --- a/app.py +++ b/app.py @@ -103,6 +103,11 @@ def list_directory_contents(directory, subpath): transcription_dir = os.path.join(directory, "Transkription") transcription_exists = os.path.isdir(transcription_dir) + direct_directories = [] + for item in folder_config: + for folder in item['folders']: + direct_directories.append(folder['foldername']) + # Define allowed file extensions. music_exts = ('.mp3',) image_exts = ('.jpg', '.jpeg', '.png', '.gif', '.bmp') @@ -125,7 +130,16 @@ def list_directory_contents(directory, subpath): if entry.name in ["Transkription", "@eaDir"]: continue rel_path = os.path.join(subpath, entry.name) if subpath else entry.name - directories.append({'name': entry.name, 'path': rel_path.replace(os.sep, '/')}) + + # check if path is inside a direct directory --> shareable + if subpath.split('/')[0] in direct_directories: + allow_share = True + else: + allow_share = False + + # build directory entry + directories.append({'name': entry.name, 'path': rel_path.replace(os.sep, '/'), 'share': allow_share}) + elif entry.is_file(follow_symlinks=False): lower_name = entry.name.lower() @@ -138,7 +152,10 @@ def list_directory_contents(directory, subpath): file_type = 'image' else: file_type = 'other' + + # build file entry 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] @@ -206,7 +223,7 @@ def serve_sw(): def api_browse(subpath): if subpath == '': # root directory foldernames = [] - for foldername, folderpath in session['folders'].items(): + for foldername, _ in session['folders'].items(): foldernames.append({'name': foldername, 'path': foldername}) return jsonify({ @@ -421,7 +438,6 @@ def create_share(subpath): return "Unauthorized", 403 paths = {} - for item in folder_config: for folder in item['folders']: paths[folder['foldername']] = folder['folderpath'] diff --git a/static/app.js b/static/app.js index 5f473e5..3f35783 100644 --- a/static/app.js +++ b/static/app.js @@ -81,7 +81,7 @@ function renderContent(data) { if (areAllShort && data.breadcrumbs.length !== 1) { contentHTML += '
'; data.directories.forEach(dir => { - if (admin_enabled && data.breadcrumbs.length != 1) { + if (admin_enabled && data.breadcrumbs.length != 1 && dir.share) { share_link = `⚙️`; } contentHTML += `
📁 ${dir.name} @@ -92,7 +92,7 @@ function renderContent(data) { } else { contentHTML += '
    '; data.directories.forEach(dir => { - if (admin_enabled && data.breadcrumbs.length != 1) { + if (admin_enabled && data.breadcrumbs.length != 1 && dir.share) { share_link = `⚙️`; } contentHTML += `
  • 📁 ${dir.name} @@ -542,34 +542,4 @@ function syncThemeColor() { .forEach(svg => svg.setAttribute('fill', cssVar)); } - -function copyTokenUrl(url) { - if (navigator.clipboard && window.isSecureContext) { - // Modern approach - navigator.clipboard.writeText(url) - .then(() => { - alert('Token-URL in die Zwischenablage kopiert!'); - }) - .catch(err => { - console.error('Fehler beim Kopieren: ', err); - }); - } else { - // Fallback for older browsers - const textarea = document.createElement('textarea'); - textarea.value = url; - textarea.style.position = 'fixed'; // Verhindert Scrollen - textarea.style.opacity = '0'; - document.body.appendChild(textarea); - textarea.focus(); - textarea.select(); - try { - document.execCommand('copy'); - alert('Token-URL in die Zwischenablage kopiert!'); - } catch (err) { - console.error('Fallback: Kopieren fehlgeschlagen', err); - } - document.body.removeChild(textarea); - } -} - document.addEventListener('DOMContentLoaded', syncThemeColor); \ No newline at end of file diff --git a/static/functions.js b/static/functions.js new file mode 100644 index 0000000..7e93716 --- /dev/null +++ b/static/functions.js @@ -0,0 +1,28 @@ +function toClipboard(url) { + if (navigator.clipboard && window.isSecureContext) { + // Modern approach + navigator.clipboard.writeText(url) + .then(() => { + alert('Link in die Zwischenablage kopiert!'); + }) + .catch(err => { + console.error('Fehler beim Kopieren: ', err); + }); + } else { + // Fallback for older browsers + const textarea = document.createElement('textarea'); + textarea.value = url; + textarea.style.position = 'fixed'; // Verhindert Scrollen + textarea.style.opacity = '0'; + document.body.appendChild(textarea); + textarea.focus(); + textarea.select(); + try { + document.execCommand('copy'); + alert('Token-URL in die Zwischenablage kopiert!'); + } catch (err) { + console.error('Fallback: Kopieren fehlgeschlagen', err); + } + document.body.removeChild(textarea); + } + } \ No newline at end of file diff --git a/templates/app.html b/templates/app.html index 36dd6a0..767b99e 100644 --- a/templates/app.html +++ b/templates/app.html @@ -35,6 +35,7 @@ +