chore (refactoring): migrate config handlers

This commit is contained in:
MickaelK
2026-08-20 16:13:09 +10:00
parent cd102dae1e
commit d4198d732c
3 changed files with 28 additions and 18 deletions
+3
View File
@@ -42,6 +42,8 @@ var (
FetchLogHandler = admin.FetchLogHandler
AdminBackend = admin.AdminBackend
AdminAuthenticationMiddleware = admin.AdminAuthenticationMiddleware
PrivateConfigHandler = admin.PrivateConfigHandler
PrivateConfigUpdateHandler = admin.PrivateConfigUpdateHandler
)
// session
@@ -83,4 +85,5 @@ var (
ReportHandler = frontend.ReportHandler
WellKnownSecurityHandler = frontend.WellKnownSecurityHandler
HealthHandler = frontend.HealthHandler
PublicConfigHandler = frontend.PublicConfigHandler
)
+24
View File
@@ -0,0 +1,24 @@
package admin
import (
"io"
"net/http"
. "github.com/mickael-kerjean/filestash/server/pkg/config"
. "github.com/mickael-kerjean/filestash/server/pkg/core"
. "github.com/mickael-kerjean/filestash/server/pkg/kernel"
)
func PrivateConfigHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
SendSuccessResult(res, &Config)
}
func PrivateConfigUpdateHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
b, _ := io.ReadAll(req.Body)
if err := SaveConfig(b); err != nil {
SendErrorResult(res, err)
return
}
Config.Load()
SendSuccessResult(res, nil)
}
@@ -1,29 +1,12 @@
package ctrl
package frontend
import (
"io"
"net/http"
"regexp"
. "github.com/mickael-kerjean/filestash/server/common"
)
var configpath = GetAbsolutePath(CONFIG_PATH, "config.json")
func PrivateConfigHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
SendSuccessResult(res, &Config)
}
func PrivateConfigUpdateHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
b, _ := io.ReadAll(req.Body)
if err := SaveConfig(b); err != nil {
SendErrorResult(res, err)
return
}
Config.Load()
SendSuccessResult(res, nil)
}
func PublicConfigHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
SendSuccessResultWithEtagAndGzip(res, req, struct {
Editor string `json:"editor"`