mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add session to settings change.
This commit is contained in:
@ -31,7 +31,7 @@ func New(
|
||||
}
|
||||
|
||||
// generate fallback image for private mode when needed
|
||||
sessions.OnSettingsChanged(func(new types.Settings, old types.Settings) {
|
||||
sessions.OnSettingsChanged(func(session types.Session, new types.Settings, old types.Settings) {
|
||||
if old.PrivateMode && !new.PrivateMode {
|
||||
log.Debug().Msg("clearing private mode fallback image")
|
||||
h.privateModeImage = nil
|
||||
|
@ -1,8 +1,12 @@
|
||||
package room
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/demodesk/neko/pkg/auth"
|
||||
"github.com/demodesk/neko/pkg/types"
|
||||
"github.com/demodesk/neko/pkg/utils"
|
||||
)
|
||||
|
||||
@ -12,13 +16,23 @@ func (h *RoomHandler) settingsGet(w http.ResponseWriter, r *http.Request) error
|
||||
}
|
||||
|
||||
func (h *RoomHandler) settingsSet(w http.ResponseWriter, r *http.Request) error {
|
||||
settings := h.sessions.Settings()
|
||||
session, _ := auth.GetSession(r)
|
||||
|
||||
if err := utils.HttpJsonRequest(w, r, &settings); err != nil {
|
||||
return err
|
||||
// We read the request body first and unmashal it inside the UpdateSettingsFunc
|
||||
// to ensure atomicity of the operation.
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
return utils.HttpBadRequest("unable to read request body").WithInternalErr(err)
|
||||
}
|
||||
|
||||
h.sessions.UpdateSettings(settings)
|
||||
h.sessions.UpdateSettingsFunc(session, func(settings *types.Settings) bool {
|
||||
err = json.Unmarshal(body, settings)
|
||||
return err == nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return utils.HttpBadRequest("unable to parse provided data").WithInternalErr(err)
|
||||
}
|
||||
|
||||
return utils.HttpSuccess(w)
|
||||
}
|
||||
|
Reference in New Issue
Block a user