This commit is contained in:
Deluan 2016-02-25 18:52:07 -05:00
parent a1829d432a
commit e760952263
17 changed files with 40 additions and 59 deletions

View File

@ -11,6 +11,3 @@ func (c *GetLicenseController) Get() {
response := responses.NewXML(&responses.License{Valid: true}) response := responses.NewXML(&responses.License{Valid: true})
c.Ctx.Output.Body(response) c.Ctx.Output.Body(response)
} }

View File

@ -20,6 +20,3 @@ func (c *GetMusicFoldersController) Get() {
response := responses.NewXML(musicFolders) response := responses.NewXML(musicFolders)
c.Ctx.Output.Body(response) c.Ctx.Output.Body(response)
} }

View File

@ -1,8 +1,8 @@
package api package api
import ( import (
"github.com/astaxie/beego"
"encoding/xml" "encoding/xml"
"github.com/astaxie/beego"
"github.com/deluan/gosonic/api/responses" "github.com/deluan/gosonic/api/responses"
) )
@ -13,6 +13,3 @@ func (c *PingController) Get() {
xmlBody, _ := xml.Marshal(response) xmlBody, _ := xml.Marshal(response)
c.Ctx.Output.Body([]byte(xml.Header + string(xmlBody))) c.Ctx.Output.Body([]byte(xml.Header + string(xmlBody)))
} }

View File

