Avoid warnings in ui package

Remove unused variables and improve JSON decoding in
saveEnclosureProgression()
This commit is contained in:
Frédéric Guillot 2024-03-15 19:28:38 -07:00
parent 309fdbb9fc
commit f6f63b5282
2 changed files with 8 additions and 17 deletions

View file

@ -4,8 +4,7 @@
package ui // import "miniflux.app/v2/internal/ui" package ui // import "miniflux.app/v2/internal/ui"
import ( import (
json2 "encoding/json" json_parser "encoding/json"
"io"
"net/http" "net/http"
"miniflux.app/v2/internal/http/request" "miniflux.app/v2/internal/http/request"
@ -30,21 +29,13 @@ func (h *handler) saveEnclosureProgression(w http.ResponseWriter, r *http.Reques
} }
var postData enclosurePositionSaveRequest var postData enclosurePositionSaveRequest
body, err := io.ReadAll(r.Body) if err := json_parser.NewDecoder(r.Body).Decode(&postData); err != nil {
if err != nil {
json.ServerError(w, r, err)
return
}
json2.Unmarshal(body, &postData)
if err != nil {
json.ServerError(w, r, err) json.ServerError(w, r, err)
return return
} }
enclosure.MediaProgression = postData.Progression enclosure.MediaProgression = postData.Progression
err = h.store.UpdateEnclosure(enclosure) if err := h.store.UpdateEnclosure(enclosure); err != nil {
if err != nil {
json.ServerError(w, r, err) json.ServerError(w, r, err)
return return
} }

View file

@ -57,7 +57,7 @@ func (u WebAuthnUser) WebAuthnCredentials() []webauthn.Credential {
return creds return creds
} }
func newWebAuthn(h *handler) (*webauthn.WebAuthn, error) { func newWebAuthn() (*webauthn.WebAuthn, error) {
url, err := url.Parse(config.Opts.BaseURL()) url, err := url.Parse(config.Opts.BaseURL())
if err != nil { if err != nil {
return nil, err return nil, err
@ -70,7 +70,7 @@ func newWebAuthn(h *handler) (*webauthn.WebAuthn, error) {
} }
func (h *handler) beginRegistration(w http.ResponseWriter, r *http.Request) { func (h *handler) beginRegistration(w http.ResponseWriter, r *http.Request) {
web, err := newWebAuthn(h) web, err := newWebAuthn()
if err != nil { if err != nil {
json.ServerError(w, r, err) json.ServerError(w, r, err)
return return
@ -117,7 +117,7 @@ func (h *handler) beginRegistration(w http.ResponseWriter, r *http.Request) {
} }
func (h *handler) finishRegistration(w http.ResponseWriter, r *http.Request) { func (h *handler) finishRegistration(w http.ResponseWriter, r *http.Request) {
web, err := newWebAuthn(h) web, err := newWebAuthn()
if err != nil { if err != nil {
json.ServerError(w, r, err) json.ServerError(w, r, err)
return return
@ -152,7 +152,7 @@ func (h *handler) finishRegistration(w http.ResponseWriter, r *http.Request) {
} }
func (h *handler) beginLogin(w http.ResponseWriter, r *http.Request) { func (h *handler) beginLogin(w http.ResponseWriter, r *http.Request) {
web, err := newWebAuthn(h) web, err := newWebAuthn()
if err != nil { if err != nil {
json.ServerError(w, r, err) json.ServerError(w, r, err)
return return
@ -195,7 +195,7 @@ func (h *handler) beginLogin(w http.ResponseWriter, r *http.Request) {
} }
func (h *handler) finishLogin(w http.ResponseWriter, r *http.Request) { func (h *handler) finishLogin(w http.ResponseWriter, r *http.Request) {
web, err := newWebAuthn(h) web, err := newWebAuthn()
if err != nil { if err != nil {
json.ServerError(w, r, err) json.ServerError(w, r, err)
return return