Skip to content

Commit

Permalink
fix: display old groups to facilitate conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
toboshii committed Oct 2, 2022
1 parent 49f5e77 commit b321846
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
4 changes: 0 additions & 4 deletions internal/handlers/startpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ func (sr *startpageResource) StartpageCtx(next http.Handler) http.Handler {
func (sr *startpageResource) GetStartpage(w http.ResponseWriter, r *http.Request) {
startpage := r.Context().Value(contextKeyStartpage).(*models.Startpage)

if len(startpage.Bookmarks) == 0 {
startpage.Bookmarks = []models.BookmarkGroup{}
}

appConfig, err := config.GetConfig()
if err != nil {
logger.Error("Failed to read configuration for hajimari: ", err)
Expand Down
2 changes: 2 additions & 0 deletions internal/models/startpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ type Startpage struct {
DefaultSearchProvider string `json:"defaultSearchProvider"`
SearchProviders []SearchProvider `json:"searchProviders"`
Bookmarks []BookmarkGroup `json:"bookmarks"`
// Deprecated
Groups []map[string]interface{} `json:"groups,omitempty"`
}
15 changes: 14 additions & 1 deletion internal/services/startpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,20 @@ func (s *startpageService) NewStartpage(startpage *models.Startpage) (string, er
}

func (s *startpageService) GetStartpage(id string) (*models.Startpage, error) {
return s.store.GetStartpage(id)
startpage, err := s.store.GetStartpage(id)
if err != nil {
return startpage, err
}

if len(startpage.Bookmarks) == 0 {
startpage.Bookmarks = []models.BookmarkGroup{}
}

if len(startpage.Groups) > 0 {
logger.Warnf("Startpage %s contains deprecated option `groups`, please convert it to `bookmarks`", startpage.ID)
}

return startpage, err
}

func (s *startpageService) UpdateStartpage(id string, startpage *models.Startpage) (*models.Startpage, error) {
Expand Down
16 changes: 15 additions & 1 deletion internal/stores/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,21 @@ var startpages = []*models.Startpage{
},
},
},
{ID: "r1NqSpS1C0z3cMHyzX-Y5", Name: "Bob"},
{
ID: "r1NqSpS1C0z3cMHyzX-Y5",
Name: "Bob",
Groups: []map[string]interface{}{
{
"name": "communicate",
"links": []map[string]interface{}{
{
"name": "Discord",
"url": "https://discord.im",
},
},
},
},
},
{ID: "NmcvYTdRozUDNpbjAxFTO", Name: "Carol"},
{ID: "3OG1X_GuRS_TrCcWb5YjK", Name: "Derrick"},
{ID: "Qq4EF6MaSKaYZpEldtLTn", Name: "Emily"},
Expand Down

0 comments on commit b321846

Please sign in to comment.