@ -32,9 +32,9 @@ func init() {
} }
type error struct { type error struct {
XMLName xml.Name`xml:"error"` XMLName xml.Name `xml:"error"`
Code int `xml:"code,attr"` Code int `xml:"code,attr"`
Message string `xml:"message,attr"` Message string `xml:"message,attr"`
} }
func NewError(errorCode int) []byte { func NewError(errorCode int) []byte {
@ -47,4 +47,4 @@ func NewError(errorCode int) []byte {
response.Body = xmlBody response.Body = xmlBody
xmlResponse, _ := xml.Marshal(response) xmlResponse, _ := xml.Marshal(response)
return []byte(xml.Header + string(xmlResponse)) return []byte(xml.Header + string(xmlResponse))
} }

View File

@ -4,5 +4,5 @@ import "encoding/xml"
type License struct { type License struct {
XMLName xml.Name `xml:"license"` XMLName xml.Name `xml:"license"`
Valid bool `xml:"valid,attr"` Valid bool `xml:"valid,attr"`
} }

View File

@ -4,11 +4,11 @@ import "encoding/xml"
type MusicFolder struct { type MusicFolder struct {
XMLName xml.Name `xml:"musicFolder"` XMLName xml.Name `xml:"musicFolder"`
Id string `xml:"id,attr"` Id string `xml:"id,attr"`
Name string `xml:"name,attr"` Name string `xml:"name,attr"`
} }
type MusicFolders struct { type MusicFolders struct {
XMLName xml.Name `xml:"musicFolders"` XMLName xml.Name `xml:"musicFolders"`
Folders []MusicFolder `xml:"musicFolders"` Folders []MusicFolder `xml:"musicFolders"`
} }

View File

@ -9,7 +9,7 @@ type Subsonic struct {
XMLName xml.Name `xml:"http://subsonic.org/restapi subsonic-response"` XMLName xml.Name `xml:"http://subsonic.org/restapi subsonic-response"`
Status string `xml:"status,attr"` Status string `xml:"status,attr"`
Version string `xml:"version,attr"` Version string `xml:"version,attr"`
Body []byte `xml:",innerxml"` Body []byte `xml:",innerxml"`
} }
func NewEmpty() Subsonic { func NewEmpty() Subsonic {
@ -22,4 +22,4 @@ func NewXML(body interface{}) []byte {
response.Body = xmlBody response.Body = xmlBody
xmlResponse, _ := xml.Marshal(response) xmlResponse, _ := xml.Marshal(response)
return []byte(xml.Header + string(xmlResponse)) return []byte(xml.Header + string(xmlResponse))
} }

View File

@ -19,9 +19,9 @@ func Validate(controller ControllerInterface) {
} }
func checkParameters(c ControllerInterface) { func checkParameters(c ControllerInterface) {
requiredParameters := []string {"u", "p", "v", "c",} requiredParameters := []string{"u", "p", "v", "c"}
for _,p := range requiredParameters { for _, p := range requiredParameters {
if c.GetString(p) == "" { if c.GetString(p) == "" {
cancel(c, responses.ERROR_MISSING_PARAMETER) cancel(c, responses.ERROR_MISSING_PARAMETER)
} }
@ -31,11 +31,11 @@ func checkParameters(c ControllerInterface) {
func authenticate(c ControllerInterface) { func authenticate(c ControllerInterface) {
user := c.GetString("u") user := c.GetString("u")
pass := c.GetString("p") // TODO Handle hex-encoded password pass := c.GetString("p") // TODO Handle hex-encoded password
if (user != beego.AppConfig.String("user") || pass != beego.AppConfig.String("password")) { if user != beego.AppConfig.String("user") || pass != beego.AppConfig.String("password") {
cancel(c, responses.ERROR_AUTHENTICATION_FAIL) cancel(c, responses.ERROR_AUTHENTICATION_FAIL)
} }
} }
func cancel(c ControllerInterface, code int) { func cancel(c ControllerInterface, code int) {
c.CustomAbort(200, string(responses.NewError(code))) c.CustomAbort(200, string(responses.NewError(code)))
} }

View File

@ -1,18 +1,16 @@
package controllers package controllers
import ( import (
"github.com/astaxie/beego"
"fmt" "fmt"
"github.com/astaxie/beego"
) )
type MainController struct{ beego.Controller } type MainController struct{ beego.Controller }
func (c *MainController) Get() { func (c *MainController) Get() {
c.Ctx.Redirect(302, "/static/Jamstash/") c.Ctx.Redirect(302, "/static/Jamstash/")
} }
func (c *MainController) Error404() { func (c *MainController) Error404() {
if beego.BConfig.RunMode == beego.DEV || beego.BConfig.Log.AccessLogs { if beego.BConfig.RunMode == beego.DEV || beego.BConfig.Log.AccessLogs {
r := c.Ctx.Request r := c.Ctx.Request

View File

@ -1,8 +1,8 @@
package controllers package controllers
import ( import (
"github.com/deluan/gosonic/models"
"encoding/json" "encoding/json"
"github.com/deluan/gosonic/models"
"github.com/astaxie/beego" "github.com/astaxie/beego"
) )
@ -89,4 +89,3 @@ func (o *ObjectController) Delete() {
o.Data["json"] = "delete success!" o.Data["json"] = "delete success!"
o.ServeJSON() o.ServeJSON()
} }

View File

@ -1,8 +1,8 @@
package controllers package controllers
import ( import (
"github.com/deluan/gosonic/models"
"encoding/json" "encoding/json"
"github.com/deluan/gosonic/models"
"github.com/astaxie/beego" "github.com/astaxie/beego"
) )
@ -116,4 +116,3 @@ func (u *UserController) Logout() {
u.Data["json"] = "logout success" u.Data["json"] = "logout success"
u.ServeJSON() u.ServeJSON()
} }

View File

@ -1,16 +1,16 @@
package itunes package itunes
import ( import (
"github.com/dhowden/itl"
"os"
"github.com/deluan/gosonic/models" "github.com/deluan/gosonic/models"
"github.com/dhowden/itl"
"net/url" "net/url"
"strings" "os"
"strings"
) )
func LoadFolder(path string) []models.MediaFile { func LoadFolder(path string) []models.MediaFile {
xml, _ := os.Open(path) xml, _ := os.Open(path)
l,_ := itl.ReadFromXML(xml) l, _ := itl.ReadFromXML(xml)
mediaFiles := make([]models.MediaFile, len(l.Tracks)) mediaFiles := make([]models.MediaFile, len(l.Tracks))
i := 0 i := 0
@ -19,7 +19,7 @@ func LoadFolder(path string) []models.MediaFile {
mediaFiles[i].Album = track.Album mediaFiles[i].Album = track.Album
mediaFiles[i].Title = track.Name mediaFiles[i].Title = track.Name
mediaFiles[i].Artist = track.Artist mediaFiles[i].Artist = track.Artist
path,_ = url.QueryUnescape(track.Location) path, _ = url.QueryUnescape(track.Location)
mediaFiles[i].Path = strings.TrimPrefix(path, "file://") mediaFiles[i].Path = strings.TrimPrefix(path, "file://")
mediaFiles[i].CreatedAt = track.DateAdded mediaFiles[i].CreatedAt = track.DateAdded
mediaFiles[i].UpdatedAt = track.DateModified mediaFiles[i].UpdatedAt = track.DateModified

View File

@ -1,11 +1,11 @@
package api_test package api_test
import ( import (
"testing" "encoding/xml"
_ "github.com/deluan/gosonic/routers" _ "github.com/deluan/gosonic/routers"
. "github.com/deluan/gosonic/tests" . "github.com/deluan/gosonic/tests"
"encoding/xml"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
"testing"
) )
func TestGetLicense(t *testing.T) { func TestGetLicense(t *testing.T) {
@ -24,4 +24,3 @@ func TestGetLicense(t *testing.T) {
}) })
} }

View File

@ -1,12 +1,12 @@
package api_test package api_test
import ( import (
"testing"
_ "github.com/deluan/gosonic/routers" _ "github.com/deluan/gosonic/routers"
. "github.com/deluan/gosonic/tests" . "github.com/deluan/gosonic/tests"
"testing"
. "github.com/smartystreets/goconvey/convey"
"encoding/xml" "encoding/xml"
. "github.com/smartystreets/goconvey/convey"
) )
func TestGetMusicFolders(t *testing.T) { func TestGetMusicFolders(t *testing.T) {
@ -24,4 +24,3 @@ func TestGetMusicFolders(t *testing.T) {
}) })
}) })
} }

