mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 15:29:26 +00:00
Logging update
This commit is contained in:
parent
541f016eaf
commit
2098aface9
13 changed files with 119 additions and 91 deletions
|
|
@ -2,7 +2,6 @@ package app
|
|||
|
||||
import (
|
||||
"be/app/helper"
|
||||
"log"
|
||||
"mime"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
|
|
@ -40,19 +39,19 @@ func ApiGet(w http.ResponseWriter, r *http.Request) {
|
|||
file = "../public/index.html" // default
|
||||
}
|
||||
|
||||
// log.Println("GET:", file)
|
||||
// app.MCRMLog("GET:", file)
|
||||
|
||||
http.ServeFile(w, r, file) // serve file
|
||||
}
|
||||
|
||||
func ApiPost(w http.ResponseWriter, r *http.Request) {
|
||||
access, data := helper.EndpointAccess(w, r)
|
||||
access, data, err := helper.EndpointAccess(w, r)
|
||||
|
||||
if !access {
|
||||
if !access || err != nil {
|
||||
MCRMLog("ApiPost EndPointAccess Error: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("api post", data == "")
|
||||
if data != "" {
|
||||
ApiAuth(data, w, r)
|
||||
return
|
||||
|
|
@ -95,7 +94,6 @@ func ApiPost(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func ApiAuth(data string, w http.ResponseWriter, r *http.Request) {
|
||||
log.Println("apiauth", data != "")
|
||||
switch r.URL.Path {
|
||||
case "/macro/play":
|
||||
PlayMacro(data, w, r)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"be/app/structs"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
|
|
@ -18,12 +17,12 @@ import (
|
|||
func GetServerIP(w http.ResponseWriter, r *http.Request) {
|
||||
ifs, err := net.Interfaces()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
MCRMLog(err)
|
||||
}
|
||||
for _, ifi := range ifs {
|
||||
addrs, err := ifi.Addrs()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
MCRMLog(err)
|
||||
}
|
||||
for _, addr := range addrs {
|
||||
var ip net.IP
|
||||
|
|
@ -44,11 +43,10 @@ func GetServerIP(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func DeviceList(w http.ResponseWriter, r *http.Request) {
|
||||
log.Println("device list")
|
||||
dir := "devices"
|
||||
files, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
MCRMLog("DeviceList Error: ", err)
|
||||
}
|
||||
|
||||
devices := make(map[string]map[string]interface{})
|
||||
|
|
@ -58,8 +56,6 @@ func DeviceList(w http.ResponseWriter, r *http.Request) {
|
|||
ext := filepath.Ext(filePath)
|
||||
device := strings.TrimSuffix(file.Name(), ext)
|
||||
|
||||
// log.Println(device, ext)
|
||||
|
||||
if _, ok := devices[device]; !ok {
|
||||
devices[device] = make(map[string]interface{})
|
||||
}
|
||||
|
|
@ -76,32 +72,30 @@ func DeviceList(w http.ResponseWriter, r *http.Request) {
|
|||
"devices": devices,
|
||||
}
|
||||
|
||||
log.Println(result)
|
||||
|
||||
json.NewEncoder(w).Encode(result)
|
||||
}
|
||||
|
||||
func readDeviceSettings(filepath string) (settings structs.Settings) {
|
||||
data, err := os.ReadFile(filepath)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
MCRMLog("readDeviceSettings Error: ", err)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(data, &settings)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
MCRMLog("readDeviceSettings JSON Error: ", err)
|
||||
}
|
||||
log.Println(settings)
|
||||
|
||||
return settings
|
||||
}
|
||||
|
||||
func DeviceAccessCheck(w http.ResponseWriter, r *http.Request) {
|
||||
log.Println("device access check")
|
||||
var req structs.Check
|
||||
|
||||
err := json.NewDecoder(r.Body).Decode(&req)
|
||||
|
||||
if err != nil {
|
||||
MCRMLog("DeviceAccessCheck Error: ", err)
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
|
@ -110,13 +104,12 @@ func DeviceAccessCheck(w http.ResponseWriter, r *http.Request) {
|
|||
_, errKey := os.Stat("devices/" + req.Uuid + ".key")
|
||||
|
||||
if (errSett == nil) && (errKey == nil) {
|
||||
log.Println("authorized")
|
||||
json.NewEncoder(w).Encode("authorized")
|
||||
} else if (errSett == nil) && (errKey != nil) {
|
||||
log.Println("unauthorized")
|
||||
MCRMLog("DeviceAccessCheck: UUID: ", req.Uuid, "; Access: Unauthorized")
|
||||
json.NewEncoder(w).Encode("unauthorized")
|
||||
} else {
|
||||
log.Println("unauthorized")
|
||||
MCRMLog("DeviceAccessCheck: UUID: ", req.Uuid, "; Access: Unlinked")
|
||||
json.NewEncoder(w).Encode("unlinked")
|
||||
}
|
||||
|
||||
|
|
@ -137,14 +130,14 @@ func DeviceAccessRequest(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
settingsJSON, err := json.Marshal(deviceSettings)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
MCRMLog("DeviceAccessRequest JSON Error: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = os.WriteFile("devices/"+req.Uuid+".json", settingsJSON, 0644)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
MCRMLog("DeviceAccessRequest Error: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -152,11 +145,11 @@ func DeviceAccessRequest(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func PingLink(w http.ResponseWriter, r *http.Request) {
|
||||
log.Println("ping link")
|
||||
var req structs.Check
|
||||
err := json.NewDecoder(r.Body).Decode(&req)
|
||||
|
||||
if err != nil {
|
||||
MCRMLog("PingLink Error: ", err)
|
||||
json.NewEncoder(w).Encode(false)
|
||||
return
|
||||
}
|
||||
|
|
@ -166,24 +159,24 @@ func PingLink(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
encryptedKey, encErr := helper.EncryptAES(string(pin), string(key))
|
||||
|
||||
log.Println(encryptedKey, string(pin), string(key))
|
||||
|
||||
if keyErr == nil && pinErr == nil && encErr == nil {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write([]byte(encryptedKey))
|
||||
return
|
||||
} else {
|
||||
MCRMLog("PingLink Error: keyErr:", keyErr, "; pinErr:", pinErr, "; encErr:", encErr)
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(false)
|
||||
}
|
||||
|
||||
func StartLink(w http.ResponseWriter, r *http.Request) {
|
||||
log.Println("start link")
|
||||
var req structs.Check
|
||||
|
||||
err := json.NewDecoder(r.Body).Decode(&req)
|
||||
|
||||
if err != nil {
|
||||
MCRMLog("StartLink Error: ", err)
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
|
@ -192,10 +185,13 @@ func StartLink(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
deviceKey := helper.GenerateKey()
|
||||
|
||||
err = helper.SaveDeviceKey(req.Uuid, deviceKey)
|
||||
errKey := helper.SaveDeviceKey(req.Uuid, deviceKey)
|
||||
savedPin, errPin := helper.TempPinFile(req.Uuid, pin)
|
||||
|
||||
if err == nil && helper.TempPinFile(req.Uuid, pin) {
|
||||
if errKey == nil && errPin == nil && savedPin == true {
|
||||
json.NewEncoder(w).Encode(pin)
|
||||
} else {
|
||||
MCRMLog("StartLink Error: errKey:", err, "; errPin:", err)
|
||||
}
|
||||
|
||||
return
|
||||
|
|
@ -224,6 +220,7 @@ func RemoveLink(data string, w http.ResponseWriter, r *http.Request) {
|
|||
_, err := helper.ParseRequest(req, data, r)
|
||||
|
||||
if err != nil {
|
||||
MCRMLog("RemoveLink ParseRequest Error: ", err)
|
||||
json.NewEncoder(w).Encode(false)
|
||||
return
|
||||
}
|
||||
|
|
@ -231,6 +228,7 @@ func RemoveLink(data string, w http.ResponseWriter, r *http.Request) {
|
|||
err = os.Remove("devices/" + req.Uuid + ".key")
|
||||
|
||||
if err != nil {
|
||||
MCRMLog("RemoveLink Remove Error: ", err)
|
||||
json.NewEncoder(w).Encode(false)
|
||||
return
|
||||
}
|
||||
|
|
@ -250,6 +248,7 @@ func Handshake(w http.ResponseWriter, r *http.Request) {
|
|||
deviceKey, err := helper.GetKeyByUuid(req.Uuid)
|
||||
|
||||
if err != nil {
|
||||
MCRMLog("Handshake GetKeyByUuid Error: ", err)
|
||||
json.NewEncoder(w).Encode(false)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package helper
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
|
@ -11,27 +11,27 @@ import (
|
|||
. "be/app/structs"
|
||||
)
|
||||
|
||||
func EndpointAccess(w http.ResponseWriter, r *http.Request) (bool, string) {
|
||||
func EndpointAccess(w http.ResponseWriter, r *http.Request) (bool, string, error) {
|
||||
ip, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return false, "", errors.New(r.URL.Path + ": SplitHostPort error: " + err.Error())
|
||||
}
|
||||
|
||||
if (isLocal(ip) && isEndpointAllowed("Local", r.URL.Path)) ||
|
||||
(isLanRemote(ip) && isEndpointAllowed("Remote", r.URL.Path)) {
|
||||
log.Println(r.URL.Path, "endpoint access: accessible")
|
||||
return true, ""
|
||||
return true, "", nil
|
||||
} else if isLanRemote(ip) && isEndpointAllowed("Auth", r.URL.Path) {
|
||||
log.Println(r.URL.Path, "endpoint access: authorized")
|
||||
data, err := decryptAuth(r)
|
||||
|
||||
data := decryptAuth(r)
|
||||
if err != nil {
|
||||
return false, "", err
|
||||
}
|
||||
|
||||
return data != "", data
|
||||
return data != "", data, nil
|
||||
}
|
||||
|
||||
log.Println(r.URL.Path, "endpoint access: not authorized or accessible")
|
||||
|
||||
return false, ""
|
||||
return false, "", errors.New(r.URL.Path + ": not authorized or accessible")
|
||||
}
|
||||
|
||||
func isLocal(ip string) bool {
|
||||
|
|
@ -45,7 +45,7 @@ func isLanRemote(ip string) bool {
|
|||
func isEndpointAllowed(source string, endpoint string) bool {
|
||||
var endpoints, err = getAllowedEndpoints(source)
|
||||
if err != "" {
|
||||
log.Println(err)
|
||||
return false
|
||||
}
|
||||
|
||||
if (endpoints != nil) && (len(endpoints) > 0) {
|
||||
|
|
@ -73,25 +73,23 @@ func getAllowedEndpoints(source string) (endpoints []string, err string) {
|
|||
return []string{}, "No allowed endpoints"
|
||||
}
|
||||
|
||||
func decryptAuth(r *http.Request) string {
|
||||
func decryptAuth(r *http.Request) (string, error) {
|
||||
var req structs.Authcall
|
||||
|
||||
err := json.NewDecoder(r.Body).Decode(&req)
|
||||
|
||||
if err != nil || req.Uuid == "" || req.Data == "" {
|
||||
return ""
|
||||
return "", errors.New("DecryptAuth Error: " + err.Error() + "; UUID: " + req.Uuid + "; Data: " + req.Data)
|
||||
}
|
||||
|
||||
log.Println("data", req.Data)
|
||||
|
||||
deviceKey, errKey := GetKeyByUuid(req.Uuid)
|
||||
decryptData, errDec := DecryptAES(deviceKey, req.Data)
|
||||
|
||||
if errKey != nil && errDec != nil || decryptData == "" {
|
||||
return ""
|
||||
return "", errors.New("DecryptAuth Error: " + errKey.Error() + "; " + errDec.Error() + "; UUID: " + req.Uuid + "; Data: " + req.Data)
|
||||
}
|
||||
|
||||
return decryptData
|
||||
return decryptData, nil
|
||||
}
|
||||
|
||||
func ParseRequest(req interface{}, data string, r *http.Request) (d interface{}, err error) {
|
||||
|
|
|
|||
|
|
@ -1,25 +1,22 @@
|
|||
package helper
|
||||
|
||||
import (
|
||||
"log"
|
||||
"errors"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TempPinFile(Uuid string, pin string) bool {
|
||||
log.Println("temp pin file", Uuid, pin)
|
||||
func TempPinFile(Uuid string, pin string) (bool, error) {
|
||||
err := os.WriteFile("devices/"+Uuid+".tmp", []byte(pin), 0644)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return false
|
||||
return false, errors.New("TempPinFile Error: " + err.Error())
|
||||
}
|
||||
|
||||
time.AfterFunc(1*time.Minute, func() {
|
||||
log.Println("deleting", Uuid, pin)
|
||||
os.Remove("devices/" + Uuid + ".tmp")
|
||||
})
|
||||
|
||||
return true
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func CheckPinFile(Uuid string) bool {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package helper
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
|
|
@ -10,7 +9,7 @@ import (
|
|||
func EnvGet(key string) string {
|
||||
err := godotenv.Load("../.env")
|
||||
if err != nil {
|
||||
log.Fatal("Error loading .env file")
|
||||
return ""
|
||||
}
|
||||
return os.Getenv("VITE_" + key)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package helper
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"errors"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
|
@ -34,12 +34,10 @@ func FormatMacroFileName(s string) string {
|
|||
}
|
||||
|
||||
func ReadMacroFile(filename string) (steps []structs.Step, err error) {
|
||||
log.Println(filename)
|
||||
|
||||
content, err := os.ReadFile(filename)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal("Error when opening file: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(content, &steps)
|
||||
|
|
@ -47,18 +45,19 @@ func ReadMacroFile(filename string) (steps []structs.Step, err error) {
|
|||
return steps, err
|
||||
}
|
||||
|
||||
func RunMacroSteps(steps []structs.Step) {
|
||||
func RunMacroSteps(steps []structs.Step) error {
|
||||
for _, step := range steps {
|
||||
// log.Println(step)
|
||||
switch step.Type {
|
||||
case "key":
|
||||
robotgo.KeyToggle(step.Key, step.Direction)
|
||||
// log.Println("Toggling", step.Key, "to", step.Direction)
|
||||
err := robotgo.KeyToggle(step.Key, step.Direction)
|
||||
if err != nil {
|
||||
return errors.New("RunMacroSteps KeyToggle Error: " + err.Error())
|
||||
}
|
||||
case "delay":
|
||||
time.Sleep(time.Duration(step.Location) * time.Millisecond)
|
||||
// log.Println("Sleeping for", step.Value, "milliseconds")
|
||||
default:
|
||||
log.Println("Unknown step type:", step.Type)
|
||||
return errors.New("RunMacroSteps Unknown step type:" + step.Type)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
22
be/app/log.go
Normal file
22
be/app/log.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
var logFile *os.File
|
||||
|
||||
func MCRMLogInit() {
|
||||
var err error
|
||||
logFile, err = os.OpenFile("log.txt", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func MCRMLog(v ...interface{}) {
|
||||
log.Println(v...)
|
||||
fmt.Fprintln(logFile, v...)
|
||||
}
|
||||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -19,33 +18,35 @@ func SaveMacro(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
MCRMLog("SaveMacro ReadAll Error: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Println(string(body))
|
||||
|
||||
err = json.Unmarshal(body, &newMacro)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
MCRMLog("SaveMacro Unmarshal Error: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
stepsJSON, err := json.Marshal(newMacro.Steps)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
MCRMLog("SaveMacro Marshal Error: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = os.WriteFile("../macros/"+helper.FormatMacroFileName(newMacro.Name)+".json", stepsJSON, 0644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
MCRMLog("SaveMacro WriteFile Error: ", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func ListMacros(w http.ResponseWriter, r *http.Request) {
|
||||
log.Println("listing macros")
|
||||
dir := "../macros"
|
||||
files, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
MCRMLog("ListMacros ReadDir Error: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
var macroList []structs.MacroInfo
|
||||
|
|
@ -55,7 +56,6 @@ func ListMacros(w http.ResponseWriter, r *http.Request) {
|
|||
macroname := strings.TrimSuffix(filename, filepath.Ext(filename))
|
||||
nicename := strings.Replace(macroname, "_", " ", -1)
|
||||
|
||||
log.Println(macroname, nicename)
|
||||
macroList = append(macroList, structs.MacroInfo{
|
||||
Name: nicename,
|
||||
Macroname: macroname,
|
||||
|
|
@ -72,6 +72,7 @@ func PlayMacro(data string, w http.ResponseWriter, r *http.Request) {
|
|||
_, err := helper.ParseRequest(req, data, r)
|
||||
|
||||
if err != nil {
|
||||
MCRMLog("PlayMacro ParseRequest Error: ", err)
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
|
@ -83,10 +84,15 @@ func PlayMacro(data string, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
macroFile, err := helper.ReadMacroFile(filepath)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
MCRMLog("PlayMacro ReadMacroFile Error: ", err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
helper.RunMacroSteps(macroFile)
|
||||
err = helper.RunMacroSteps(macroFile)
|
||||
|
||||
if err != nil {
|
||||
MCRMLog("PlayMacro RunMacroSteps Error: ", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"be/app/structs"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
|
@ -14,6 +13,7 @@ import (
|
|||
func PanelList(w http.ResponseWriter, r *http.Request) {
|
||||
panelDirs, err := os.ReadDir("../panels")
|
||||
if err != nil {
|
||||
MCRMLog("PanelList ReadDir Error: ", err)
|
||||
json.NewEncoder(w).Encode(false)
|
||||
return
|
||||
}
|
||||
|
|
@ -22,12 +22,12 @@ func PanelList(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
for _, panelDir := range panelDirs {
|
||||
if panelDir.IsDir() {
|
||||
// log.Println(getPanelInfo(panelDir.Name()))
|
||||
panelList = append(panelList, getPanelInfo(panelDir.Name()))
|
||||
}
|
||||
}
|
||||
|
||||
if len(panelList) == 0 {
|
||||
MCRMLog("PanelList: No panels found")
|
||||
json.NewEncoder(w).Encode(false)
|
||||
return
|
||||
}
|
||||
|
|
@ -48,7 +48,7 @@ func getPanelInfo(dirname string) structs.PanelInfo {
|
|||
} else {
|
||||
err = json.Unmarshal(jsonFile, &panelInfo)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
MCRMLog("getPanelInfo Unmarshal Error: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -67,6 +67,7 @@ func getPanelThumb(dirname string) string {
|
|||
filename := "thumbnail" + ext
|
||||
file, err := os.Open("../panels/" + dirname + "/" + filename)
|
||||
if err != nil {
|
||||
MCRMLog("getPanelThumb Open Error: ", err)
|
||||
continue
|
||||
}
|
||||
defer file.Close()
|
||||
|
|
@ -87,6 +88,7 @@ func getPanelCode(dirname string) (html string, css string) {
|
|||
func encodeImg(file *os.File) string {
|
||||
contents, err := os.ReadFile(file.Name())
|
||||
if err != nil {
|
||||
MCRMLog("encodeImg ReadFile Error: ", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
|
|
@ -99,12 +101,13 @@ func GetPanel(data string, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
_, err := helper.ParseRequest(req, data, r)
|
||||
if err != nil {
|
||||
MCRMLog("GetPanel ParseRequest Error: ", err)
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
var response = structs.PanelResponse{}
|
||||
// dirname := req.Dir
|
||||
|
||||
panelInfo := getPanelInfo(req.Dir)
|
||||
panelHtml, panelCss := getPanelCode(req.Dir)
|
||||
|
||||
|
|
@ -124,6 +127,7 @@ func SavePanelJSON(w http.ResponseWriter, r *http.Request) {
|
|||
var req structs.PanelSaveJSON
|
||||
err := json.NewDecoder(r.Body).Decode(&req)
|
||||
if err != nil {
|
||||
MCRMLog("SavePanelJSON Decode Error: ", err)
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
|
@ -135,12 +139,14 @@ func SavePanelJSON(w http.ResponseWriter, r *http.Request) {
|
|||
// Marshal the data to JSON without the dir field
|
||||
jsonData, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
MCRMLog("SavePanelJSON Marshal Error: ", err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
err = os.WriteFile(filePath, jsonData, 0644)
|
||||
if err != nil {
|
||||
MCRMLog("SavePanelJSON WriteFile Error: ", err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue