diff --git a/be/Macrame.exe b/be/Macrame.exe new file mode 100644 index 0000000..41a40aa Binary files /dev/null and b/be/Macrame.exe differ diff --git a/be/Setup.exe b/be/Setup.exe new file mode 100644 index 0000000..94d791f Binary files /dev/null and b/be/Setup.exe differ diff --git a/be/app/api.go b/be/app/api.go index 0f169ef..a189c31 100644 --- a/be/app/api.go +++ b/be/app/api.go @@ -24,24 +24,6 @@ func ApiCORS(w http.ResponseWriter, r *http.Request) (http.ResponseWriter, *http } 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") if err != nil { MCRMLog("ApiGet Abs Error: ", err) @@ -63,8 +45,6 @@ func ApiGet(w http.ResponseWriter, r *http.Request) { file = filepath.Join(root, "index.html") } - // MCRMLog("ApiGet Path: ", r.URL.Path, "; File: ", file, "; Content-Type: ", contentType) - http.ServeFile(w, r, file) } @@ -86,6 +66,8 @@ func ApiPost(w http.ResponseWriter, r *http.Request) { SaveMacro(w, r) case "/macro/list": ListMacros(w, r) + case "/macro/open": + OpenMacro(w, r) case "/macro/delete": DeleteMacro(w, r) case "/macro/play": diff --git a/be/app/device.go b/be/app/device.go index 4ad7ed3..d0c169e 100644 --- a/be/app/device.go +++ b/be/app/device.go @@ -18,12 +18,25 @@ func GetServerIP(w http.ResponseWriter, r *http.Request) { ifs, err := net.Interfaces() if err != nil { MCRMLog(err) + return } + 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() if err != nil { MCRMLog(err) + continue } + for _, addr := range addrs { var ip net.IP @@ -34,10 +47,18 @@ func GetServerIP(w http.ResponseWriter, r *http.Request) { ip = v.IP } - if ip != nil && ip.To4() != nil { - json.NewEncoder(w).Encode(ip.String()) - return + 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()) + return } } } diff --git a/be/app/helper/translation-helper.go b/be/app/helper/translation-helper.go index 4cbf5ea..ccb5515 100644 --- a/be/app/helper/translation-helper.go +++ b/be/app/helper/translation-helper.go @@ -1,6 +1,8 @@ package helper -import "strings" +import ( + "strings" +) func Translate(code string) string { translations := map[string]string{ @@ -44,6 +46,18 @@ func Translate(code string) string { "NumpadDivide": "num/", "NumpadEnter": "num_enter", "Clear": "num_clear", + "BracketLeft": "[", + "BracketRight": "]", + "Quote": "'", + "Semicolon": ";", + "Backquote": "`", + "Backslash": "\\", + "IntlBackslash": "\\", + "Slash": "/", + "Comma": ",", + "Period": ".", + "Equal": "=", + "Minus": "-", } if translations[code] == "" { diff --git a/be/app/macro.go b/be/app/macro.go index c5dbaef..6709dea 100644 --- a/be/app/macro.go +++ b/be/app/macro.go @@ -128,3 +128,27 @@ func PlayMacro(data string, w http.ResponseWriter, r *http.Request) { 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) +} diff --git a/be/app/structs/api-struct.go b/be/app/structs/api-struct.go index f3be4d1..208845e 100644 --- a/be/app/structs/api-struct.go +++ b/be/app/structs/api-struct.go @@ -10,6 +10,7 @@ var Endpoints = Allowed{ Local: []string{ "/macro/record", "/macro/list", + "/macro/open", "/macro/delete", "/macro/play", "/device/server/ip", diff --git a/be/main.exe b/be/main.exe new file mode 100644 index 0000000..d0d3fe6 Binary files /dev/null and b/be/main.exe differ diff --git a/be/setup/setup.go b/be/setup/setup.go index 192ea35..f6938b2 100644 --- a/be/setup/setup.go +++ b/be/setup/setup.go @@ -6,9 +6,5 @@ func main() { helper.CreateConfigFile("../public/config.js") helper.CheckFeDevDir() - port := helper.EnvGet("MCRM__PORT") - - helper.MakeCaddyFile("CaddyFile", port) - return }