use rel paths
This commit is contained in:
@@ -29,7 +29,7 @@ func (c *Controller) GetIndexes(w http.ResponseWriter, r *http.Request) {
|
||||
indexes = append(indexes, index)
|
||||
}
|
||||
index.Artists = append(index.Artists, &subsonic.Artist{
|
||||
ID: folder.ID,
|
||||
ID: *folder.ID,
|
||||
Name: folder.Name,
|
||||
})
|
||||
}
|
||||
@@ -58,11 +58,11 @@ func (c *Controller) GetMusicDirectory(w http.ResponseWriter, r *http.Request) {
|
||||
Find(&folders)
|
||||
for _, folder := range folders {
|
||||
childrenObj = append(childrenObj, &subsonic.Child{
|
||||
Parent: cFolder.ID,
|
||||
ID: folder.ID,
|
||||
Parent: *cFolder.ID,
|
||||
ID: *folder.ID,
|
||||
Title: folder.Name,
|
||||
IsDir: true,
|
||||
CoverID: folder.CoverID,
|
||||
CoverID: *folder.CoverID,
|
||||
})
|
||||
}
|
||||
//
|
||||
@@ -80,14 +80,14 @@ func (c *Controller) GetMusicDirectory(w http.ResponseWriter, r *http.Request) {
|
||||
track.Suffix = "mp3"
|
||||
}
|
||||
childrenObj = append(childrenObj, &subsonic.Child{
|
||||
ID: track.ID,
|
||||
ID: *track.ID,
|
||||
Album: track.Album.Title,
|
||||
Artist: track.Artist,
|
||||
ContentType: track.ContentType,
|
||||
CoverID: cFolder.CoverID,
|
||||
CoverID: *cFolder.CoverID,
|
||||
Duration: 0,
|
||||
IsDir: false,
|
||||
Parent: cFolder.ID,
|
||||
Parent: *cFolder.ID,
|
||||
Path: track.Path,
|
||||
Size: track.Size,
|
||||
Suffix: track.Suffix,
|
||||
@@ -100,8 +100,8 @@ func (c *Controller) GetMusicDirectory(w http.ResponseWriter, r *http.Request) {
|
||||
// respond section
|
||||
sub := subsonic.NewResponse()
|
||||
sub.Directory = &subsonic.Directory{
|
||||
ID: cFolder.ID,
|
||||
Parent: cFolder.ParentID,
|
||||
ID: *cFolder.ID,
|
||||
Parent: *cFolder.ParentID,
|
||||
Name: cFolder.Name,
|
||||
Children: childrenObj,
|
||||
}
|
||||
@@ -162,11 +162,11 @@ func (c *Controller) GetAlbumList(w http.ResponseWriter, r *http.Request) {
|
||||
listObj := []*subsonic.Album{}
|
||||
for _, folder := range folders {
|
||||
listObj = append(listObj, &subsonic.Album{
|
||||
ID: folder.ID,
|
||||
ID: *folder.ID,
|
||||
Title: folder.Name,
|
||||
Album: folder.Name,
|
||||
CoverID: folder.CoverID,
|
||||
ParentID: folder.ParentID,
|
||||
CoverID: *folder.CoverID,
|
||||
ParentID: *folder.ParentID,
|
||||
IsDir: true,
|
||||
Artist: folder.Parent.Name,
|
||||
})
|
||||
|
||||
@@ -27,7 +27,7 @@ func (c *Controller) GetArtists(w http.ResponseWriter, r *http.Request) {
|
||||
indexes.List = append(indexes.List, index)
|
||||
}
|
||||
index.Artists = append(index.Artists, &subsonic.Artist{
|
||||
ID: artist.ID,
|
||||
ID: *artist.ID,
|
||||
Name: artist.Name,
|
||||
})
|
||||
}
|
||||
@@ -49,17 +49,17 @@ func (c *Controller) GetArtist(w http.ResponseWriter, r *http.Request) {
|
||||
albumsObj := []*subsonic.Album{}
|
||||
for _, album := range artist.Albums {
|
||||
albumsObj = append(albumsObj, &subsonic.Album{
|
||||
ID: album.ID,
|
||||
ID: *album.ID,
|
||||
Name: album.Title,
|
||||
Created: album.CreatedAt,
|
||||
Artist: artist.Name,
|
||||
ArtistID: artist.ID,
|
||||
CoverID: album.CoverID,
|
||||
ArtistID: *artist.ID,
|
||||
CoverID: *album.CoverID,
|
||||
})
|
||||
}
|
||||
sub := subsonic.NewResponse()
|
||||
sub.Artist = &subsonic.Artist{
|
||||
ID: artist.ID,
|
||||
ID: *artist.ID,
|
||||
Name: artist.Name,
|
||||
Albums: albumsObj,
|
||||
}
|
||||
@@ -80,7 +80,7 @@ func (c *Controller) GetAlbum(w http.ResponseWriter, r *http.Request) {
|
||||
tracksObj := []*subsonic.Track{}
|
||||
for _, track := range album.Tracks {
|
||||
tracksObj = append(tracksObj, &subsonic.Track{
|
||||
ID: track.ID,
|
||||
ID: *track.ID,
|
||||
Title: track.Title,
|
||||
Artist: track.Artist, // track artist
|
||||
TrackNo: track.TrackNumber,
|
||||
@@ -90,17 +90,17 @@ func (c *Controller) GetAlbum(w http.ResponseWriter, r *http.Request) {
|
||||
Created: track.CreatedAt,
|
||||
Size: track.Size,
|
||||
Album: album.Title,
|
||||
AlbumID: album.ID,
|
||||
ArtistID: album.AlbumArtist.ID, // album artist
|
||||
CoverID: album.CoverID,
|
||||
AlbumID: *album.ID,
|
||||
ArtistID: *album.AlbumArtist.ID, // album artist
|
||||
CoverID: *album.CoverID,
|
||||
Type: "music",
|
||||
})
|
||||
}
|
||||
sub := subsonic.NewResponse()
|
||||
sub.Album = &subsonic.Album{
|
||||
ID: album.ID,
|
||||
ID: *album.ID,
|
||||
Name: album.Title,
|
||||
CoverID: album.CoverID,
|
||||
CoverID: *album.CoverID,
|
||||
Created: album.CreatedAt,
|
||||
Artist: album.AlbumArtist.Name,
|
||||
Tracks: tracksObj,
|
||||
@@ -164,12 +164,12 @@ func (c *Controller) GetAlbumListTwo(w http.ResponseWriter, r *http.Request) {
|
||||
listObj := []*subsonic.Album{}
|
||||
for _, album := range albums {
|
||||
listObj = append(listObj, &subsonic.Album{
|
||||
ID: album.ID,
|
||||
ID: *album.ID,
|
||||
Name: album.Title,
|
||||
Created: album.CreatedAt,
|
||||
CoverID: album.CoverID,
|
||||
CoverID: *album.CoverID,
|
||||
Artist: album.AlbumArtist.Name,
|
||||
ArtistID: album.AlbumArtist.ID,
|
||||
ArtistID: *album.AlbumArtist.ID,
|
||||
})
|
||||
}
|
||||
sub := subsonic.NewResponse()
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
"unicode"
|
||||
@@ -40,13 +41,14 @@ func (c *Controller) Stream(w http.ResponseWriter, r *http.Request) {
|
||||
respondError(w, r, 70, fmt.Sprintf("media with id `%d` was not found", id))
|
||||
return
|
||||
}
|
||||
file, err := os.Open(track.Path)
|
||||
absPath := path.Join(c.MusicPath, track.Path)
|
||||
file, err := os.Open(absPath)
|
||||
if err != nil {
|
||||
respondError(w, r, 0, fmt.Sprintf("error while streaming media: %v", err))
|
||||
return
|
||||
}
|
||||
stat, _ := file.Stat()
|
||||
http.ServeContent(w, r, track.Path, stat.ModTime(), file)
|
||||
http.ServeContent(w, r, absPath, stat.ModTime(), file)
|
||||
//
|
||||
// after we've served the file, mark the album as played
|
||||
user := r.Context().Value(contextUserKey).(*model.User)
|
||||
@@ -111,7 +113,7 @@ func (c *Controller) Scrobble(w http.ResponseWriter, r *http.Request) {
|
||||
&track,
|
||||
// clients will provide time in miliseconds, so use that or
|
||||
// instead convert UnixNano to miliseconds
|
||||
getIntParamOr(r, "time", int(time.Now().UnixNano() / 1e6)),
|
||||
getIntParamOr(r, "time", int(time.Now().UnixNano()/1e6)),
|
||||
getStrParamOr(r, "submission", "true") != "false",
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@@ -30,7 +30,7 @@ func (c *Controller) WithUserSession(next http.HandlerFunc) http.HandlerFunc {
|
||||
}
|
||||
// take username from sesion and add the user row to the context
|
||||
user := c.GetUserFromName(username)
|
||||
if user.ID == 0 {
|
||||
if *user.ID == 0 {
|
||||
// the username in the client's session no longer relates to a
|
||||
// user in the database (maybe the user was deleted)
|
||||
session.Options.MaxAge = -1
|
||||
|
||||
@@ -61,7 +61,7 @@ func (c *Controller) WithValidSubsonicArgs(next http.HandlerFunc) http.HandlerFu
|
||||
return
|
||||
}
|
||||
user := c.GetUserFromName(username)
|
||||
if user.ID == 0 {
|
||||
if *user.ID == 0 {
|
||||
// the user does not exist
|
||||
respondError(w, r, 40, "invalid username")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user