Fixed merge conflicts

This commit is contained in:
BetaPictoris
2023-10-28 17:05:50 -07:00
60 changed files with 1996 additions and 1267 deletions

No files matched your search

+5 -2
View File
@@ -59,7 +59,10 @@
<p class="col-span-full text-gray-500" title="{{ .LastScanTime }}">scanned {{ .LastScanTime | dateHuman }}</p>
{{ end }}
<form class="col-span-full" action="{{ path "/admin/start_scan_inc_do" }}" method="post">
<input type="submit" title="start a incremental scan" value="scan now">
<input type="submit" title="start a incremental scan. gonic will only scan files that have changed since the last scan. it is usually quite fast" value="scan (i)">
</form>
<form class="col-span-full" action="{{ path "/admin/start_scan_full_do" }}" method="post">
<input type="submit" title="start a slow scan. gonic will not check the timestamps of changed files. you generally shouldn't need this" value="scan slow (i)">
</form>
{{ end }}
{{ if .IsScanning }}<p class="text-green-500 col-span-full">scan in progress...</p>{{ end }}
@@ -93,7 +96,7 @@
{{ component "block" (props .
"Icon" "lastfm"
"Name" "last.fm"
"Desc" "scrobble to last.fm on a per user basis (the admin must set a global api key first)"
"Desc" "scrobble to last.fm on a per user basis. adding an api key will also help gonic get rich artist info and images for subsonic clients"
) }}
<div class="flex flex-col gap-2 items-end">
{{ if .CurrentLastFMAPIKey }}
+12 -12
View File
@@ -50,7 +50,7 @@ func (c *Controller) ServeHome(r *http.Request) *Response {
c.DB.Table("tracks").Count(&data.TrackCount)
// lastfm box
data.RequestRoot = c.BaseURL(r)
data.CurrentLastFMAPIKey, _ = c.DB.GetSetting("lastfm_api_key")
data.CurrentLastFMAPIKey, _ = c.DB.GetSetting(db.LastFMAPIKey)
data.DefaultListenBrainzURL = listenbrainz.BaseURL
// users box
@@ -62,12 +62,12 @@ func (c *Controller) ServeHome(r *http.Request) *Response {
// recent folders box
c.DB.
Where("tag_artist_id IS NOT NULL").
Order("created_at DESC").
Limit(8).
Limit(20).
Find(&data.RecentFolders)
data.IsScanning = c.Scanner.IsScanning()
if tStr, err := c.DB.GetSetting("last_scan_time"); err != nil {
if tStr, _ := c.DB.GetSetting(db.LastScanTime); tStr != "" {
i, _ := strconv.ParseInt(tStr, 10, 64)
data.LastScanTime = time.Unix(i, 0)
}
@@ -97,11 +97,11 @@ func (c *Controller) ServeLinkLastFMDo(r *http.Request) *Response {
if token == "" {
return &Response{code: 400, err: "please provide a token"}
}
apiKey, err := c.DB.GetSetting("lastfm_api_key")
apiKey, err := c.DB.GetSetting(db.LastFMAPIKey)
if err != nil {
return &Response{redirect: r.Referer(), flashW: []string{fmt.Sprintf("couldn't get api key: %v", err)}}
}
secret, err := c.DB.GetSetting("lastfm_secret")
secret, err := c.DB.GetSetting(db.LastFMSecret)
if err != nil {
return &Response{redirect: r.Referer(), flashW: []string{fmt.Sprintf("couldn't get secret: %v", err)}}
}
@@ -457,10 +457,10 @@ func (c *Controller) ServeCreateUserDo(r *http.Request) *Response {
func (c *Controller) ServeUpdateLastFMAPIKey(r *http.Request) *Response {
data := &templateData{}
var err error
if data.CurrentLastFMAPIKey, err = c.DB.GetSetting("lastfm_api_key"); err != nil {
if data.CurrentLastFMAPIKey, err = c.DB.GetSetting(db.LastFMAPIKey); err != nil {
return &Response{redirect: r.Referer(), flashW: []string{fmt.Sprintf("couldn't get api key: %v", err)}}
}
if data.CurrentLastFMAPISecret, err = c.DB.GetSetting("lastfm_secret"); err != nil {
if data.CurrentLastFMAPISecret, err = c.DB.GetSetting(db.LastFMSecret); err != nil {
return &Response{redirect: r.Referer(), flashW: []string{fmt.Sprintf("couldn't get secret: %v", err)}}
}
return &Response{
@@ -478,10 +478,10 @@ func (c *Controller) ServeUpdateLastFMAPIKeyDo(r *http.Request) *Response {
flashW: []string{err.Error()},
}
}
if err := c.DB.SetSetting("lastfm_api_key", apiKey); err != nil {
if err := c.DB.SetSetting(db.LastFMAPIKey, apiKey); err != nil {
return &Response{redirect: r.Referer(), flashW: []string{fmt.Sprintf("couldn't set api key: %v", err)}}
}
if err := c.DB.SetSetting("lastfm_secret", secret); err != nil {
if err := c.DB.SetSetting(db.LastFMSecret, secret); err != nil {
return &Response{redirect: r.Referer(), flashW: []string{fmt.Sprintf("couldn't set secret: %v", err)}}
}
return &Response{redirect: "/admin/home"}
@@ -568,7 +568,7 @@ func (c *Controller) ServePodcastDownloadDo(r *http.Request) *Response {
return &Response{code: 400, err: "please provide a valid podcast id"}
}
if err := c.Podcasts.DownloadPodcastAll(id); err != nil {
return &Response{code: 400, err: "please provide a valid podcast id"}
return &Response{redirect: r.Referer(), flashW: []string{fmt.Sprintf("error downloading: %v", err)}}
}
return &Response{
redirect: "/admin/home",
@@ -609,7 +609,7 @@ func (c *Controller) ServePodcastDeleteDo(r *http.Request) *Response {
return &Response{code: 400, err: "please provide a valid podcast id"}
}
if err := c.Podcasts.DeletePodcast(id); err != nil {
return &Response{code: 400, err: "please provide a valid podcast id"}
return &Response{redirect: r.Referer(), flashW: []string{fmt.Sprintf("error deleting: %v", err)}}
}
return &Response{
redirect: "/admin/home",
+64
View File
@@ -0,0 +1,64 @@
package ctrladmin
import (
"net/http"
"github.com/gorilla/mux"
"go.senan.xyz/gonic/server/ctrladmin/adminui"
)
func AddRoutes(c *Controller, r *mux.Router) {
// public routes (creates session)
r.Use(c.WithSession)
r.Handle("/login", c.H(c.ServeLogin))
r.Handle("/login_do", c.HR(c.ServeLoginDo)) // "raw" handler, updates session
staticHandler := http.StripPrefix("/admin", http.FileServer(http.FS(adminui.StaticFS)))
r.PathPrefix("/static").Handler(staticHandler)
// user routes (if session is valid)
routUser := r.NewRoute().Subrouter()
routUser.Use(c.WithUserSession)
routUser.Handle("/logout", c.HR(c.ServeLogout)) // "raw" handler, updates session
routUser.Handle("/home", c.H(c.ServeHome))
routUser.Handle("/ldap", c.H(c.ServeLDAPConfig))
routUser.Handle("/ldap_do", c.H(c.ServeLDAPConfigDo))
routUser.Handle("/change_username", c.H(c.ServeChangeUsername))
routUser.Handle("/change_username_do", c.H(c.ServeChangeUsernameDo))
routUser.Handle("/change_password", c.H(c.ServeChangePassword))
routUser.Handle("/change_password_do", c.H(c.ServeChangePasswordDo))
routUser.Handle("/change_avatar", c.H(c.ServeChangeAvatar))
routUser.Handle("/change_avatar_do", c.H(c.ServeChangeAvatarDo))
routUser.Handle("/delete_avatar_do", c.H(c.ServeDeleteAvatarDo))
routUser.Handle("/delete_user", c.H(c.ServeDeleteUser))
routUser.Handle("/delete_user_do", c.H(c.ServeDeleteUserDo))
routUser.Handle("/link_lastfm_do", c.H(c.ServeLinkLastFMDo))
routUser.Handle("/unlink_lastfm_do", c.H(c.ServeUnlinkLastFMDo))
routUser.Handle("/link_listenbrainz_do", c.H(c.ServeLinkListenBrainzDo))
routUser.Handle("/unlink_listenbrainz_do", c.H(c.ServeUnlinkListenBrainzDo))
routUser.Handle("/create_transcode_pref_do", c.H(c.ServeCreateTranscodePrefDo))
routUser.Handle("/delete_transcode_pref_do", c.H(c.ServeDeleteTranscodePrefDo))
// admin routes (if session is valid, and is admin)
routAdmin := routUser.NewRoute().Subrouter()
routAdmin.Use(c.WithAdminSession)
routAdmin.Handle("/create_user", c.H(c.ServeCreateUser))
routAdmin.Handle("/create_user_do", c.H(c.ServeCreateUserDo))
routAdmin.Handle("/update_lastfm_api_key", c.H(c.ServeUpdateLastFMAPIKey))
routAdmin.Handle("/update_lastfm_api_key_do", c.H(c.ServeUpdateLastFMAPIKeyDo))
routAdmin.Handle("/start_scan_inc_do", c.H(c.ServeStartScanIncDo))
routAdmin.Handle("/start_scan_full_do", c.H(c.ServeStartScanFullDo))
routAdmin.Handle("/add_podcast_do", c.H(c.ServePodcastAddDo))
routAdmin.Handle("/delete_podcast_do", c.H(c.ServePodcastDeleteDo))
routAdmin.Handle("/download_podcast_do", c.H(c.ServePodcastDownloadDo))
routAdmin.Handle("/update_podcast_do", c.H(c.ServePodcastUpdateDo))
routAdmin.Handle("/add_internet_radio_station_do", c.H(c.ServeInternetRadioStationAddDo))
routAdmin.Handle("/delete_internet_radio_station_do", c.H(c.ServeInternetRadioStationDeleteDo))
routAdmin.Handle("/update_internet_radio_station_do", c.H(c.ServeInternetRadioStationUpdateDo))
// middlewares should be run for not found handler
// https://github.com/gorilla/mux/issues/416
notFoundHandler := c.H(c.ServeNotFound)
notFoundRoute := r.NewRoute().Handler(notFoundHandler)
r.NotFoundHandler = notFoundRoute.GetHandler()
}