mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +00:00
feat: show new updates in dashboard (#690)
* feat: show new update banner * feat(http): add request logger * refactor: updates checker * feat: make update check optional * fix: empty releases * add toggle switch for update checks * feat: toggle updates check from settings * feat: toggle updates check from settings * feat: check on toggle enabled --------- Co-authored-by: soup <soup@r4tio.dev>
This commit is contained in:
parent
3fdd7cf5e4
commit
2917a7d42d
24 changed files with 687 additions and 121 deletions
|
@ -1,52 +1,84 @@
|
|||
package http
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/config"
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/render"
|
||||
)
|
||||
|
||||
type configJson struct {
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
LogLevel string `json:"log_level"`
|
||||
LogPath string `json:"log_path"`
|
||||
BaseURL string `json:"base_url"`
|
||||
Version string `json:"version"`
|
||||
Commit string `json:"commit"`
|
||||
Date string `json:"date"`
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
LogLevel string `json:"log_level"`
|
||||
LogPath string `json:"log_path"`
|
||||
BaseURL string `json:"base_url"`
|
||||
CheckForUpdates bool `json:"check_for_updates"`
|
||||
Version string `json:"version"`
|
||||
Commit string `json:"commit"`
|
||||
Date string `json:"date"`
|
||||
}
|
||||
|
||||
type configHandler struct {
|
||||
encoder encoder
|
||||
|
||||
cfg *config.AppConfig
|
||||
server Server
|
||||
}
|
||||
|
||||
func newConfigHandler(encoder encoder, server Server) *configHandler {
|
||||
func newConfigHandler(encoder encoder, server Server, cfg *config.AppConfig) *configHandler {
|
||||
return &configHandler{
|
||||
encoder: encoder,
|
||||
cfg: cfg,
|
||||
server: server,
|
||||
}
|
||||
}
|
||||
|
||||
func (h configHandler) Routes(r chi.Router) {
|
||||
r.Get("/", h.getConfig)
|
||||
r.Patch("/", h.updateConfig)
|
||||
}
|
||||
|
||||
func (h configHandler) getConfig(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
||||
conf := configJson{
|
||||
Host: h.server.config.Host,
|
||||
Port: h.server.config.Port,
|
||||
LogLevel: h.server.config.LogLevel,
|
||||
LogPath: h.server.config.LogPath,
|
||||
BaseURL: h.server.config.BaseURL,
|
||||
Version: h.server.version,
|
||||
Commit: h.server.commit,
|
||||
Date: h.server.date,
|
||||
Host: h.cfg.Config.Host,
|
||||
Port: h.cfg.Config.Port,
|
||||
LogLevel: h.cfg.Config.LogLevel,
|
||||
LogPath: h.cfg.Config.LogPath,
|
||||
BaseURL: h.cfg.Config.BaseURL,
|
||||
CheckForUpdates: h.cfg.Config.CheckForUpdates,
|
||||
Version: h.server.version,
|
||||
Commit: h.server.commit,
|
||||
Date: h.server.date,
|
||||
}
|
||||
|
||||
h.encoder.StatusResponse(ctx, w, conf, http.StatusOK)
|
||||
render.JSON(w, r, conf)
|
||||
}
|
||||
|
||||
func (h configHandler) updateConfig(w http.ResponseWriter, r *http.Request) {
|
||||
var data domain.ConfigUpdate
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&data); err != nil {
|
||||
h.encoder.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
if data.CheckForUpdates != nil {
|
||||
h.cfg.Config.CheckForUpdates = *data.CheckForUpdates
|
||||
}
|
||||
|
||||
if err := h.cfg.UpdateConfig(); err != nil {
|
||||
render.Status(r, http.StatusInternalServerError)
|
||||
render.JSON(w, r, errorResponse{
|
||||
Message: err.Error(),
|
||||
Status: http.StatusInternalServerError,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
render.NoContent(w, r)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue