diff --git a/resources/i18n/ar.json b/resources/i18n/ar.json index d7902c14b..3c09c6284 100644 --- a/resources/i18n/ar.json +++ b/resources/i18n/ar.json @@ -196,6 +196,13 @@ "updatedAt": "آخر تحديث", "createdAt": "تاريخ الإنشاء", "downloadable": "هل يسمح بالتنزيل؟" + }, + "actions": { + "download": { + "title": "تحميل", + "currentTrack": "المقطع الحالي", + "allTracks": "جميع المقاطع" + } } } }, diff --git a/resources/i18n/bg.json b/resources/i18n/bg.json index 7a0281f33..830ffc8cf 100644 --- a/resources/i18n/bg.json +++ b/resources/i18n/bg.json @@ -256,6 +256,13 @@ "updatedAt": "Актуализирана на", "createdAt": "Създадена на", "downloadable": "Разреши изтегляния?" + }, + "actions": { + "download": { + "title": "Изтегляне", + "currentTrack": "Текуща песен", + "allTracks": "Всички песни" + } } }, "missing": { diff --git a/resources/i18n/bs.json b/resources/i18n/bs.json index 9d5c552e7..77f5be3bd 100644 --- a/resources/i18n/bs.json +++ b/resources/i18n/bs.json @@ -253,6 +253,13 @@ "updatedAt": "Ažurirano", "createdAt": "Kreirano", "downloadable": "Dozvoli preuzimanje?" + }, + "actions": { + "download": { + "title": "Preuzmi", + "currentTrack": "Trenutna pjesma", + "allTracks": "Sve pjesme" + } } }, "missing": { diff --git a/resources/i18n/ca.json b/resources/i18n/ca.json index 1ef2ce016..34c0b3537 100644 --- a/resources/i18n/ca.json +++ b/resources/i18n/ca.json @@ -256,6 +256,13 @@ "updatedAt": "Actualitzat", "createdAt": "Creat", "downloadable": "Permet descarregar?" + }, + "actions": { + "download": { + "title": "Descarrega", + "currentTrack": "Pista actual", + "allTracks": "Totes les pistes" + } } }, "missing": { diff --git a/resources/i18n/cs.json b/resources/i18n/cs.json index fc2cc959d..8608ccec6 100644 --- a/resources/i18n/cs.json +++ b/resources/i18n/cs.json @@ -196,6 +196,13 @@ "updatedAt": "Nahráno", "createdAt": "Vytvořeno", "downloadable": "Povolit stahování?" + }, + "actions": { + "download": { + "title": "Stáhnout", + "currentTrack": "Aktuální skladba", + "allTracks": "Všechny skladby" + } } } }, diff --git a/resources/i18n/da.json b/resources/i18n/da.json index edb1df183..7fb48cdba 100644 --- a/resources/i18n/da.json +++ b/resources/i18n/da.json @@ -256,6 +256,13 @@ "updatedAt": "Opdateret d.", "createdAt": "Oprettet d.", "downloadable": "Tillad downloads?" + }, + "actions": { + "download": { + "title": "Download", + "currentTrack": "Nuværende nummer", + "allTracks": "Alle numre" + } } }, "missing": { @@ -718,4 +725,4 @@ "empty": "Intet afspilles nu", "minutesAgo": "for %{smart_count} minut siden |||| for %{smart_count} minutter siden" } -} \ No newline at end of file +} diff --git a/resources/i18n/de.json b/resources/i18n/de.json index 1a516d393..55c2fdd89 100644 --- a/resources/i18n/de.json +++ b/resources/i18n/de.json @@ -258,6 +258,13 @@ "updatedAt": "Geändert am", "createdAt": "Erstellt am", "downloadable": "Downloads erlauben?" + }, + "actions": { + "download": { + "title": "Herunterladen", + "currentTrack": "Aktueller Titel", + "allTracks": "Alle Titel" + } } }, "missing": { @@ -720,4 +727,4 @@ "empty": "Keine Wiedergabe", "minutesAgo": "Vor %{smart_count} Minute |||| Vor %{smart_count} Minuten" } -} \ No newline at end of file +} diff --git a/resources/i18n/el.json b/resources/i18n/el.json index 3876c2e33..d6810fdcf 100644 --- a/resources/i18n/el.json +++ b/resources/i18n/el.json @@ -256,6 +256,13 @@ "updatedAt": "Ενημερώθηκε στις", "createdAt": "Δημιουργήθηκε στις", "downloadable": "Επιτρέπονται οι λήψεις?" + }, + "actions": { + "download": { + "title": "Λήψη", + "currentTrack": "Τρέχον κομμάτι", + "allTracks": "Όλα τα κομμάτια" + } } }, "missing": { @@ -718,4 +725,4 @@ "empty": "Δεν παίζει τίποτα", "minutesAgo": "%{smart_count} λεπτό πριν |||| %{smart_count} λεπτά πριν" } -} \ No newline at end of file +} diff --git a/resources/i18n/eo.json b/resources/i18n/eo.json index 60eaa6d7c..0f121c457 100644 --- a/resources/i18n/eo.json +++ b/resources/i18n/eo.json @@ -256,6 +256,13 @@ "updatedAt": "Ĝisdatiĝis je", "createdAt": "Fariĝis je", "downloadable": "Ĉu Ebligi Elŝutojn?" + }, + "actions": { + "download": { + "title": "Elŝuti", + "currentTrack": "Nuna trako", + "allTracks": "Ĉiuj trakoj" + } } }, "missing": { @@ -718,4 +725,4 @@ "empty": "Nenio ludas", "minutesAgo": "Antaŭ %{smart_count} minuto |||| Antaŭ %{smart_count} minutoj" } -} \ No newline at end of file +} diff --git a/resources/i18n/es.json b/resources/i18n/es.json index 555c165d6..1483bddd2 100644 --- a/resources/i18n/es.json +++ b/resources/i18n/es.json @@ -258,6 +258,13 @@ "updatedAt": "Actualizado el", "createdAt": "Creado el", "downloadable": "¿Permitir descargas?" + }, + "actions": { + "download": { + "title": "Descargar", + "currentTrack": "Pista actual", + "allTracks": "Todas las pistas" + } } }, "missing": { @@ -720,4 +727,4 @@ "empty": "Nada en reproducción", "minutesAgo": "Hace %{smart_count} minuto |||| Hace %{smart_count} minutos" } -} \ No newline at end of file +} diff --git a/resources/i18n/eu.json b/resources/i18n/eu.json index 30db91cde..72f21250a 100644 --- a/resources/i18n/eu.json +++ b/resources/i18n/eu.json @@ -260,7 +260,13 @@ "createdAt": "Sortze-data:" }, "notifications": {}, - "actions": {} + "actions": { + "download": { + "title": "Deskargatu", + "currentTrack": "Uneko pista", + "allTracks": "Pista guztiak" + } + } }, "missing": { "name": "Aurkitu ez den fitxategia |||| Aurkitu ez diren fitxategiak", @@ -601,7 +607,7 @@ "shareSuccess": "URLa arbelera kopiatu da: %{url}", "shareFailure": "Errorea %{url} URLa arbelera kopiatzean", "downloadDialogTitle": "Deskargatu '%{name}' %{resource}, (%{size})", - "downloadOriginalFormat": "Deskargatu jatorrizko formatua" + "downloadOriginalFormat": "Deskargatu jatorrizko formatua" }, "menu": { "library": "Liburutegia", diff --git a/resources/i18n/fa.json b/resources/i18n/fa.json index 86504afef..cbe74691f 100644 --- a/resources/i18n/fa.json +++ b/resources/i18n/fa.json @@ -196,6 +196,13 @@ "updatedAt": "", "createdAt": "", "downloadable": "" + }, + "actions": { + "download": { + "title": "دانلود", + "currentTrack": "آهنگ فعلی", + "allTracks": "همه آهنگها" + } } } }, @@ -457,4 +464,4 @@ "current_song": "" } } -} +} \ No newline at end of file diff --git a/resources/i18n/fi.json b/resources/i18n/fi.json index 0e6149f87..32c207fe9 100644 --- a/resources/i18n/fi.json +++ b/resources/i18n/fi.json @@ -258,6 +258,13 @@ "updatedAt": "Päivitetty", "createdAt": "Luotu", "downloadable": "Salli lataus?" + }, + "actions": { + "download": { + "title": "Lataa", + "currentTrack": "Nykyinen kappale", + "allTracks": "Kaikki kappaleet" + } } }, "missing": { @@ -720,4 +727,4 @@ "empty": "Ei soita mitään", "minutesAgo": "%{smart_count} minuutti sitten |||| %{smart_count} minuuttia sitten" } -} \ No newline at end of file +} diff --git a/resources/i18n/fr.json b/resources/i18n/fr.json index dae9f47e7..d29c5ac0b 100644 --- a/resources/i18n/fr.json +++ b/resources/i18n/fr.json @@ -256,6 +256,13 @@ "updatedAt": "Mis à jour le", "createdAt": "Créé le", "downloadable": "Autoriser les téléchargements ?" + }, + "actions": { + "download": { + "title": "Télécharger", + "currentTrack": "Piste en cours", + "allTracks": "Toutes les pistes" + } } }, "missing": { @@ -718,4 +725,4 @@ "empty": "Aucun titre en cours de lecture", "minutesAgo": "Il y a %{smart_count} minute |||| Il y a %{smart_count} minutes" } -} \ No newline at end of file +} diff --git a/resources/i18n/gl.json b/resources/i18n/gl.json index 444998d03..bd7f5d263 100644 --- a/resources/i18n/gl.json +++ b/resources/i18n/gl.json @@ -258,6 +258,13 @@ "updatedAt": "Actualizada o", "createdAt": "Creada o", "downloadable": "Permitir descargas?" + }, + "actions": { + "download": { + "title": "Descargar", + "currentTrack": "Pista actual", + "allTracks": "Todas as pistas" + } } }, "missing": { @@ -720,4 +727,4 @@ "empty": "Sen reprodución", "minutesAgo": "hai %{smart_count} minuto |||| hai %{smart_count} minutos" } -} \ No newline at end of file +} diff --git a/resources/i18n/hi.json b/resources/i18n/hi.json index 5b9ece530..44ff7bd96 100644 --- a/resources/i18n/hi.json +++ b/resources/i18n/hi.json @@ -255,7 +255,13 @@ "createdAt": "बनाया गया" }, "notifications": {}, - "actions": {} + "actions": { + "download": { + "title": "डाउनलोड", + "currentTrack": "वर्तमान ट्रैक", + "allTracks": "सभी ट्रैक" + } + } }, "missing": { "name": "गुम फ़ाइल |||| गुम फ़ाइलें", diff --git a/resources/i18n/hu.json b/resources/i18n/hu.json index ce3d5ae87..f7a03201a 100644 --- a/resources/i18n/hu.json +++ b/resources/i18n/hu.json @@ -256,6 +256,13 @@ "updatedAt": "Frissítve", "createdAt": "Létrehozva", "downloadable": "Engedélyezed a letöltéseket?" + }, + "actions": { + "download": { + "title": "Letöltés", + "currentTrack": "Jelenlegi szám", + "allTracks": "Összes szám" + } } }, "missing": { @@ -715,4 +722,4 @@ "current_song": "Aktuális számhoz ugrás" } } -} \ No newline at end of file +} diff --git a/resources/i18n/id.json b/resources/i18n/id.json index 762ce4ebb..c17bfecfd 100644 --- a/resources/i18n/id.json +++ b/resources/i18n/id.json @@ -258,6 +258,13 @@ "updatedAt": "Diperbarui pada", "createdAt": "Dibuat pada", "downloadable": "Izinkan Pengunduhan?" + }, + "actions": { + "download": { + "title": "Unduh", + "currentTrack": "Trek saat ini", + "allTracks": "Semua trek" + } } }, "missing": { @@ -720,4 +727,4 @@ "empty": "Tidak ada yang diputar", "minutesAgo": "%{smart_count} menit yang lalu |||| %{smart_count} menit yang lalu" } -} \ No newline at end of file +} diff --git a/resources/i18n/it.json b/resources/i18n/it.json index 656043589..85cfbc2c5 100644 --- a/resources/i18n/it.json +++ b/resources/i18n/it.json @@ -261,7 +261,13 @@ "createdAt": "Data di creazione" }, "notifications": {}, - "actions": {} + "actions": { + "download": { + "title": "Scarica", + "currentTrack": "Traccia corrente", + "allTracks": "Tutte le tracce" + } + } }, "missing": { "name": "File mancante |||| File mancanti", diff --git a/resources/i18n/ja.json b/resources/i18n/ja.json index 29975b92b..3c0668432 100644 --- a/resources/i18n/ja.json +++ b/resources/i18n/ja.json @@ -253,6 +253,13 @@ "updatedAt": "更新日", "createdAt": "作成日", "downloadable": "ダウンロードを許可しますか?" + }, + "actions": { + "download": { + "title": "ダウンロード", + "currentTrack": "現在のトラック", + "allTracks": "すべてのトラック" + } } }, "missing": { @@ -631,4 +638,4 @@ "empty": "何も再生されていません", "minutesAgo": "%{smart_count} 分前 |||| %{smart_count} 分前" } -} \ No newline at end of file +} diff --git a/resources/i18n/ko.json b/resources/i18n/ko.json index 6b81e02d8..7f0eb5239 100644 --- a/resources/i18n/ko.json +++ b/resources/i18n/ko.json @@ -12,7 +12,7 @@ "artist": "아티스트", "album": "앨범", "path": "파일 경로", - "libraryName": "라이브러리", + "libraryName": "라이브러리", "genre": "장르", "compilation": "컴필레이션", "year": "년", @@ -183,7 +183,7 @@ "scrobbleEnabled": "외부 서비스에 스크로블 보내기" } }, -"transcoding": { + "transcoding": { "name": "트랜스코딩 |||| 트랜스코딩", "fields": { "name": "이름", @@ -254,7 +254,13 @@ "createdAt": "생성됨" }, "notifications": {}, - "actions": {} + "actions": { + "download": { + "title": "다운로드", + "currentTrack": "현재 트랙", + "allTracks": "모든 트랙" + } + } }, "missing": { "name": "누락 파일 |||| 누락 파일들", diff --git a/resources/i18n/nl.json b/resources/i18n/nl.json index 46c3df9de..f014f114b 100644 --- a/resources/i18n/nl.json +++ b/resources/i18n/nl.json @@ -258,6 +258,13 @@ "updatedAt": "Bijgewerkt op", "createdAt": "Aangemaakt op", "downloadable": "Downloads toestaan?" + }, + "actions": { + "download": { + "title": "Downloaden", + "currentTrack": "Huidig nummer", + "allTracks": "Alle nummers" + } } }, "missing": { @@ -720,4 +727,4 @@ "empty": "Er wordt niets afgespeed", "minutesAgo": "%{smart_count} minuut geleden |||| %{smart_count} minuten geleden" } -} \ No newline at end of file +} diff --git a/resources/i18n/no.json b/resources/i18n/no.json index 3b75bab25..95913aa50 100644 --- a/resources/i18n/no.json +++ b/resources/i18n/no.json @@ -253,6 +253,13 @@ "updatedAt": "Oppdatert", "createdAt": "Opprettet", "downloadable": "Tillat Nedlastinger?" + }, + "actions": { + "download": { + "title": "Last ned", + "currentTrack": "Gjeldende spor", + "allTracks": "Alle spor" + } } }, "missing": { @@ -631,4 +638,4 @@ "empty": "", "minutesAgo": "" } -} \ No newline at end of file +} diff --git a/resources/i18n/pl.json b/resources/i18n/pl.json index 6229798e9..7c2b4f5ec 100644 --- a/resources/i18n/pl.json +++ b/resources/i18n/pl.json @@ -255,6 +255,13 @@ "updatedAt": "Zaktualizowano", "createdAt": "Stworzono", "downloadable": "Zezwolić Na Pobieranie?" + }, + "actions": { + "download": { + "title": "Pobierz", + "currentTrack": "Bieżący utwór", + "allTracks": "Wszystkie utwory" + } } }, "missing": { @@ -708,4 +715,4 @@ "empty": "Nic nie jest odtwarzane", "minutesAgo": "%{smart_count} minutę temu |||| %{smart_count} minut temu" } -} \ No newline at end of file +} diff --git a/resources/i18n/pt-br.json b/resources/i18n/pt-br.json index b3b3bab2f..491d29b4a 100644 --- a/resources/i18n/pt-br.json +++ b/resources/i18n/pt-br.json @@ -258,6 +258,13 @@ "updatedAt": "Últ. Atualização", "createdAt": "Data de Criação", "downloadable": "Permitir Baixar?" + }, + "actions": { + "download": { + "title": "Baixar", + "currentTrack": "Faixa atual", + "allTracks": "Todas as faixas" + } } }, "missing": { @@ -720,4 +727,4 @@ "empty": "Nada tocando", "minutesAgo": "%{smart_count} minuto atrás |||| %{smart_count} minutos atrás" } -} \ No newline at end of file +} diff --git a/resources/i18n/ru.json b/resources/i18n/ru.json index 1a7adcc4a..c13d13030 100644 --- a/resources/i18n/ru.json +++ b/resources/i18n/ru.json @@ -258,6 +258,13 @@ "updatedAt": "Обновлено", "createdAt": "Создано", "downloadable": "Разрешить загрузку?" + }, + "actions": { + "download": { + "title": "Скачать", + "currentTrack": "Текущий трек", + "allTracks": "Все треки" + } } }, "missing": { diff --git a/resources/i18n/sl.json b/resources/i18n/sl.json index ceb56e9b7..030e4c759 100644 --- a/resources/i18n/sl.json +++ b/resources/i18n/sl.json @@ -256,6 +256,13 @@ "updatedAt": "Posodobljeno ob", "createdAt": "Ustvarjeno ob", "downloadable": "Dovoli prenose?" + }, + "actions": { + "download": { + "title": "Prenesi", + "currentTrack": "Trenutna skladba", + "allTracks": "Vse skladbe" + } } }, "missing": { diff --git a/resources/i18n/sr.json b/resources/i18n/sr.json index cf0fc5d2f..bf5bd746e 100644 --- a/resources/i18n/sr.json +++ b/resources/i18n/sr.json @@ -260,7 +260,13 @@ "createdAt": "Креирано" }, "notifications": {}, - "actions": {} + "actions": { + "download": { + "title": "Преузми", + "currentTrack": "Тренутна песма", + "allTracks": "Све песме" + } + } }, "missing": { "name": "Фајл који недостаје|||| Фајлови који недостају", diff --git a/resources/i18n/sv.json b/resources/i18n/sv.json index 228cc2cf3..5d4f0c419 100644 --- a/resources/i18n/sv.json +++ b/resources/i18n/sv.json @@ -256,6 +256,13 @@ "updatedAt": "Uppdaterad", "createdAt": "Skapad", "downloadable": "Tillåt nedladdning?" + }, + "actions": { + "download": { + "title": "Ladda ner", + "currentTrack": "Nuvarande spår", + "allTracks": "Alla spår" + } } }, "missing": { @@ -718,4 +725,4 @@ "empty": "Inget spelas", "minutesAgo": "%{smart_count} minut sedan |||| %{smart_count} minuter sedan" } -} \ No newline at end of file +} diff --git a/resources/i18n/th.json b/resources/i18n/th.json index fde89494e..55944e173 100644 --- a/resources/i18n/th.json +++ b/resources/i18n/th.json @@ -258,6 +258,13 @@ "updatedAt": "อัปเดตเมื่อ", "createdAt": "สร้างเมื่อ", "downloadable": "อนุญาตให้ดาวโหลด?" + }, + "actions": { + "download": { + "title": "ดาวน์โหลด", + "currentTrack": "แทร็กปัจจุบัน", + "allTracks": "แทร็กทั้งหมด" + } } }, "missing": { @@ -720,4 +727,4 @@ "empty": "ไม่มีเพลงเล่น", "minutesAgo": "%{smart_count} นาทีที่แล้ว |||| %{smart_count} นาทีที่แล้ว" } -} \ No newline at end of file +} diff --git a/resources/i18n/tr.json b/resources/i18n/tr.json index ff387aff8..5eb29e2d7 100644 --- a/resources/i18n/tr.json +++ b/resources/i18n/tr.json @@ -258,6 +258,13 @@ "updatedAt": "Güncelleme Tarihi", "createdAt": "Oluşturma Tarihi", "downloadable": "İndirmelere İzin Ver" + }, + "actions": { + "download": { + "title": "İndir", + "currentTrack": "Mevcut parça", + "allTracks": "Tüm parçalar" + } } }, "missing": { @@ -720,4 +727,4 @@ "empty": "Çalan şarkı yok", "minutesAgo": "%{smart_count} dakika önce" } -} \ No newline at end of file +} diff --git a/resources/i18n/uk.json b/resources/i18n/uk.json index c5644fde7..bc0df5f04 100644 --- a/resources/i18n/uk.json +++ b/resources/i18n/uk.json @@ -256,6 +256,13 @@ "updatedAt": "Оновлено", "createdAt": "Створено", "downloadable": "Дозволити завантаження?" + }, + "actions": { + "download": { + "title": "Завантажити", + "currentTrack": "Поточний трек", + "allTracks": "Усі треки" + } } }, "missing": { @@ -718,4 +725,4 @@ "empty": "Нічого не грає", "minutesAgo": "%{smart_count} хвилин тому |||| %{smart_count} хвилин тому" } -} \ No newline at end of file +} diff --git a/resources/i18n/zh-Hans.json b/resources/i18n/zh-Hans.json index 21778506a..495bc26d5 100644 --- a/resources/i18n/zh-Hans.json +++ b/resources/i18n/zh-Hans.json @@ -260,7 +260,13 @@ "createdAt": "创建于" }, "notifications": {}, - "actions": {} + "actions": { + "download": { + "title": "下载", + "currentTrack": "当前曲目", + "allTracks": "所有曲目" + } + } }, "missing": { "name": "丢失文件", diff --git a/resources/i18n/zh-Hant.json b/resources/i18n/zh-Hant.json index d00ae2ac3..b7f799b7a 100644 --- a/resources/i18n/zh-Hant.json +++ b/resources/i18n/zh-Hant.json @@ -258,6 +258,13 @@ "updatedAt": "更新於", "createdAt": "建立於", "downloadable": "允許下載?" + }, + "actions": { + "download": { + "title": "下載", + "currentTrack": "目前曲目", + "allTracks": "所有曲目" + } } }, "missing": { @@ -720,4 +727,4 @@ "empty": "無播放內容", "minutesAgo": "1 分鐘前 |||| %{smart_count} 分鐘前" } -} \ No newline at end of file +} diff --git a/server/public/handle_streams.go b/server/public/handle_streams.go index 15abab693..8828c891c 100644 --- a/server/public/handle_streams.go +++ b/server/public/handle_streams.go @@ -2,11 +2,15 @@ package public import ( "errors" + "fmt" + "mime" "net/http" "slices" "strconv" + "strings" "time" + "github.com/navidrome/navidrome/conf" "github.com/navidrome/navidrome/core/auth" streampkg "github.com/navidrome/navidrome/core/stream" "github.com/navidrome/navidrome/log" @@ -84,6 +88,12 @@ func (pub *Router) handleStream(w http.ResponseWriter, r *http.Request) { w.Header().Set("X-Content-Type-Options", "nosniff") w.Header().Set("X-Content-Duration", strconv.FormatFloat(float64(stream.Duration()), 'G', -1, 32)) + if conf.Server.EnableDownloads && p.BoolOr("download", false) { + w.Header().Set("Content-Disposition", mime.FormatMediaType( + "attachment", map[string]string{"filename": downloadFilename(mf, info.format)}, + )) + } + n, err := stream.Serve(ctx, w, r) if err != nil || n == 0 { http.Error(w, "internal error", http.StatusInternalServerError) @@ -124,3 +134,15 @@ func decodeStreamInfo(tokenString string) (shareTrackInfo, error) { shareID: c.ShareID, }, nil } + +func sanitizeName(target string) string { + return strings.ReplaceAll(target, "/", "_") +} + +func downloadFilename(mf *model.MediaFile, format string) string { + ext := mf.Suffix + if format != "" && format != "raw" { + ext = format + } + return fmt.Sprintf("%s - %s.%s", sanitizeName(mf.Artist), sanitizeName(mf.Title), ext) +} diff --git a/server/public/handle_streams_test.go b/server/public/handle_streams_test.go index 2f32ea6f2..d29b62849 100644 --- a/server/public/handle_streams_test.go +++ b/server/public/handle_streams_test.go @@ -246,3 +246,52 @@ var _ = Describe("handleStream", func() { Expect(w.Code).To(Equal(http.StatusBadRequest)) }) }) + +var _ = Describe("sanitizeName", func() { + It("leaves a plain string unchanged", func() { + Expect(sanitizeName("Artist Name")).To(Equal("Artist Name")) + }) + + It("replaces a single slash with an underscore", func() { + Expect(sanitizeName("AC/DC")).To(Equal("AC_DC")) + }) + + It("replaces multiple slashes with underscores", func() { + Expect(sanitizeName("a/b/c")).To(Equal("a_b_c")) + }) +}) + +var _ = Describe("downloadFilename", func() { + var mf *model.MediaFile + + BeforeEach(func() { + mf = &model.MediaFile{ + Artist: "The Beatles", + Title: "Hey Jude", + Suffix: "flac", + UpdatedAt: time.Now(), + } + }) + + It("uses the media file suffix when format is empty", func() { + Expect(downloadFilename(mf, "")).To(Equal("The Beatles - Hey Jude.flac")) + }) + + It("uses the media file suffix when format is 'raw'", func() { + Expect(downloadFilename(mf, "raw")).To(Equal("The Beatles - Hey Jude.flac")) + }) + + It("uses the format as the extension when a real format is given", func() { + Expect(downloadFilename(mf, "mp3")).To(Equal("The Beatles - Hey Jude.mp3")) + }) + + It("sanitizes slashes in the artist name", func() { + mf.Artist = "AC/DC" + Expect(downloadFilename(mf, "")).To(Equal("AC_DC - Hey Jude.flac")) + }) + + It("sanitizes slashes in the title", func() { + mf.Title = "Love/Hate" + Expect(downloadFilename(mf, "")).To(Equal("The Beatles - Love_Hate.flac")) + }) +}) diff --git a/server/serve_index.go b/server/serve_index.go index a538daf1a..c0b31780e 100644 --- a/server/serve_index.go +++ b/server/serve_index.go @@ -161,6 +161,9 @@ func addShareData(r *http.Request, data map[string]any, shareInfo *model.Share) Description: shareInfo.Description, Downloadable: shareInfo.Downloadable, } + if sd.Description == "" { + sd.Description = shareInfo.Contents + } sd.Tracks = slice.Map(shareInfo.Tracks, func(mf model.MediaFile) shareTrack { return shareTrack{ ID: mf.ID, diff --git a/server/serve_index_test.go b/server/serve_index_test.go index 78f3873b8..6f0bf3ee3 100644 --- a/server/serve_index_test.go +++ b/server/serve_index_test.go @@ -312,6 +312,13 @@ var _ = Describe("addShareData", func() { addShareData(r, data, shareInfo) Expect(data["ShareDescription"]).To(Equal(shareInfo.Contents)) }) + It("should use shareInfo.Contents as ShareInfo.Description", func() { + addShareData(r, data, shareInfo) + var sd shareData + err := json.Unmarshal([]byte(data["ShareInfo"].(string)), &sd) + Expect(err).NotTo(HaveOccurred()) + Expect(sd.Description).To(Equal(shareInfo.Contents)) + }) }) }) }) diff --git a/ui/index.html b/ui/index.html index 827751856..55a6fc572 100644 --- a/ui/index.html +++ b/ui/index.html @@ -26,7 +26,7 @@ -