mirror of
https://github.com/knadh/listmonk.git
synced 2025-12-05 16:00:03 +01:00
- Add a new vacuum setting option on the UI in Admin -> Settings -> Maintenance. - Also refactor frontend (lock-and-wait-for-restart) login on settings into the global vue instance so that it can be reused across contexts. Settings.vue and Maintenance.vue both now use it to wait for the backend to restart.
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package core
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/jmoiron/sqlx/types"
|
|
"github.com/knadh/listmonk/models"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
// GetSettings returns settings from the DB.
|
|
func (c *Core) GetSettings() (models.Settings, error) {
|
|
var (
|
|
b types.JSONText
|
|
out models.Settings
|
|
)
|
|
|
|
if err := c.q.GetSettings.Get(&b); err != nil {
|
|
return out, echo.NewHTTPError(http.StatusInternalServerError,
|
|
c.i18n.Ts("globals.messages.errorFetching",
|
|
"name", "{globals.terms.settings}", "error", pqErrMsg(err)))
|
|
}
|
|
|
|
// Unmarshal the settings and filter out sensitive fields.
|
|
if err := json.Unmarshal([]byte(b), &out); err != nil {
|
|
return out, echo.NewHTTPError(http.StatusInternalServerError,
|
|
c.i18n.Ts("settings.errorEncoding", "error", err.Error()))
|
|
}
|
|
|
|
return out, nil
|
|
}
|
|
|
|
// UpdateSettings updates settings.
|
|
func (c *Core) UpdateSettings(s models.Settings) error {
|
|
// Marshal settings.
|
|
b, err := json.Marshal(s)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusInternalServerError,
|
|
c.i18n.Ts("settings.errorEncoding", "error", err.Error()))
|
|
}
|
|
|
|
// Update the settings in the DB.
|
|
if _, err := c.q.UpdateSettings.Exec(b); err != nil {
|
|
return echo.NewHTTPError(http.StatusInternalServerError,
|
|
c.i18n.Ts("globals.messages.errorUpdating", "name", "{globals.terms.settings}", "error", pqErrMsg(err)))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UpdateSettingsByKey updates a single setting by key.
|
|
func (c *Core) UpdateSettingsByKey(key string, value json.RawMessage) error {
|
|
if _, err := c.q.UpdateSettingsByKey.Exec(key, value); err != nil {
|
|
return echo.NewHTTPError(http.StatusInternalServerError,
|
|
c.i18n.Ts("globals.messages.errorUpdating", "name", "{globals.terms.settings}", "error", pqErrMsg(err)))
|
|
}
|
|
|
|
return nil
|
|
}
|