move models into db package
This commit is contained in:
@@ -4,6 +4,7 @@ linters:
|
|||||||
- gochecknoglobals
|
- gochecknoglobals
|
||||||
- gochecknoinits
|
- gochecknoinits
|
||||||
- gomnd
|
- gomnd
|
||||||
|
- godox
|
||||||
- funlen
|
- funlen
|
||||||
- wsl
|
- wsl
|
||||||
issues:
|
issues:
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ type EmbeddedAsset struct {
|
|||||||
}
|
}
|
||||||
var Bytes = map[string]*EmbeddedAsset{
|
var Bytes = map[string]*EmbeddedAsset{
|
||||||
"pages/change_password.tmpl": &EmbeddedAsset{
|
"pages/change_password.tmpl": &EmbeddedAsset{
|
||||||
ModTime: time.Unix(1580143156, 0),
|
ModTime: time.Unix(1582000031, 0),
|
||||||
Bytes: []byte{
|
Bytes: []byte{
|
||||||
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x75,0x73,0x65,0x72,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x64,0x69,0x76,
|
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x75,0x73,0x65,0x72,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x64,0x69,0x76,
|
||||||
0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,0x20,0x20,0x20,
|
0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,0x20,0x20,0x20,
|
||||||
@@ -39,7 +39,7 @@ var Bytes = map[string]*EmbeddedAsset{
|
|||||||
0x64,0x20,0x7d,0x7d,0x0a,
|
0x64,0x20,0x7d,0x7d,0x0a,
|
||||||
}},
|
}},
|
||||||
"pages/login.tmpl": &EmbeddedAsset{
|
"pages/login.tmpl": &EmbeddedAsset{
|
||||||
ModTime: time.Unix(1580142568, 0),
|
ModTime: time.Unix(1582000031, 0),
|
||||||
Bytes: []byte{
|
Bytes: []byte{
|
||||||
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x63,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x22,0x20,0x7d,0x7d,0x0a,0x3c,
|
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x63,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x22,0x20,0x7d,0x7d,0x0a,0x3c,
|
||||||
0x64,0x69,0x76,0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,
|
0x64,0x69,0x76,0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,
|
||||||
@@ -62,7 +62,7 @@ var Bytes = map[string]*EmbeddedAsset{
|
|||||||
0x7b,0x20,0x65,0x6e,0x64,0x20,0x7d,0x7d,0x0a,
|
0x7b,0x20,0x65,0x6e,0x64,0x20,0x7d,0x7d,0x0a,
|
||||||
}},
|
}},
|
||||||
"pages/home.tmpl": &EmbeddedAsset{
|
"pages/home.tmpl": &EmbeddedAsset{
|
||||||
ModTime: time.Unix(1580143754, 0),
|
ModTime: time.Unix(1582113240, 0),
|
||||||
Bytes: []byte{
|
Bytes: []byte{
|
||||||
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x75,0x73,0x65,0x72,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x64,0x69,0x76,
|
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x75,0x73,0x65,0x72,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x64,0x69,0x76,
|
||||||
0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,0x20,0x20,0x20,
|
0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,0x20,0x20,0x20,
|
||||||
@@ -282,7 +282,7 @@ var Bytes = map[string]*EmbeddedAsset{
|
|||||||
0x2f,0x64,0x69,0x76,0x3e,0x0a,0x7b,0x7b,0x20,0x65,0x6e,0x64,0x20,0x7d,0x7d,0x0a,
|
0x2f,0x64,0x69,0x76,0x3e,0x0a,0x7b,0x7b,0x20,0x65,0x6e,0x64,0x20,0x7d,0x7d,0x0a,
|
||||||
}},
|
}},
|
||||||
"pages/delete_user.tmpl": &EmbeddedAsset{
|
"pages/delete_user.tmpl": &EmbeddedAsset{
|
||||||
ModTime: time.Unix(1580143173, 0),
|
ModTime: time.Unix(1582000031, 0),
|
||||||
Bytes: []byte{
|
Bytes: []byte{
|
||||||
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x75,0x73,0x65,0x72,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x64,0x69,0x76,
|
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x75,0x73,0x65,0x72,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x64,0x69,0x76,
|
||||||
0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,0x20,0x20,0x20,
|
0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,0x20,0x20,0x20,
|
||||||
@@ -307,7 +307,7 @@ var Bytes = map[string]*EmbeddedAsset{
|
|||||||
0x2f,0x64,0x69,0x76,0x3e,0x0a,0x7b,0x7b,0x20,0x65,0x6e,0x64,0x20,0x7d,0x7d,0x0a,
|
0x2f,0x64,0x69,0x76,0x3e,0x0a,0x7b,0x7b,0x20,0x65,0x6e,0x64,0x20,0x7d,0x7d,0x0a,
|
||||||
}},
|
}},
|
||||||
"pages/update_lastfm_api_key.tmpl": &EmbeddedAsset{
|
"pages/update_lastfm_api_key.tmpl": &EmbeddedAsset{
|
||||||
ModTime: time.Unix(1580143015, 0),
|
ModTime: time.Unix(1582000031, 0),
|
||||||
Bytes: []byte{
|
Bytes: []byte{
|
||||||
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x75,0x73,0x65,0x72,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x64,0x69,0x76,
|
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x75,0x73,0x65,0x72,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x64,0x69,0x76,
|
||||||
0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,0x20,0x20,0x20,
|
0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,0x20,0x20,0x20,
|
||||||
@@ -341,7 +341,7 @@ var Bytes = map[string]*EmbeddedAsset{
|
|||||||
0x3e,0x0a,0x7b,0x7b,0x20,0x65,0x6e,0x64,0x20,0x7d,0x7d,0x0a,
|
0x3e,0x0a,0x7b,0x7b,0x20,0x65,0x6e,0x64,0x20,0x7d,0x7d,0x0a,
|
||||||
}},
|
}},
|
||||||
"pages/change_own_password.tmpl": &EmbeddedAsset{
|
"pages/change_own_password.tmpl": &EmbeddedAsset{
|
||||||
ModTime: time.Unix(1580143781, 0),
|
ModTime: time.Unix(1582000031, 0),
|
||||||
Bytes: []byte{
|
Bytes: []byte{
|
||||||
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x75,0x73,0x65,0x72,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x64,0x69,0x76,
|
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x75,0x73,0x65,0x72,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x64,0x69,0x76,
|
||||||
0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,0x20,0x20,0x20,
|
0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,0x20,0x20,0x20,
|
||||||
@@ -367,7 +367,7 @@ var Bytes = map[string]*EmbeddedAsset{
|
|||||||
0x7d,0x0a,
|
0x7d,0x0a,
|
||||||
}},
|
}},
|
||||||
"pages/create_user.tmpl": &EmbeddedAsset{
|
"pages/create_user.tmpl": &EmbeddedAsset{
|
||||||
ModTime: time.Unix(1580142992, 0),
|
ModTime: time.Unix(1582000031, 0),
|
||||||
Bytes: []byte{
|
Bytes: []byte{
|
||||||
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x75,0x73,0x65,0x72,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x64,0x69,0x76,
|
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x75,0x73,0x65,0x72,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x64,0x69,0x76,
|
||||||
0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,0x20,0x20,0x20,
|
0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,0x20,0x20,0x20,
|
||||||
@@ -10715,7 +10715,7 @@ var Bytes = map[string]*EmbeddedAsset{
|
|||||||
0x55,0x23,0xfe,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82,
|
0x55,0x23,0xfe,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82,
|
||||||
}},
|
}},
|
||||||
"static/main.css": &EmbeddedAsset{
|
"static/main.css": &EmbeddedAsset{
|
||||||
ModTime: time.Unix(1579270806, 0),
|
ModTime: time.Unix(1582113240, 0),
|
||||||
Bytes: []byte{
|
Bytes: []byte{
|
||||||
0x3a,0x72,0x6f,0x6f,0x74,0x20,0x7b,0x0a,0x20,0x20,0x2d,0x2d,0x70,0x61,0x64,0x2d,0x73,0x69,0x7a,0x65,0x3a,0x20,0x31,0x2e,
|
0x3a,0x72,0x6f,0x6f,0x74,0x20,0x7b,0x0a,0x20,0x20,0x2d,0x2d,0x70,0x61,0x64,0x2d,0x73,0x69,0x7a,0x65,0x3a,0x20,0x31,0x2e,
|
||||||
0x37,0x35,0x72,0x65,0x6d,0x3b,0x0a,0x7d,0x0a,0x0a,0x2a,0x2c,0x20,0x73,0x70,0x61,0x6e,0x2c,0x20,0x64,0x69,0x76,0x2c,0x20,
|
0x37,0x35,0x72,0x65,0x6d,0x3b,0x0a,0x7d,0x0a,0x0a,0x2a,0x2c,0x20,0x73,0x70,0x61,0x6e,0x2c,0x20,0x64,0x69,0x76,0x2c,0x20,
|
||||||
@@ -10813,7 +10813,7 @@ var Bytes = map[string]*EmbeddedAsset{
|
|||||||
0x32,0x3b,0x0a,0x7d,0x0a,
|
0x32,0x3b,0x0a,0x7d,0x0a,
|
||||||
}},
|
}},
|
||||||
"partials/head.tmpl": &EmbeddedAsset{
|
"partials/head.tmpl": &EmbeddedAsset{
|
||||||
ModTime: time.Unix(1579908949, 0),
|
ModTime: time.Unix(1582000031, 0),
|
||||||
Bytes: []byte{
|
Bytes: []byte{
|
||||||
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x68,0x65,0x61,0x64,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x6c,0x69,0x6e,
|
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x68,0x65,0x61,0x64,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x6c,0x69,0x6e,
|
||||||
0x6b,0x20,0x72,0x65,0x6c,0x3d,0x22,0x73,0x74,0x79,0x6c,0x65,0x73,0x68,0x65,0x65,0x74,0x22,0x20,0x68,0x72,0x65,0x66,0x3d,
|
0x6b,0x20,0x72,0x65,0x6c,0x3d,0x22,0x73,0x74,0x79,0x6c,0x65,0x73,0x68,0x65,0x65,0x74,0x22,0x20,0x68,0x72,0x65,0x66,0x3d,
|
||||||
@@ -10840,7 +10840,7 @@ var Bytes = map[string]*EmbeddedAsset{
|
|||||||
0x65,0x6e,0x64,0x20,0x7d,0x7d,0x0a,
|
0x65,0x6e,0x64,0x20,0x7d,0x7d,0x0a,
|
||||||
}},
|
}},
|
||||||
"layouts/base.tmpl": &EmbeddedAsset{
|
"layouts/base.tmpl": &EmbeddedAsset{
|
||||||
ModTime: time.Unix(1579908703, 0),
|
ModTime: time.Unix(1582000031, 0),
|
||||||
Bytes: []byte{
|
Bytes: []byte{
|
||||||
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x6c,0x61,0x79,0x6f,0x75,0x74,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x21,
|
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x6c,0x61,0x79,0x6f,0x75,0x74,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x21,
|
||||||
0x64,0x6f,0x63,0x74,0x79,0x70,0x65,0x20,0x68,0x74,0x6d,0x6c,0x3e,0x0a,0x3c,0x68,0x74,0x6d,0x6c,0x3e,0x0a,0x20,0x20,0x20,
|
0x64,0x6f,0x63,0x74,0x79,0x70,0x65,0x20,0x68,0x74,0x6d,0x6c,0x3e,0x0a,0x3c,0x68,0x74,0x6d,0x6c,0x3e,0x0a,0x20,0x20,0x20,
|
||||||
@@ -10881,7 +10881,7 @@ var Bytes = map[string]*EmbeddedAsset{
|
|||||||
0x3c,0x2f,0x68,0x74,0x6d,0x6c,0x3e,0x0a,0x7b,0x7b,0x20,0x65,0x6e,0x64,0x20,0x7d,0x7d,0x0a,
|
0x3c,0x2f,0x68,0x74,0x6d,0x6c,0x3e,0x0a,0x7b,0x7b,0x20,0x65,0x6e,0x64,0x20,0x7d,0x7d,0x0a,
|
||||||
}},
|
}},
|
||||||
"layouts/user.tmpl": &EmbeddedAsset{
|
"layouts/user.tmpl": &EmbeddedAsset{
|
||||||
ModTime: time.Unix(1579908924, 0),
|
ModTime: time.Unix(1582000031, 0),
|
||||||
Bytes: []byte{
|
Bytes: []byte{
|
||||||
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x63,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x22,0x20,0x7d,0x7d,0x0a,0x3c,
|
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x63,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x22,0x20,0x7d,0x7d,0x0a,0x3c,
|
||||||
0x64,0x69,0x76,0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x73,0x69,0x64,0x65,0x2d,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x6c,
|
0x64,0x69,0x76,0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x73,0x69,0x64,0x65,0x2d,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x6c,
|
||||||
|
|||||||
26
db/db.go
26
db/db.go
@@ -8,8 +8,6 @@ import (
|
|||||||
|
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"senan.xyz/g/gonic/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -37,18 +35,8 @@ func New(path string) (*DB, error) {
|
|||||||
db.SetLogger(log.New(os.Stdout, "gorm ", 0))
|
db.SetLogger(log.New(os.Stdout, "gorm ", 0))
|
||||||
db.DB().SetMaxOpenConns(dbMaxOpenConns)
|
db.DB().SetMaxOpenConns(dbMaxOpenConns)
|
||||||
db.Exec("PRAGMA journal_mode=WAL;")
|
db.Exec("PRAGMA journal_mode=WAL;")
|
||||||
db.AutoMigrate(
|
|
||||||
model.Artist{},
|
|
||||||
model.Track{},
|
|
||||||
model.User{},
|
|
||||||
model.Setting{},
|
|
||||||
model.Play{},
|
|
||||||
model.Album{},
|
|
||||||
model.Playlist{},
|
|
||||||
model.PlayQueue{},
|
|
||||||
)
|
|
||||||
// TODO: don't log if user already exists
|
// TODO: don't log if user already exists
|
||||||
db.FirstOrCreate(&model.User{}, model.User{
|
db.FirstOrCreate(&User{}, User{
|
||||||
Name: "admin",
|
Name: "admin",
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
IsAdmin: true,
|
IsAdmin: true,
|
||||||
@@ -61,7 +49,7 @@ func NewMock() (*DB, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) GetSetting(key string) string {
|
func (db *DB) GetSetting(key string) string {
|
||||||
setting := &model.Setting{}
|
setting := &Setting{}
|
||||||
db.
|
db.
|
||||||
Where("key = ?", key).
|
Where("key = ?", key).
|
||||||
First(setting)
|
First(setting)
|
||||||
@@ -70,13 +58,13 @@ func (db *DB) GetSetting(key string) string {
|
|||||||
|
|
||||||
func (db *DB) SetSetting(key, value string) {
|
func (db *DB) SetSetting(key, value string) {
|
||||||
db.
|
db.
|
||||||
Where(model.Setting{Key: key}).
|
Where(Setting{Key: key}).
|
||||||
Assign(model.Setting{Value: value}).
|
Assign(Setting{Value: value}).
|
||||||
FirstOrCreate(&model.Setting{})
|
FirstOrCreate(&Setting{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) GetUserFromName(name string) *model.User {
|
func (db *DB) GetUserFromName(name string) *User {
|
||||||
user := &model.User{}
|
user := &User{}
|
||||||
err := db.
|
err := db.
|
||||||
Where("name = ?", name).
|
Where("name = ?", name).
|
||||||
First(user).
|
First(user).
|
||||||
|
|||||||
1
db/migrations.go
Normal file
1
db/migrations.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package db
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
//nolint:lll
|
//nolint:lll
|
||||||
package model
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
"path"
|
||||||
@@ -17,7 +17,6 @@ import (
|
|||||||
|
|
||||||
"senan.xyz/g/gonic/db"
|
"senan.xyz/g/gonic/db"
|
||||||
"senan.xyz/g/gonic/mime"
|
"senan.xyz/g/gonic/mime"
|
||||||
"senan.xyz/g/gonic/model"
|
|
||||||
"senan.xyz/g/gonic/scanner/stack"
|
"senan.xyz/g/gonic/scanner/stack"
|
||||||
"senan.xyz/g/gonic/scanner/tags"
|
"senan.xyz/g/gonic/scanner/tags"
|
||||||
)
|
)
|
||||||
@@ -106,7 +105,7 @@ func (s *Scanner) Start() error {
|
|||||||
var deleted uint
|
var deleted uint
|
||||||
// delete tracks not on filesystem
|
// delete tracks not on filesystem
|
||||||
s.db.WithTx(func(tx *gorm.DB) {
|
s.db.WithTx(func(tx *gorm.DB) {
|
||||||
var tracks []*model.Track
|
var tracks []*db.Track
|
||||||
tx.
|
tx.
|
||||||
Select("id").
|
Select("id").
|
||||||
Find(&tracks)
|
Find(&tracks)
|
||||||
@@ -120,7 +119,7 @@ func (s *Scanner) Start() error {
|
|||||||
})
|
})
|
||||||
// delete folders not on filesystem
|
// delete folders not on filesystem
|
||||||
s.db.WithTx(func(tx *gorm.DB) {
|
s.db.WithTx(func(tx *gorm.DB) {
|
||||||
var folders []*model.Album
|
var folders []*db.Album
|
||||||
tx.
|
tx.
|
||||||
Select("id").
|
Select("id").
|
||||||
Find(&folders)
|
Find(&folders)
|
||||||
@@ -268,7 +267,7 @@ func (s *Scanner) handleFolder(it *item) error {
|
|||||||
s.trTx.Commit()
|
s.trTx.Commit()
|
||||||
s.trTxOpen = false
|
s.trTxOpen = false
|
||||||
}
|
}
|
||||||
folder := &model.Album{}
|
folder := &db.Album{}
|
||||||
defer func() {
|
defer func() {
|
||||||
// folder's id will come from early return
|
// folder's id will come from early return
|
||||||
// or save at the end
|
// or save at the end
|
||||||
@@ -277,7 +276,7 @@ func (s *Scanner) handleFolder(it *item) error {
|
|||||||
}()
|
}()
|
||||||
err := s.db.
|
err := s.db.
|
||||||
Select("id, updated_at").
|
Select("id, updated_at").
|
||||||
Where(model.Album{
|
Where(db.Album{
|
||||||
LeftPath: it.directory,
|
LeftPath: it.directory,
|
||||||
RightPath: it.filename,
|
RightPath: it.filename,
|
||||||
}).
|
}).
|
||||||
@@ -304,10 +303,10 @@ func (s *Scanner) handleTrack(it *item) error {
|
|||||||
}
|
}
|
||||||
//
|
//
|
||||||
// set track basics
|
// set track basics
|
||||||
track := &model.Track{}
|
track := &db.Track{}
|
||||||
err := s.trTx.
|
err := s.trTx.
|
||||||
Select("id, updated_at").
|
Select("id, updated_at").
|
||||||
Where(model.Track{
|
Where(db.Track{
|
||||||
AlbumID: s.curFolders.PeekID(),
|
AlbumID: s.curFolders.PeekID(),
|
||||||
Filename: it.filename,
|
Filename: it.filename,
|
||||||
}).
|
}).
|
||||||
@@ -350,7 +349,7 @@ func (s *Scanner) handleTrack(it *item) error {
|
|||||||
}
|
}
|
||||||
return "Unknown Artist"
|
return "Unknown Artist"
|
||||||
}()
|
}()
|
||||||
artist := &model.Artist{}
|
artist := &db.Artist{}
|
||||||
err = s.trTx.
|
err = s.trTx.
|
||||||
Select("id").
|
Select("id").
|
||||||
Where("name = ?", artistName).
|
Where("name = ?", artistName).
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"senan.xyz/g/gonic/model"
|
"senan.xyz/g/gonic/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
type item struct {
|
type item struct {
|
||||||
value *model.Album
|
value *db.Album
|
||||||
next *item
|
next *item
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ type Stack struct {
|
|||||||
len uint
|
len uint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Stack) Push(v *model.Album) {
|
func (s *Stack) Push(v *db.Album) {
|
||||||
s.top = &item{
|
s.top = &item{
|
||||||
value: v,
|
value: v,
|
||||||
next: s.top,
|
next: s.top,
|
||||||
@@ -25,7 +25,7 @@ func (s *Stack) Push(v *model.Album) {
|
|||||||
s.len++
|
s.len++
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Stack) Pop() *model.Album {
|
func (s *Stack) Pop() *db.Album {
|
||||||
if s.len == 0 {
|
if s.len == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ func (s *Stack) Pop() *model.Album {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Stack) Peek() *model.Album {
|
func (s *Stack) Peek() *db.Album {
|
||||||
if s.len == 0 {
|
if s.len == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,15 +3,15 @@ package stack
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"senan.xyz/g/gonic/model"
|
"senan.xyz/g/gonic/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFolderStack(t *testing.T) {
|
func TestFolderStack(t *testing.T) {
|
||||||
sta := &Stack{}
|
sta := &Stack{}
|
||||||
sta.Push(&model.Album{ID: 3})
|
sta.Push(&db.Album{ID: 3})
|
||||||
sta.Push(&model.Album{ID: 4})
|
sta.Push(&db.Album{ID: 4})
|
||||||
sta.Push(&model.Album{ID: 5})
|
sta.Push(&db.Album{ID: 5})
|
||||||
sta.Push(&model.Album{ID: 6})
|
sta.Push(&db.Album{ID: 6})
|
||||||
expected := "[6, 5, 4, 3, ]"
|
expected := "[6, 5, 4, 3, ]"
|
||||||
actual := sta.String()
|
actual := sta.String()
|
||||||
if expected != actual {
|
if expected != actual {
|
||||||
@@ -20,12 +20,12 @@ func TestFolderStack(t *testing.T) {
|
|||||||
}
|
}
|
||||||
//
|
//
|
||||||
sta = &Stack{}
|
sta = &Stack{}
|
||||||
sta.Push(&model.Album{ID: 27})
|
sta.Push(&db.Album{ID: 27})
|
||||||
sta.Push(&model.Album{ID: 4})
|
sta.Push(&db.Album{ID: 4})
|
||||||
sta.Peek()
|
sta.Peek()
|
||||||
sta.Push(&model.Album{ID: 5})
|
sta.Push(&db.Album{ID: 5})
|
||||||
sta.Push(&model.Album{ID: 6})
|
sta.Push(&db.Album{ID: 6})
|
||||||
sta.Push(&model.Album{ID: 7})
|
sta.Push(&db.Album{ID: 7})
|
||||||
sta.Pop()
|
sta.Pop()
|
||||||
expected = "[6, 5, 4, 27, ]"
|
expected = "[6, 5, 4, 27, ]"
|
||||||
actual = sta.String()
|
actual = sta.String()
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ package ctrladmin
|
|||||||
import (
|
import (
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Masterminds/sprig"
|
"github.com/Masterminds/sprig"
|
||||||
@@ -18,7 +18,7 @@ import (
|
|||||||
"github.com/wader/gormstore"
|
"github.com/wader/gormstore"
|
||||||
|
|
||||||
"senan.xyz/g/gonic/assets"
|
"senan.xyz/g/gonic/assets"
|
||||||
"senan.xyz/g/gonic/model"
|
"senan.xyz/g/gonic/db"
|
||||||
"senan.xyz/g/gonic/server/ctrlbase"
|
"senan.xyz/g/gonic/server/ctrlbase"
|
||||||
"senan.xyz/g/gonic/version"
|
"senan.xyz/g/gonic/version"
|
||||||
)
|
)
|
||||||
@@ -96,22 +96,22 @@ func New(base *ctrlbase.Controller) *Controller {
|
|||||||
type templateData struct {
|
type templateData struct {
|
||||||
// common
|
// common
|
||||||
Flashes []interface{}
|
Flashes []interface{}
|
||||||
User *model.User
|
User *db.User
|
||||||
Version string
|
Version string
|
||||||
// home
|
// home
|
||||||
AlbumCount int
|
AlbumCount int
|
||||||
ArtistCount int
|
ArtistCount int
|
||||||
TrackCount int
|
TrackCount int
|
||||||
RequestRoot string
|
RequestRoot string
|
||||||
RecentFolders []*model.Album
|
RecentFolders []*db.Album
|
||||||
AllUsers []*model.User
|
AllUsers []*db.User
|
||||||
LastScanTime time.Time
|
LastScanTime time.Time
|
||||||
IsScanning bool
|
IsScanning bool
|
||||||
Playlists []*model.Playlist
|
Playlists []*db.Playlist
|
||||||
//
|
//
|
||||||
CurrentLastFMAPIKey string
|
CurrentLastFMAPIKey string
|
||||||
CurrentLastFMAPISecret string
|
CurrentLastFMAPISecret string
|
||||||
SelectedUser *model.User
|
SelectedUser *db.User
|
||||||
}
|
}
|
||||||
|
|
||||||
type adminHandler func(r *http.Request) *Response
|
type adminHandler func(r *http.Request) *Response
|
||||||
@@ -168,7 +168,7 @@ func (c *Controller) H(h adminHandler) http.Handler {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if user, ok := r.Context().Value(CtxUser).(*model.User); ok {
|
if user, ok := r.Context().Value(CtxUser).(*db.User); ok {
|
||||||
resp.data.User = user
|
resp.data.User = user
|
||||||
}
|
}
|
||||||
buff := c.buffPool.Get()
|
buff := c.buffPool.Get()
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"senan.xyz/g/gonic/model"
|
"senan.xyz/g/gonic/db"
|
||||||
"senan.xyz/g/gonic/scanner"
|
"senan.xyz/g/gonic/scanner"
|
||||||
"senan.xyz/g/gonic/server/lastfm"
|
"senan.xyz/g/gonic/server/lastfm"
|
||||||
)
|
)
|
||||||
@@ -54,7 +54,7 @@ func (c *Controller) ServeHome(r *http.Request) *Response {
|
|||||||
data.LastScanTime = time.Unix(i, 0)
|
data.LastScanTime = time.Unix(i, 0)
|
||||||
}
|
}
|
||||||
// ** begin playlists box
|
// ** begin playlists box
|
||||||
user := r.Context().Value(CtxUser).(*model.User)
|
user := r.Context().Value(CtxUser).(*db.User)
|
||||||
c.DB.
|
c.DB.
|
||||||
Where("user_id = ?", user.ID).
|
Where("user_id = ?", user.ID).
|
||||||
Limit(20).
|
Limit(20).
|
||||||
@@ -80,7 +80,7 @@ func (c *Controller) ServeChangeOwnPasswordDo(r *http.Request) *Response {
|
|||||||
flashW: []string{err.Error()},
|
flashW: []string{err.Error()},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
user := r.Context().Value(CtxUser).(*model.User)
|
user := r.Context().Value(CtxUser).(*db.User)
|
||||||
user.Password = passwordOne
|
user.Password = passwordOne
|
||||||
c.DB.Save(user)
|
c.DB.Save(user)
|
||||||
return &Response{redirect: "/admin/home"}
|
return &Response{redirect: "/admin/home"}
|
||||||
@@ -105,14 +105,14 @@ func (c *Controller) ServeLinkLastFMDo(r *http.Request) *Response {
|
|||||||
flashW: []string{err.Error()},
|
flashW: []string{err.Error()},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
user := r.Context().Value(CtxUser).(*model.User)
|
user := r.Context().Value(CtxUser).(*db.User)
|
||||||
user.LastFMSession = sessionKey
|
user.LastFMSession = sessionKey
|
||||||
c.DB.Save(&user)
|
c.DB.Save(&user)
|
||||||
return &Response{redirect: "/admin/home"}
|
return &Response{redirect: "/admin/home"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) ServeUnlinkLastFMDo(r *http.Request) *Response {
|
func (c *Controller) ServeUnlinkLastFMDo(r *http.Request) *Response {
|
||||||
user := r.Context().Value(CtxUser).(*model.User)
|
user := r.Context().Value(CtxUser).(*db.User)
|
||||||
user.LastFMSession = ""
|
user.LastFMSession = ""
|
||||||
c.DB.Save(&user)
|
c.DB.Save(&user)
|
||||||
return &Response{redirect: "/admin/home"}
|
return &Response{redirect: "/admin/home"}
|
||||||
@@ -210,7 +210,7 @@ func (c *Controller) ServeCreateUserDo(r *http.Request) *Response {
|
|||||||
flashW: []string{err.Error()},
|
flashW: []string{err.Error()},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
user := model.User{
|
user := db.User{
|
||||||
Name: username,
|
Name: username,
|
||||||
Password: passwordOne,
|
Password: passwordOne,
|
||||||
}
|
}
|
||||||
@@ -273,7 +273,7 @@ func (c *Controller) ServeUploadPlaylistDo(r *http.Request) *Response {
|
|||||||
code: 500,
|
code: 500,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
user := r.Context().Value(CtxUser).(*model.User)
|
user := r.Context().Value(CtxUser).(*db.User)
|
||||||
var playlistCount int
|
var playlistCount int
|
||||||
var errors []string
|
var errors []string
|
||||||
for _, headers := range r.MultipartForm.File {
|
for _, headers := range r.MultipartForm.File {
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
|
"senan.xyz/g/gonic/db"
|
||||||
"senan.xyz/g/gonic/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Controller) WithSession(next http.Handler) http.Handler {
|
func (c *Controller) WithSession(next http.Handler) http.Handler {
|
||||||
@@ -47,7 +46,7 @@ func (c *Controller) WithAdminSession(next http.Handler) http.Handler {
|
|||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
// session and user exist at this point
|
// session and user exist at this point
|
||||||
session := r.Context().Value(CtxSession).(*sessions.Session)
|
session := r.Context().Value(CtxSession).(*sessions.Session)
|
||||||
user := r.Context().Value(CtxUser).(*model.User)
|
user := r.Context().Value(CtxUser).(*db.User)
|
||||||
if !user.IsAdmin {
|
if !user.IsAdmin {
|
||||||
sessAddFlashW(session, []string{"you are not an admin"})
|
sessAddFlashW(session, []string{"you are not an admin"})
|
||||||
sessLogSave(session, w, r)
|
sessLogSave(session, w, r)
|
||||||
|
|||||||
@@ -8,15 +8,14 @@ import (
|
|||||||
|
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"senan.xyz/g/gonic/db"
|
||||||
"senan.xyz/g/gonic/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func playlistParseLine(c *Controller, path string) (int, error) {
|
func playlistParseLine(c *Controller, path string) (int, error) {
|
||||||
if strings.HasPrefix(path, "#") || strings.TrimSpace(path) == "" {
|
if strings.HasPrefix(path, "#") || strings.TrimSpace(path) == "" {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
var track model.Track
|
var track db.Track
|
||||||
query := c.DB.Raw(`
|
query := c.DB.Raw(`
|
||||||
SELECT tracks.id FROM TRACKS
|
SELECT tracks.id FROM TRACKS
|
||||||
JOIN albums ON tracks.album_id = albums.id
|
JOIN albums ON tracks.album_id = albums.id
|
||||||
@@ -62,8 +61,8 @@ func playlistParseUpload(c *Controller, userID int, header *multipart.FileHeader
|
|||||||
if err := scanner.Err(); err != nil {
|
if err := scanner.Err(); err != nil {
|
||||||
return []string{fmt.Sprintf("iterating playlist file: %v", err)}, true
|
return []string{fmt.Sprintf("iterating playlist file: %v", err)}, true
|
||||||
}
|
}
|
||||||
playlist := &model.Playlist{}
|
playlist := &db.Playlist{}
|
||||||
c.DB.FirstOrCreate(playlist, model.Playlist{
|
c.DB.FirstOrCreate(playlist, db.Playlist{
|
||||||
Name: playlistName,
|
Name: playlistName,
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
|
|
||||||
"senan.xyz/g/gonic/model"
|
"senan.xyz/g/gonic/db"
|
||||||
"senan.xyz/g/gonic/server/ctrlsubsonic/params"
|
"senan.xyz/g/gonic/server/ctrlsubsonic/params"
|
||||||
"senan.xyz/g/gonic/server/ctrlsubsonic/spec"
|
"senan.xyz/g/gonic/server/ctrlsubsonic/spec"
|
||||||
)
|
)
|
||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
// under the root directory
|
// under the root directory
|
||||||
|
|
||||||
func (c *Controller) ServeGetIndexes(r *http.Request) *spec.Response {
|
func (c *Controller) ServeGetIndexes(r *http.Request) *spec.Response {
|
||||||
var folders []*model.Album
|
var folders []*db.Album
|
||||||
c.DB.
|
c.DB.
|
||||||
Select("*, count(sub.id) as child_count").
|
Select("*, count(sub.id) as child_count").
|
||||||
Joins(`
|
Joins(`
|
||||||
@@ -65,11 +65,11 @@ func (c *Controller) ServeGetMusicDirectory(r *http.Request) *spec.Response {
|
|||||||
return spec.NewError(10, "please provide an `id` parameter")
|
return spec.NewError(10, "please provide an `id` parameter")
|
||||||
}
|
}
|
||||||
childrenObj := []*spec.TrackChild{}
|
childrenObj := []*spec.TrackChild{}
|
||||||
folder := &model.Album{}
|
folder := &db.Album{}
|
||||||
c.DB.First(folder, id)
|
c.DB.First(folder, id)
|
||||||
//
|
//
|
||||||
// start looking for child childFolders in the current dir
|
// start looking for child childFolders in the current dir
|
||||||
var childFolders []*model.Album
|
var childFolders []*db.Album
|
||||||
c.DB.
|
c.DB.
|
||||||
Where("parent_id = ?", id).
|
Where("parent_id = ?", id).
|
||||||
Find(&childFolders)
|
Find(&childFolders)
|
||||||
@@ -78,7 +78,7 @@ func (c *Controller) ServeGetMusicDirectory(r *http.Request) *spec.Response {
|
|||||||
}
|
}
|
||||||
//
|
//
|
||||||
// start looking for child childTracks in the current dir
|
// start looking for child childTracks in the current dir
|
||||||
var childTracks []*model.Track
|
var childTracks []*db.Track
|
||||||
c.DB.
|
c.DB.
|
||||||
Where("album_id = ?", id).
|
Where("album_id = ?", id).
|
||||||
Preload("Album").
|
Preload("Album").
|
||||||
@@ -118,7 +118,7 @@ func (c *Controller) ServeGetAlbumList(r *http.Request) *spec.Response {
|
|||||||
case "alphabeticalByName":
|
case "alphabeticalByName":
|
||||||
q = q.Order("right_path")
|
q = q.Order("right_path")
|
||||||
case "frequent":
|
case "frequent":
|
||||||
user := r.Context().Value(CtxUser).(*model.User)
|
user := r.Context().Value(CtxUser).(*db.User)
|
||||||
q = q.Joins(`
|
q = q.Joins(`
|
||||||
JOIN plays
|
JOIN plays
|
||||||
ON albums.id = plays.album_id AND plays.user_id = ?`,
|
ON albums.id = plays.album_id AND plays.user_id = ?`,
|
||||||
@@ -129,7 +129,7 @@ func (c *Controller) ServeGetAlbumList(r *http.Request) *spec.Response {
|
|||||||
case "random":
|
case "random":
|
||||||
q = q.Order(gorm.Expr("random()"))
|
q = q.Order(gorm.Expr("random()"))
|
||||||
case "recent":
|
case "recent":
|
||||||
user := r.Context().Value(CtxUser).(*model.User)
|
user := r.Context().Value(CtxUser).(*db.User)
|
||||||
q = q.Joins(`
|
q = q.Joins(`
|
||||||
JOIN plays
|
JOIN plays
|
||||||
ON albums.id = plays.album_id AND plays.user_id = ?`,
|
ON albums.id = plays.album_id AND plays.user_id = ?`,
|
||||||
@@ -138,7 +138,7 @@ func (c *Controller) ServeGetAlbumList(r *http.Request) *spec.Response {
|
|||||||
default:
|
default:
|
||||||
return spec.NewError(10, "unknown value `%s` for parameter 'type'", listType)
|
return spec.NewError(10, "unknown value `%s` for parameter 'type'", listType)
|
||||||
}
|
}
|
||||||
var folders []*model.Album
|
var folders []*db.Album
|
||||||
q.
|
q.
|
||||||
Where("albums.tag_artist_id IS NOT NULL").
|
Where("albums.tag_artist_id IS NOT NULL").
|
||||||
Offset(params.GetIntOr("offset", 0)).
|
Offset(params.GetIntOr("offset", 0)).
|
||||||
@@ -165,7 +165,7 @@ func (c *Controller) ServeSearchTwo(r *http.Request) *spec.Response {
|
|||||||
results := &spec.SearchResultTwo{}
|
results := &spec.SearchResultTwo{}
|
||||||
//
|
//
|
||||||
// search "artists"
|
// search "artists"
|
||||||
var artists []*model.Album
|
var artists []*db.Album
|
||||||
c.DB.
|
c.DB.
|
||||||
Where(`
|
Where(`
|
||||||
parent_id = 1
|
parent_id = 1
|
||||||
@@ -181,7 +181,7 @@ func (c *Controller) ServeSearchTwo(r *http.Request) *spec.Response {
|
|||||||
}
|
}
|
||||||
//
|
//
|
||||||
// search "albums"
|
// search "albums"
|
||||||
var albums []*model.Album
|
var albums []*db.Album
|
||||||
c.DB.
|
c.DB.
|
||||||
Where(`
|
Where(`
|
||||||
tag_artist_id IS NOT NULL
|
tag_artist_id IS NOT NULL
|
||||||
@@ -196,7 +196,7 @@ func (c *Controller) ServeSearchTwo(r *http.Request) *spec.Response {
|
|||||||
}
|
}
|
||||||
//
|
//
|
||||||
// search tracks
|
// search tracks
|
||||||
var tracks []*model.Track
|
var tracks []*db.Track
|
||||||
c.DB.
|
c.DB.
|
||||||
Preload("Album").
|
Preload("Album").
|
||||||
Where(`
|
Where(`
|
||||||
|
|||||||
@@ -8,14 +8,14 @@ import (
|
|||||||
|
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
|
|
||||||
"senan.xyz/g/gonic/model"
|
"senan.xyz/g/gonic/db"
|
||||||
"senan.xyz/g/gonic/server/ctrlsubsonic/params"
|
"senan.xyz/g/gonic/server/ctrlsubsonic/params"
|
||||||
"senan.xyz/g/gonic/server/ctrlsubsonic/spec"
|
"senan.xyz/g/gonic/server/ctrlsubsonic/spec"
|
||||||
"senan.xyz/g/gonic/server/lastfm"
|
"senan.xyz/g/gonic/server/lastfm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Controller) ServeGetArtists(r *http.Request) *spec.Response {
|
func (c *Controller) ServeGetArtists(r *http.Request) *spec.Response {
|
||||||
var artists []*model.Artist
|
var artists []*db.Artist
|
||||||
c.DB.
|
c.DB.
|
||||||
Select("*, count(sub.id) as album_count").
|
Select("*, count(sub.id) as album_count").
|
||||||
Joins(`
|
Joins(`
|
||||||
@@ -57,7 +57,7 @@ func (c *Controller) ServeGetArtist(r *http.Request) *spec.Response {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return spec.NewError(10, "please provide an `id` parameter")
|
return spec.NewError(10, "please provide an `id` parameter")
|
||||||
}
|
}
|
||||||
artist := &model.Artist{}
|
artist := &db.Artist{}
|
||||||
c.DB.
|
c.DB.
|
||||||
Preload("Albums").
|
Preload("Albums").
|
||||||
First(artist, id)
|
First(artist, id)
|
||||||
@@ -77,7 +77,7 @@ func (c *Controller) ServeGetAlbum(r *http.Request) *spec.Response {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return spec.NewError(10, "please provide an `id` parameter")
|
return spec.NewError(10, "please provide an `id` parameter")
|
||||||
}
|
}
|
||||||
album := &model.Album{}
|
album := &db.Album{}
|
||||||
err = c.DB.
|
err = c.DB.
|
||||||
Preload("TagArtist").
|
Preload("TagArtist").
|
||||||
Preload("Tracks", func(db *gorm.DB) *gorm.DB {
|
Preload("Tracks", func(db *gorm.DB) *gorm.DB {
|
||||||
@@ -121,7 +121,7 @@ func (c *Controller) ServeGetAlbumListTwo(r *http.Request) *spec.Response {
|
|||||||
params.GetIntOr("toYear", 2200))
|
params.GetIntOr("toYear", 2200))
|
||||||
q = q.Order("tag_year")
|
q = q.Order("tag_year")
|
||||||
case "frequent":
|
case "frequent":
|
||||||
user := r.Context().Value(CtxUser).(*model.User)
|
user := r.Context().Value(CtxUser).(*db.User)
|
||||||
q = q.Joins(`
|
q = q.Joins(`
|
||||||
JOIN plays
|
JOIN plays
|
||||||
ON albums.id = plays.album_id AND plays.user_id = ?`,
|
ON albums.id = plays.album_id AND plays.user_id = ?`,
|
||||||
@@ -132,7 +132,7 @@ func (c *Controller) ServeGetAlbumListTwo(r *http.Request) *spec.Response {
|
|||||||
case "random":
|
case "random":
|
||||||
q = q.Order(gorm.Expr("random()"))
|
q = q.Order(gorm.Expr("random()"))
|
||||||
case "recent":
|
case "recent":
|
||||||
user := r.Context().Value(CtxUser).(*model.User)
|
user := r.Context().Value(CtxUser).(*db.User)
|
||||||
q = q.Joins(`
|
q = q.Joins(`
|
||||||
JOIN plays
|
JOIN plays
|
||||||
ON albums.id = plays.album_id AND plays.user_id = ?`,
|
ON albums.id = plays.album_id AND plays.user_id = ?`,
|
||||||
@@ -141,7 +141,7 @@ func (c *Controller) ServeGetAlbumListTwo(r *http.Request) *spec.Response {
|
|||||||
default:
|
default:
|
||||||
return spec.NewError(10, "unknown value `%s` for parameter 'type'", listType)
|
return spec.NewError(10, "unknown value `%s` for parameter 'type'", listType)
|
||||||
}
|
}
|
||||||
var albums []*model.Album
|
var albums []*db.Album
|
||||||
q.
|
q.
|
||||||
Where("albums.tag_artist_id IS NOT NULL").
|
Where("albums.tag_artist_id IS NOT NULL").
|
||||||
Offset(params.GetIntOr("offset", 0)).
|
Offset(params.GetIntOr("offset", 0)).
|
||||||
@@ -169,7 +169,7 @@ func (c *Controller) ServeSearchThree(r *http.Request) *spec.Response {
|
|||||||
results := &spec.SearchResultThree{}
|
results := &spec.SearchResultThree{}
|
||||||
//
|
//
|
||||||
// search "artists"
|
// search "artists"
|
||||||
var artists []*model.Artist
|
var artists []*db.Artist
|
||||||
c.DB.
|
c.DB.
|
||||||
Where(`
|
Where(`
|
||||||
name LIKE ? OR
|
name LIKE ? OR
|
||||||
@@ -184,7 +184,7 @@ func (c *Controller) ServeSearchThree(r *http.Request) *spec.Response {
|
|||||||
}
|
}
|
||||||
//
|
//
|
||||||
// search "albums"
|
// search "albums"
|
||||||
var albums []*model.Album
|
var albums []*db.Album
|
||||||
c.DB.
|
c.DB.
|
||||||
Preload("TagArtist").
|
Preload("TagArtist").
|
||||||
Where(`
|
Where(`
|
||||||
@@ -200,7 +200,7 @@ func (c *Controller) ServeSearchThree(r *http.Request) *spec.Response {
|
|||||||
}
|
}
|
||||||
//
|
//
|
||||||
// search tracks
|
// search tracks
|
||||||
var tracks []*model.Track
|
var tracks []*db.Track
|
||||||
c.DB.
|
c.DB.
|
||||||
Preload("Album").
|
Preload("Album").
|
||||||
Where(`
|
Where(`
|
||||||
@@ -229,7 +229,7 @@ func (c *Controller) ServeGetArtistInfoTwo(r *http.Request) *spec.Response {
|
|||||||
if apiKey == "" {
|
if apiKey == "" {
|
||||||
return spec.NewError(0, "please set ask your admin to set the last.fm api key")
|
return spec.NewError(0, "please set ask your admin to set the last.fm api key")
|
||||||
}
|
}
|
||||||
artist := &model.Artist{}
|
artist := &db.Artist{}
|
||||||
err = c.DB.
|
err = c.DB.
|
||||||
Where("id = ?", id).
|
Where("id = ?", id).
|
||||||
Find(artist).
|
Find(artist).
|
||||||
@@ -263,7 +263,7 @@ func (c *Controller) ServeGetArtistInfoTwo(r *http.Request) *spec.Response {
|
|||||||
if i == count {
|
if i == count {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
artist = &model.Artist{}
|
artist = &db.Artist{}
|
||||||
err = c.DB.
|
err = c.DB.
|
||||||
Select("*, count(albums.id) as album_count").
|
Select("*, count(albums.id) as album_count").
|
||||||
Where("name = ?", similarInfo.Name).
|
Where("name = ?", similarInfo.Name).
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
|
|
||||||
"senan.xyz/g/gonic/model"
|
"senan.xyz/g/gonic/db"
|
||||||
"senan.xyz/g/gonic/scanner"
|
"senan.xyz/g/gonic/scanner"
|
||||||
"senan.xyz/g/gonic/server/ctrlsubsonic/params"
|
"senan.xyz/g/gonic/server/ctrlsubsonic/params"
|
||||||
"senan.xyz/g/gonic/server/ctrlsubsonic/spec"
|
"senan.xyz/g/gonic/server/ctrlsubsonic/spec"
|
||||||
@@ -44,12 +44,12 @@ func (c *Controller) ServeScrobble(r *http.Request) *spec.Response {
|
|||||||
return spec.NewError(10, "please provide an `id` parameter")
|
return spec.NewError(10, "please provide an `id` parameter")
|
||||||
}
|
}
|
||||||
// fetch user to get lastfm session
|
// fetch user to get lastfm session
|
||||||
user := r.Context().Value(CtxUser).(*model.User)
|
user := r.Context().Value(CtxUser).(*db.User)
|
||||||
if user.LastFMSession == "" {
|
if user.LastFMSession == "" {
|
||||||
return spec.NewError(0, "you don't have a last.fm session")
|
return spec.NewError(0, "you don't have a last.fm session")
|
||||||
}
|
}
|
||||||
// fetch track for getting info to send to last.fm function
|
// fetch track for getting info to send to last.fm function
|
||||||
track := &model.Track{}
|
track := &db.Track{}
|
||||||
c.DB.
|
c.DB.
|
||||||
Preload("Album").
|
Preload("Album").
|
||||||
Preload("Artist").
|
Preload("Artist").
|
||||||
@@ -96,7 +96,7 @@ func (c *Controller) ServeStartScan(r *http.Request) *spec.Response {
|
|||||||
func (c *Controller) ServeGetScanStatus(r *http.Request) *spec.Response {
|
func (c *Controller) ServeGetScanStatus(r *http.Request) *spec.Response {
|
||||||
var trackCount int
|
var trackCount int
|
||||||
c.DB.
|
c.DB.
|
||||||
Model(model.Track{}).
|
Model(db.Track{}).
|
||||||
Count(&trackCount)
|
Count(&trackCount)
|
||||||
sub := spec.NewResponse()
|
sub := spec.NewResponse()
|
||||||
sub.ScanStatus = &spec.ScanStatus{
|
sub.ScanStatus = &spec.ScanStatus{
|
||||||
@@ -107,7 +107,7 @@ func (c *Controller) ServeGetScanStatus(r *http.Request) *spec.Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) ServeGetUser(r *http.Request) *spec.Response {
|
func (c *Controller) ServeGetUser(r *http.Request) *spec.Response {
|
||||||
user := r.Context().Value(CtxUser).(*model.User)
|
user := r.Context().Value(CtxUser).(*db.User)
|
||||||
sub := spec.NewResponse()
|
sub := spec.NewResponse()
|
||||||
sub.User = &spec.User{
|
sub.User = &spec.User{
|
||||||
Username: user.Name,
|
Username: user.Name,
|
||||||
@@ -123,8 +123,8 @@ func (c *Controller) ServeNotFound(r *http.Request) *spec.Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) ServeGetPlaylists(r *http.Request) *spec.Response {
|
func (c *Controller) ServeGetPlaylists(r *http.Request) *spec.Response {
|
||||||
user := r.Context().Value(CtxUser).(*model.User)
|
user := r.Context().Value(CtxUser).(*db.User)
|
||||||
var playlists []*model.Playlist
|
var playlists []*db.Playlist
|
||||||
c.DB.Where("user_id = ?", user.ID).Find(&playlists)
|
c.DB.Where("user_id = ?", user.ID).Find(&playlists)
|
||||||
sub := spec.NewResponse()
|
sub := spec.NewResponse()
|
||||||
sub.Playlists = &spec.Playlists{
|
sub.Playlists = &spec.Playlists{
|
||||||
@@ -144,7 +144,7 @@ func (c *Controller) ServeGetPlaylist(r *http.Request) *spec.Response {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return spec.NewError(10, "please provide an `id` parameter")
|
return spec.NewError(10, "please provide an `id` parameter")
|
||||||
}
|
}
|
||||||
playlist := model.Playlist{}
|
playlist := db.Playlist{}
|
||||||
err = c.DB.
|
err = c.DB.
|
||||||
Where("id = ?", playlistID).
|
Where("id = ?", playlistID).
|
||||||
Find(&playlist).
|
Find(&playlist).
|
||||||
@@ -152,7 +152,7 @@ func (c *Controller) ServeGetPlaylist(r *http.Request) *spec.Response {
|
|||||||
if gorm.IsRecordNotFoundError(err) {
|
if gorm.IsRecordNotFoundError(err) {
|
||||||
return spec.NewError(70, "playlist with id `%d` not found", playlistID)
|
return spec.NewError(70, "playlist with id `%d` not found", playlistID)
|
||||||
}
|
}
|
||||||
user := r.Context().Value(CtxUser).(*model.User)
|
user := r.Context().Value(CtxUser).(*db.User)
|
||||||
sub := spec.NewResponse()
|
sub := spec.NewResponse()
|
||||||
sub.Playlist = spec.NewPlaylist(&playlist)
|
sub.Playlist = spec.NewPlaylist(&playlist)
|
||||||
sub.Playlist.Owner = user.Name
|
sub.Playlist.Owner = user.Name
|
||||||
@@ -160,7 +160,7 @@ func (c *Controller) ServeGetPlaylist(r *http.Request) *spec.Response {
|
|||||||
trackIDs := playlist.GetItems()
|
trackIDs := playlist.GetItems()
|
||||||
sub.Playlist.List = make([]*spec.TrackChild, len(trackIDs))
|
sub.Playlist.List = make([]*spec.TrackChild, len(trackIDs))
|
||||||
for i, id := range trackIDs {
|
for i, id := range trackIDs {
|
||||||
track := model.Track{}
|
track := db.Track{}
|
||||||
c.DB.
|
c.DB.
|
||||||
Where("id = ?", id).
|
Where("id = ?", id).
|
||||||
Preload("Album").
|
Preload("Album").
|
||||||
@@ -171,7 +171,7 @@ func (c *Controller) ServeGetPlaylist(r *http.Request) *spec.Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) ServeUpdatePlaylist(r *http.Request) *spec.Response {
|
func (c *Controller) ServeUpdatePlaylist(r *http.Request) *spec.Response {
|
||||||
user := r.Context().Value(CtxUser).(*model.User)
|
user := r.Context().Value(CtxUser).(*db.User)
|
||||||
params := r.Context().Value(CtxParams).(params.Params)
|
params := r.Context().Value(CtxParams).(params.Params)
|
||||||
var playlistID int
|
var playlistID int
|
||||||
if p := params.GetFirstList("id", "playlistId"); p != nil {
|
if p := params.GetFirstList("id", "playlistId"); p != nil {
|
||||||
@@ -179,7 +179,7 @@ func (c *Controller) ServeUpdatePlaylist(r *http.Request) *spec.Response {
|
|||||||
}
|
}
|
||||||
// playlistID may be 0 from above. in that case we get a new playlist
|
// playlistID may be 0 from above. in that case we get a new playlist
|
||||||
// as intended
|
// as intended
|
||||||
playlist := &model.Playlist{ID: playlistID}
|
playlist := &db.Playlist{ID: playlistID}
|
||||||
c.DB.Where(playlist).First(playlist)
|
c.DB.Where(playlist).First(playlist)
|
||||||
// ** begin update meta info
|
// ** begin update meta info
|
||||||
playlist.UserID = user.ID
|
playlist.UserID = user.ID
|
||||||
@@ -211,13 +211,13 @@ func (c *Controller) ServeDeletePlaylist(r *http.Request) *spec.Response {
|
|||||||
params := r.Context().Value(CtxParams).(params.Params)
|
params := r.Context().Value(CtxParams).(params.Params)
|
||||||
c.DB.
|
c.DB.
|
||||||
Where("id = ?", params.GetIntOr("id", 0)).
|
Where("id = ?", params.GetIntOr("id", 0)).
|
||||||
Delete(&model.Playlist{})
|
Delete(&db.Playlist{})
|
||||||
return spec.NewResponse()
|
return spec.NewResponse()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) ServeGetPlayQueue(r *http.Request) *spec.Response {
|
func (c *Controller) ServeGetPlayQueue(r *http.Request) *spec.Response {
|
||||||
user := r.Context().Value(CtxUser).(*model.User)
|
user := r.Context().Value(CtxUser).(*db.User)
|
||||||
queue := model.PlayQueue{}
|
queue := db.PlayQueue{}
|
||||||
err := c.DB.
|
err := c.DB.
|
||||||
Where("user_id = ?", user.ID).
|
Where("user_id = ?", user.ID).
|
||||||
Find(&queue).
|
Find(&queue).
|
||||||
@@ -235,7 +235,7 @@ func (c *Controller) ServeGetPlayQueue(r *http.Request) *spec.Response {
|
|||||||
trackIDs := queue.GetItems()
|
trackIDs := queue.GetItems()
|
||||||
sub.PlayQueue.List = make([]*spec.TrackChild, len(trackIDs))
|
sub.PlayQueue.List = make([]*spec.TrackChild, len(trackIDs))
|
||||||
for i, id := range trackIDs {
|
for i, id := range trackIDs {
|
||||||
track := model.Track{}
|
track := db.Track{}
|
||||||
c.DB.
|
c.DB.
|
||||||
Where("id = ?", id).
|
Where("id = ?", id).
|
||||||
Preload("Album").
|
Preload("Album").
|
||||||
@@ -251,8 +251,8 @@ func (c *Controller) ServeSavePlayQueue(r *http.Request) *spec.Response {
|
|||||||
if tracks == nil {
|
if tracks == nil {
|
||||||
return spec.NewError(10, "please provide some `id` parameters")
|
return spec.NewError(10, "please provide some `id` parameters")
|
||||||
}
|
}
|
||||||
user := r.Context().Value(CtxUser).(*model.User)
|
user := r.Context().Value(CtxUser).(*db.User)
|
||||||
queue := &model.PlayQueue{UserID: user.ID}
|
queue := &db.PlayQueue{UserID: user.ID}
|
||||||
c.DB.Where(queue).First(queue)
|
c.DB.Where(queue).First(queue)
|
||||||
queue.Current = params.GetIntOr("current", 0)
|
queue.Current = params.GetIntOr("current", 0)
|
||||||
queue.Position = params.GetIntOr("position", 0)
|
queue.Position = params.GetIntOr("position", 0)
|
||||||
@@ -268,7 +268,7 @@ func (c *Controller) ServeGetSong(r *http.Request) *spec.Response {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return spec.NewError(10, "provide an `id` parameter")
|
return spec.NewError(10, "provide an `id` parameter")
|
||||||
}
|
}
|
||||||
track := &model.Track{}
|
track := &db.Track{}
|
||||||
err = c.DB.
|
err = c.DB.
|
||||||
Where("id = ?", id).
|
Where("id = ?", id).
|
||||||
Preload("Album").
|
Preload("Album").
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
|
|
||||||
"senan.xyz/g/gonic/model"
|
"senan.xyz/g/gonic/db"
|
||||||
"senan.xyz/g/gonic/server/ctrlsubsonic/params"
|
"senan.xyz/g/gonic/server/ctrlsubsonic/params"
|
||||||
"senan.xyz/g/gonic/server/ctrlsubsonic/spec"
|
"senan.xyz/g/gonic/server/ctrlsubsonic/spec"
|
||||||
)
|
)
|
||||||
@@ -24,7 +24,7 @@ func (c *Controller) ServeGetCoverArt(w http.ResponseWriter, r *http.Request) *s
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return spec.NewError(10, "please provide an `id` parameter")
|
return spec.NewError(10, "please provide an `id` parameter")
|
||||||
}
|
}
|
||||||
folder := &model.Album{}
|
folder := &db.Album{}
|
||||||
err = c.DB.
|
err = c.DB.
|
||||||
Select("id, left_path, right_path, cover").
|
Select("id, left_path, right_path, cover").
|
||||||
First(folder, id).
|
First(folder, id).
|
||||||
@@ -51,7 +51,7 @@ func (c *Controller) ServeStream(w http.ResponseWriter, r *http.Request) *spec.R
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return spec.NewError(10, "please provide an `id` parameter")
|
return spec.NewError(10, "please provide an `id` parameter")
|
||||||
}
|
}
|
||||||
track := &model.Track{}
|
track := &db.Track{}
|
||||||
err = c.DB.
|
err = c.DB.
|
||||||
Preload("Album").
|
Preload("Album").
|
||||||
First(track, id).
|
First(track, id).
|
||||||
@@ -68,8 +68,8 @@ func (c *Controller) ServeStream(w http.ResponseWriter, r *http.Request) *spec.R
|
|||||||
http.ServeFile(w, r, absPath)
|
http.ServeFile(w, r, absPath)
|
||||||
//
|
//
|
||||||
// after we've served the file, mark the album as played
|
// after we've served the file, mark the album as played
|
||||||
user := r.Context().Value(CtxUser).(*model.User)
|
user := r.Context().Value(CtxUser).(*db.User)
|
||||||
play := model.Play{
|
play := db.Play{
|
||||||
AlbumID: track.Album.ID,
|
AlbumID: track.Album.ID,
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package spec
|
package spec
|
||||||
|
|
||||||
import "senan.xyz/g/gonic/model"
|
import "senan.xyz/g/gonic/db"
|
||||||
|
|
||||||
func NewPlaylist(p *model.Playlist) *Playlist {
|
func NewPlaylist(p *db.Playlist) *Playlist {
|
||||||
return &Playlist{
|
return &Playlist{
|
||||||
ID: p.ID,
|
ID: p.ID,
|
||||||
Name: p.Name,
|
Name: p.Name,
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ package spec
|
|||||||
import (
|
import (
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
"senan.xyz/g/gonic/model"
|
"senan.xyz/g/gonic/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewAlbumByFolder(f *model.Album) *Album {
|
func NewAlbumByFolder(f *db.Album) *Album {
|
||||||
a := &Album{
|
a := &Album{
|
||||||
Artist: f.Parent.RightPath,
|
Artist: f.Parent.RightPath,
|
||||||
ID: f.ID,
|
ID: f.ID,
|
||||||
@@ -21,7 +21,7 @@ func NewAlbumByFolder(f *model.Album) *Album {
|
|||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTCAlbumByFolder(f *model.Album) *TrackChild {
|
func NewTCAlbumByFolder(f *db.Album) *TrackChild {
|
||||||
trCh := &TrackChild{
|
trCh := &TrackChild{
|
||||||
ID: f.ID,
|
ID: f.ID,
|
||||||
IsDir: true,
|
IsDir: true,
|
||||||
@@ -35,7 +35,7 @@ func NewTCAlbumByFolder(f *model.Album) *TrackChild {
|
|||||||
return trCh
|
return trCh
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTCTrackByFolder(t *model.Track, parent *model.Album) *TrackChild {
|
func NewTCTrackByFolder(t *db.Track, parent *db.Album) *TrackChild {
|
||||||
trCh := &TrackChild{
|
trCh := &TrackChild{
|
||||||
ID: t.ID,
|
ID: t.ID,
|
||||||
ContentType: t.MIME(),
|
ContentType: t.MIME(),
|
||||||
@@ -66,7 +66,7 @@ func NewTCTrackByFolder(t *model.Track, parent *model.Album) *TrackChild {
|
|||||||
return trCh
|
return trCh
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewArtistByFolder(f *model.Album) *Artist {
|
func NewArtistByFolder(f *db.Album) *Artist {
|
||||||
return &Artist{
|
return &Artist{
|
||||||
ID: f.ID,
|
ID: f.ID,
|
||||||
Name: f.RightPath,
|
Name: f.RightPath,
|
||||||
@@ -74,7 +74,7 @@ func NewArtistByFolder(f *model.Album) *Artist {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDirectoryByFolder(f *model.Album, children []*TrackChild) *Directory {
|
func NewDirectoryByFolder(f *db.Album, children []*TrackChild) *Directory {
|
||||||
dir := &Directory{
|
dir := &Directory{
|
||||||
ID: f.ID,
|
ID: f.ID,
|
||||||
Name: f.RightPath,
|
Name: f.RightPath,
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ package spec
|
|||||||
import (
|
import (
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
"senan.xyz/g/gonic/model"
|
"senan.xyz/g/gonic/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewAlbumByTags(a *model.Album, artist *model.Artist) *Album {
|
func NewAlbumByTags(a *db.Album, artist *db.Artist) *Album {
|
||||||
ret := &Album{
|
ret := &Album{
|
||||||
Created: a.ModifiedAt,
|
Created: a.ModifiedAt,
|
||||||
ID: a.ID,
|
ID: a.ID,
|
||||||
@@ -23,7 +23,7 @@ func NewAlbumByTags(a *model.Album, artist *model.Artist) *Album {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTrackByTags(t *model.Track, album *model.Album) *TrackChild {
|
func NewTrackByTags(t *db.Track, album *db.Album) *TrackChild {
|
||||||
ret := &TrackChild{
|
ret := &TrackChild{
|
||||||
ID: t.ID,
|
ID: t.ID,
|
||||||
ContentType: t.MIME(),
|
ContentType: t.MIME(),
|
||||||
@@ -55,7 +55,7 @@ func NewTrackByTags(t *model.Track, album *model.Album) *TrackChild {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewArtistByTags(a *model.Artist) *Artist {
|
func NewArtistByTags(a *db.Artist) *Artist {
|
||||||
return &Artist{
|
return &Artist{
|
||||||
ID: a.ID,
|
ID: a.ID,
|
||||||
Name: a.Name,
|
Name: a.Name,
|
||||||
|
|||||||
BIN
server/ctrlsubsonic/testdata/db
vendored
BIN
server/ctrlsubsonic/testdata/db
vendored
Binary file not shown.
@@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"senan.xyz/g/gonic/model"
|
"senan.xyz/g/gonic/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -55,7 +55,6 @@ func makeRequest(method string, params url.Values) (LastFM, error) {
|
|||||||
if err = decoder.Decode(&lastfm); err != nil {
|
if err = decoder.Decode(&lastfm); err != nil {
|
||||||
return LastFM{}, errors.Wrap(err, "decoding")
|
return LastFM{}, errors.Wrap(err, "decoding")
|
||||||
}
|
}
|
||||||
//?
|
|
||||||
if lastfm.Error.Code != 0 {
|
if lastfm.Error.Code != 0 {
|
||||||
return LastFM{}, fmt.Errorf("parsing: %v", lastfm.Error.Value)
|
return LastFM{}, fmt.Errorf("parsing: %v", lastfm.Error.Value)
|
||||||
}
|
}
|
||||||
@@ -76,7 +75,7 @@ func GetSession(apiKey, secret, token string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ScrobbleOpts struct {
|
type ScrobbleOpts struct {
|
||||||
Track *model.Track
|
Track *db.Track
|
||||||
StampMili int
|
StampMili int
|
||||||
Submission bool
|
Submission bool
|
||||||
}
|
}
|
||||||
@@ -103,7 +102,7 @@ func Scrobble(apiKey, secret, session string, opts ScrobbleOpts) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func ArtistGetInfo(apiKey string, artist *model.Artist) (Artist, error) {
|
func ArtistGetInfo(apiKey string, artist *db.Artist) (Artist, error) {
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Add("method", "artist.getInfo")
|
params.Add("method", "artist.getInfo")
|
||||||
params.Add("api_key", apiKey)
|
params.Add("api_key", apiKey)
|
||||||
|
|||||||
@@ -4,8 +4,10 @@
|
|||||||
|
|
||||||
package version
|
package version
|
||||||
|
|
||||||
const NAME = "gonic"
|
const (
|
||||||
const NAME_UPPER = "GONIC"
|
NAME = "gonic"
|
||||||
const NAME_EMBED = "gonicembed"
|
NAME_UPPER = "GONIC"
|
||||||
const NAME_SCAN = "gonicscan"
|
NAME_EMBED = "gonicembed"
|
||||||
const VERSION = "v0.6.3"
|
NAME_SCAN = "gonicscan"
|
||||||
|
VERSION = "v0.6.3"
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user