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})
c.Ctx.Output.Body(response)
}

View File

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

View File

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

View File

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

View File

@ -4,5 +4,5 @@ import "encoding/xml"
type License struct {
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 {
XMLName xml.Name `xml:"musicFolder"`
Id string `xml:"id,attr"`
Name string `xml:"name,attr"`
Id string `xml:"id,attr"`
Name string `xml:"name,attr"`
}
type MusicFolders struct {
XMLName xml.Name `xml:"musicFolders"`
XMLName xml.Name `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"`
Status string `xml:"status,attr"`
Version string `xml:"version,attr"`
Body []byte `xml:",innerxml"`
Body []byte `xml:",innerxml"`
}
func NewEmpty() Subsonic {
@ -22,4 +22,4 @@ func NewXML(body interface{}) []byte {
response.Body = xmlBody
xmlResponse, _ := xml.Marshal(response)
return []byte(xml.Header + string(xmlResponse))
}
}

View File

@ -19,9 +19,9 @@ func Validate(controller 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) == "" {
cancel(c, responses.ERROR_MISSING_PARAMETER)
}
@ -31,11 +31,11 @@ func checkParameters(c ControllerInterface) {
func authenticate(c ControllerInterface) {
user := c.GetString("u")
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)
}
}
func cancel(c ControllerInterface, code int) {
c.CustomAbort(200, string(responses.NewError(code)))
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,23 +3,23 @@ package test
import (
"fmt"
"github.com/astaxie/beego"
"net/http/httptest"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"runtime"
"os"
)
const (
testUser = "deluan"
testUser = "deluan"
testPassword = "wordpass"
testClient = "test"
testVersion = "1.0.0"
testClient = "test"
testVersion = "1.0.0"
)
func init() {
_, 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)
noLog := os.Getenv("NOLOG")
@ -41,4 +41,3 @@ func Get(url string, testCase string) (*http.Request, *httptest.ResponseRecorder
return r, w
}