mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2026-10-19 16:14:39 +00:00
chore (refactoring): migrate config handlers
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
@@ -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"`
|
||||
Reference in New Issue
Block a user