View File

@ -1,12 +1,12 @@
package api_test package api_test
import ( import (
"testing"
"encoding/xml" "encoding/xml"
_ "github.com/deluan/gosonic/routers"
. "github.com/smartystreets/goconvey/convey"
"github.com/deluan/gosonic/api/responses" "github.com/deluan/gosonic/api/responses"
_ "github.com/deluan/gosonic/routers"
. "github.com/deluan/gosonic/tests" . "github.com/deluan/gosonic/tests"
. "github.com/smartystreets/goconvey/convey"
"testing"
) )
func TestPing(t *testing.T) { func TestPing(t *testing.T) {
@ -28,4 +28,3 @@ func TestPing(t *testing.T) {
}) })
} }

View File

@ -1,12 +1,12 @@
package api_test package api_test
import ( import (
"testing"
"encoding/xml" "encoding/xml"
"github.com/deluan/gosonic/api/responses"
_ "github.com/deluan/gosonic/routers" _ "github.com/deluan/gosonic/routers"
. "github.com/deluan/gosonic/tests" . "github.com/deluan/gosonic/tests"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
"github.com/deluan/gosonic/api/responses" "testing"
) )
func TestCheckParams(t *testing.T) { func TestCheckParams(t *testing.T) {
@ -44,5 +44,3 @@ func TestAuthentication(t *testing.T) {
}) })
}) })
} }

View File

@ -3,23 +3,23 @@ package test
import ( import (
"fmt" "fmt"
"github.com/astaxie/beego" "github.com/astaxie/beego"
"net/http/httptest"
"net/http" "net/http"
"net/http/httptest"
"os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"os"
) )
const ( const (
testUser = "deluan" testUser = "deluan"
testPassword = "wordpass" testPassword = "wordpass"
testClient = "test" testClient = "test"
testVersion = "1.0.0" testVersion = "1.0.0"
) )
func init() { func init() {
_, file, _, _ := runtime.Caller(1) _, file, _, _ := runtime.Caller(1)
appPath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".." + string(filepath.Separator)))) appPath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator))))
beego.TestBeegoInit(appPath) beego.TestBeegoInit(appPath)
noLog := os.Getenv("NOLOG") noLog := os.Getenv("NOLOG")
@ -41,4 +41,3 @@ func Get(url string, testCase string) (*http.Request, *httptest.ResponseRecorder
return r, w return r, w
} }