Backend update.

This commit is contained in:
Jesse Malotaux 2025-04-28 10:20:13 +02:00
parent f49630558d
commit 90bf6be882
9 changed files with 66 additions and 28 deletions

BIN
be/Macrame.exe Normal file

Binary file not shown.

BIN
be/Setup.exe Normal file

Binary file not shown.

View file

@ -24,24 +24,6 @@ func ApiCORS(w http.ResponseWriter, r *http.Request) (http.ResponseWriter, *http
} }
func ApiGet(w http.ResponseWriter, r *http.Request) { func ApiGet(w http.ResponseWriter, r *http.Request) {
// file := "" // base directory
// if strings.Contains(r.URL.Path, "/config.js") {
// file = "../public/config.js"
// } else if r.URL.Path != "/" {
// file = "../public" + r.URL.Path // request
// }
// MCRMLog("ApiGet Path: ", r.URL.Path, "; File: ", file)
// contentType := mime.TypeByExtension(filepath.Ext(file)) // get content type
// if contentType == "" {
// file = "../public/index.html" // default
// }
// MCRMLog("ApiGet File: ", file)
// http.ServeFile(w, r, file)
root, err := filepath.Abs("../public") root, err := filepath.Abs("../public")
if err != nil { if err != nil {
MCRMLog("ApiGet Abs Error: ", err) MCRMLog("ApiGet Abs Error: ", err)
@ -63,8 +45,6 @@ func ApiGet(w http.ResponseWriter, r *http.Request) {
file = filepath.Join(root, "index.html") file = filepath.Join(root, "index.html")
} }
// MCRMLog("ApiGet Path: ", r.URL.Path, "; File: ", file, "; Content-Type: ", contentType)
http.ServeFile(w, r, file) http.ServeFile(w, r, file)
} }
@ -86,6 +66,8 @@ func ApiPost(w http.ResponseWriter, r *http.Request) {
SaveMacro(w, r) SaveMacro(w, r)
case "/macro/list": case "/macro/list":
ListMacros(w, r) ListMacros(w, r)
case "/macro/open":
OpenMacro(w, r)
case "/macro/delete": case "/macro/delete":
DeleteMacro(w, r) DeleteMacro(w, r)
case "/macro/play": case "/macro/play":

View file

@ -18,12 +18,25 @@ func GetServerIP(w http.ResponseWriter, r *http.Request) {
ifs, err := net.Interfaces() ifs, err := net.Interfaces()
if err != nil { if err != nil {
MCRMLog(err) MCRMLog(err)
return
} }
for _, ifi := range ifs { for _, ifi := range ifs {
// Skip interfaces that are down
if ifi.Flags&net.FlagUp == 0 {
continue
}
// Skip loopback interfaces
if ifi.Flags&net.FlagLoopback != 0 {
continue
}
addrs, err := ifi.Addrs() addrs, err := ifi.Addrs()
if err != nil { if err != nil {
MCRMLog(err) MCRMLog(err)
continue
} }
for _, addr := range addrs { for _, addr := range addrs {
var ip net.IP var ip net.IP
@ -34,12 +47,20 @@ func GetServerIP(w http.ResponseWriter, r *http.Request) {
ip = v.IP ip = v.IP
} }
if ip != nil && ip.To4() != nil { if ip == nil || ip.To4() == nil {
continue
}
// Skip APIPA (169.254.x.x) addresses
if ip.IsLinkLocalUnicast() {
continue
}
// Found a good IP, return it
json.NewEncoder(w).Encode(ip.String()) json.NewEncoder(w).Encode(ip.String())
return return
} }
} }
}
} }
func DeviceList(w http.ResponseWriter, r *http.Request) { func DeviceList(w http.ResponseWriter, r *http.Request) {

View file

@ -1,6 +1,8 @@
package helper package helper
import "strings" import (
"strings"
)
func Translate(code string) string { func Translate(code string) string {
translations := map[string]string{ translations := map[string]string{
@ -44,6 +46,18 @@ func Translate(code string) string {
"NumpadDivide": "num/", "NumpadDivide": "num/",
"NumpadEnter": "num_enter", "NumpadEnter": "num_enter",
"Clear": "num_clear", "Clear": "num_clear",
"BracketLeft": "[",
"BracketRight": "]",
"Quote": "'",
"Semicolon": ";",
"Backquote": "`",
"Backslash": "\\",
"IntlBackslash": "\\",
"Slash": "/",
"Comma": ",",
"Period": ".",
"Equal": "=",
"Minus": "-",
} }
if translations[code] == "" { if translations[code] == "" {

View file

@ -128,3 +128,27 @@ func PlayMacro(data string, w http.ResponseWriter, r *http.Request) {
return return
} }
} }
func OpenMacro(w http.ResponseWriter, r *http.Request) {
var req structs.MacroRequest
err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
MCRMLog("OpenMacro Decode Error: ", err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
var filename = helper.FormatMacroFileName(req.Macro)
macroFile, err := helper.ReadMacroFile(fmt.Sprintf("../macros/%s.json", filename))
if err != nil {
MCRMLog("OpenMacro ReadMacroFile Error: ", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
json.NewEncoder(w).Encode(macroFile)
}

View file

@ -10,6 +10,7 @@ var Endpoints = Allowed{
Local: []string{ Local: []string{
"/macro/record", "/macro/record",
"/macro/list", "/macro/list",
"/macro/open",
"/macro/delete", "/macro/delete",
"/macro/play", "/macro/play",
"/device/server/ip", "/device/server/ip",

BIN
be/main.exe Normal file

Binary file not shown.

View file

@ -6,9 +6,5 @@ func main() {
helper.CreateConfigFile("../public/config.js") helper.CreateConfigFile("../public/config.js")
helper.CheckFeDevDir() helper.CheckFeDevDir()
port := helper.EnvGet("MCRM__PORT")
helper.MakeCaddyFile("CaddyFile", port)
return return
} }