mirror of
https://github.com/OpenFactorioServerManager/factorio-server-manager.git
synced 2025-02-03 13:21:25 +02:00
Added route for updating server-settings.json file
This commit is contained in:
parent
c4304e9b51
commit
17a9c7c8af
@ -931,7 +931,7 @@ func RemoveUser(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// Return JSON response of config.ini file
|
||||
// Return JSON response of server-settings.json file
|
||||
func GetServerSettings(w http.ResponseWriter, r *http.Request) {
|
||||
resp := JSONResponse{
|
||||
Success: false,
|
||||
@ -948,3 +948,33 @@ func GetServerSettings(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
log.Printf("Sent server settings response")
|
||||
}
|
||||
|
||||
func UpdateServerSettings(w http.ResponseWrite, r *http.Request) {
|
||||
resp := JSONResponse{
|
||||
Success: false,
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json;charset=UTF-8")
|
||||
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
log.Printf("GET not supported for add user handler")
|
||||
resp.Data = "Unsupported method"
|
||||
resp.Success = false
|
||||
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
||||
log.Printf("Error adding user: %s", err)
|
||||
}
|
||||
case "POST":
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
log.Printf("Error in reading server settings POST: %s", err)
|
||||
resp.Data = fmt.Sprintf("Error in updating settings: %s", err)
|
||||
resp.Success = false
|
||||
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
||||
log.Printf("Error updating settings: %s", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
log.Printf("Received settings JSON: %s", body)
|
||||
}
|
||||
}
|
||||
|
@ -225,5 +225,10 @@ var apiRoutes = Routes{
|
||||
"GET",
|
||||
"/settings",
|
||||
GetServerSettings,
|
||||
}, {
|
||||
"UpdateServerSettings",
|
||||
"POST",
|
||||
"/settings/update",
|
||||
UpdateServerSettings,
|
||||
},
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user