From 975579ab2650b75dd4bbf2a44037fac7ef67eb5d Mon Sep 17 00:00:00 2001 From: Deluan Date: Sat, 28 Nov 2020 10:24:55 -0500 Subject: [PATCH] Add option for player to report real paths in Subsonic API. Closes #625 --- .../20201128100726_add_real-path_option.go | 23 +++++++++++++++++++ model/player.go | 19 +++++++-------- resources/i18n/pt.json | 5 ++-- server/subsonic/helpers.go | 7 +++++- ui/src/i18n/en.json | 3 ++- ui/src/player/PlayerEdit.js | 2 ++ 6 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 db/migration/20201128100726_add_real-path_option.go diff --git a/db/migration/20201128100726_add_real-path_option.go b/db/migration/20201128100726_add_real-path_option.go new file mode 100644 index 000000000..d3c7ec88a --- /dev/null +++ b/db/migration/20201128100726_add_real-path_option.go @@ -0,0 +1,23 @@ +package migration + +import ( + "database/sql" + + "github.com/pressly/goose" +) + +func init() { + goose.AddMigration(Up20201128100726, Down20201128100726) +} + +func Up20201128100726(tx *sql.Tx) error { + _, err := tx.Exec(` +alter table player + add report_real_path bool default FALSE not null; +`) + return err +} + +func Down20201128100726(tx *sql.Tx) error { + return nil +} diff --git a/model/player.go b/model/player.go index 3fc855102..36ad3b2eb 100644 --- a/model/player.go +++ b/model/player.go @@ -5,15 +5,16 @@ import ( ) type Player struct { - ID string `json:"id" orm:"column(id)"` - Name string `json:"name"` - Type string `json:"type"` - UserName string `json:"userName"` - Client string `json:"client"` - IPAddress string `json:"ipAddress"` - LastSeen time.Time `json:"lastSeen"` - TranscodingId string `json:"transcodingId"` - MaxBitRate int `json:"maxBitRate"` + ID string `json:"id" orm:"column(id)"` + Name string `json:"name"` + Type string `json:"type"` + UserName string `json:"userName"` + Client string `json:"client"` + IPAddress string `json:"ipAddress"` + LastSeen time.Time `json:"lastSeen"` + TranscodingId string `json:"transcodingId"` + MaxBitRate int `json:"maxBitRate"` + ReportRealPath bool `json:"reportRealPath"` } type Players []Player diff --git a/resources/i18n/pt.json b/resources/i18n/pt.json index d013f9bd7..66dd298fa 100644 --- a/resources/i18n/pt.json +++ b/resources/i18n/pt.json @@ -92,7 +92,8 @@ "maxBitRate": "Bitrate máx", "client": "Cliente", "userName": "Usuário", - "lastSeen": "Últ. acesso" + "lastSeen": "Últ. acesso", + "reportRealPath": "Use paths reais" } }, "transcoding": { @@ -323,4 +324,4 @@ "serverUptime": "Uptime do servidor", "serverDown": "DESCONECTADO" } -} \ No newline at end of file +} diff --git a/server/subsonic/helpers.go b/server/subsonic/helpers.go index 768e215d4..6ce14cf47 100644 --- a/server/subsonic/helpers.go +++ b/server/subsonic/helpers.go @@ -147,7 +147,12 @@ func childFromMediaFile(ctx context.Context, mf model.MediaFile) responses.Child child.CoverArt = "al-" + mf.AlbumID } child.ContentType = mf.ContentType() - child.Path = fmt.Sprintf("%s/%s/%s.%s", realArtistName(mf), mf.Album, mf.Title, mf.Suffix) + player, ok := request.PlayerFrom(ctx) + if ok && player.ReportRealPath { + child.Path = mf.Path + } else { + child.Path = fmt.Sprintf("%s/%s/%s.%s", realArtistName(mf), mf.Album, mf.Title, mf.Suffix) + } child.DiscNumber = mf.DiscNumber child.Created = &mf.CreatedAt child.AlbumId = mf.AlbumID diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json index 2ac1cb4fa..422b59e13 100644 --- a/ui/src/i18n/en.json +++ b/ui/src/i18n/en.json @@ -92,7 +92,8 @@ "maxBitRate": "Max. Bit Rate", "client": "Client", "userName": "Username", - "lastSeen": "Last Seen At" + "lastSeen": "Last Seen At", + "reportRealPath": "Report Real Path" } }, "transcoding": { diff --git a/ui/src/player/PlayerEdit.js b/ui/src/player/PlayerEdit.js index 0da820204..1c8f8dec7 100644 --- a/ui/src/player/PlayerEdit.js +++ b/ui/src/player/PlayerEdit.js @@ -1,6 +1,7 @@ import React from 'react' import { TextInput, + BooleanInput, TextField, Edit, required, @@ -45,6 +46,7 @@ const PlayerEdit = (props) => ( { id: 0, name: '-' }, ]} /> +