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
50
internal/http/update.go
Normal file
50
internal/http/update.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/autobrr/autobrr/pkg/version"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/render"
|
||||
)
|
||||
|
||||
type updateService interface {
|
||||
CheckUpdates(ctx context.Context)
|
||||
GetLatestRelease(ctx context.Context) *version.Release
|
||||
}
|
||||
|
||||
type updateHandler struct {
|
||||
encoder encoder
|
||||
service updateService
|
||||
}
|
||||
|
||||
func newUpdateHandler(encoder encoder, service updateService) *updateHandler {
|
||||
return &updateHandler{
|
||||
encoder: encoder,
|
||||
service: service,
|
||||
}
|
||||
}
|
||||
|
||||
func (h updateHandler) Routes(r chi.Router) {
|
||||
r.Get("/latest", h.getLatest)
|
||||
r.Get("/check", h.checkUpdates)
|
||||
}
|
||||
|
||||
func (h updateHandler) getLatest(w http.ResponseWriter, r *http.Request) {
|
||||
latest := h.service.GetLatestRelease(r.Context())
|
||||
if latest != nil {
|
||||
render.Status(r, http.StatusOK)
|
||||
render.JSON(w, r, latest)
|
||||
return
|
||||
}
|
||||
|
||||
render.NoContent(w, r)
|
||||
}
|
||||
|
||||
func (h updateHandler) checkUpdates(w http.ResponseWriter, r *http.Request) {
|
||||
h.service.CheckUpdates(r.Context())
|
||||
|
||||
render.NoContent(w, r)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue