mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 15:29:26 +00:00
Check Macro endpoint added.
This commit is contained in:
parent
97af604cb6
commit
9218f53c5d
2 changed files with 28 additions and 4 deletions
|
|
@ -62,6 +62,8 @@ func ApiPost(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
switch r.URL.Path {
|
||||
case "/macro/check":
|
||||
CheckMacro(w, r)
|
||||
case "/macro/record":
|
||||
SaveMacro(w, r)
|
||||
case "/macro/list":
|
||||
|
|
|
|||
|
|
@ -13,6 +13,30 @@ import (
|
|||
"be/app/structs"
|
||||
)
|
||||
|
||||
func CheckMacro(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 macroFile != nil && err == nil {
|
||||
json.NewEncoder(w).Encode(true)
|
||||
return
|
||||
} else {
|
||||
MCRMLog("OpenMacro ReadMacroFile Error: ", err)
|
||||
json.NewEncoder(w).Encode(false)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func SaveMacro(w http.ResponseWriter, r *http.Request) {
|
||||
var newMacro structs.NewMacro
|
||||
|
||||
|
|
@ -57,7 +81,7 @@ func simplifyMacro(step structs.Step) map[string]interface{} {
|
|||
case "key":
|
||||
keyCode := step.Code
|
||||
|
||||
if keyCode == "" {
|
||||
if keyCode == "" || (strings.Contains(keyCode, "Digit")) {
|
||||
keyCode = step.Key
|
||||
} else if strings.Contains(keyCode, "Key") {
|
||||
keyCode = strings.Replace(keyCode, "Key", "", 1)
|
||||
|
|
@ -140,9 +164,7 @@ func OpenMacro(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
var filename = helper.FormatMacroFileName(req.Macro)
|
||||
|
||||
macroFile, err := helper.ReadMacroFile(fmt.Sprintf("../macros/%s.json", filename))
|
||||
macroFile, err := helper.ReadMacroFile(fmt.Sprintf("../macros/%s.json", req.Macro))
|
||||
|
||||
if err != nil {
|
||||
MCRMLog("OpenMacro ReadMacroFile Error: ", err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue