use consistent case for indexes

This commit is contained in:
sentriz
2019-06-07 11:23:09 +01:00
parent 8123be035c
commit c6fdd38f4e
5 changed files with 15 additions and 14 deletions

View File

@@ -23,14 +23,14 @@ func (c *Controller) GetIndexes(w http.ResponseWriter, r *http.Request) {
c.DB.
Where("parent_id = 1").
Find(&folders)
indexMap := make(map[rune]*subsonic.Index)
indexMap := make(map[string]*subsonic.Index)
indexes := []*subsonic.Index{}
for _, folder := range folders {
i := indexOf(folder.RightPath)
i := indexOf(folder.RightPath[0])
index, ok := indexMap[i]
if !ok {
index = &subsonic.Index{
Name: string(i),
Name: i,
Artists: []*subsonic.Artist{},
}
indexMap[i] = index

View File

@@ -15,14 +15,14 @@ import (
func (c *Controller) GetArtists(w http.ResponseWriter, r *http.Request) {
var artists []*model.Artist
c.DB.Find(&artists)
indexMap := make(map[rune]*subsonic.Index)
indexMap := make(map[string]*subsonic.Index)
indexes := &subsonic.Artists{}
for _, artist := range artists {
i := indexOf(artist.Name)
i := indexOf(artist.Name[0])
index, ok := indexMap[i]
if !ok {
index = &subsonic.Index{
Name: string(i),
Name: i,
Artists: []*subsonic.Artist{},
}
indexMap[i] = index

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"os"
"path"
"strings"
"sync/atomic"
"time"
"unicode"
@@ -18,13 +19,13 @@ import (
"github.com/sentriz/gonic/server/subsonic"
)
func indexOf(s string) rune {
first := string(s[0])
c := rune(unidecode.Unidecode(first)[0])
if !unicode.IsLetter(c) {
return '#'
func indexOf(in byte) string {
lower := strings.ToLower(string(in))
decode := unidecode.Unidecode(lower)
if !unicode.IsLetter(rune(decode[0])) {
return "#"
}
return c
return decode
}
func (c *Controller) Stream(w http.ResponseWriter, r *http.Request) {

View File

@@ -14,7 +14,7 @@
]
},
{
"name": "A",
"name": "a",
"artist": [
{
"id": 1,

View File

@@ -19,7 +19,7 @@
]
},
{
"name": "A",
"name": "a",
"artist": [
{
"id": 2,