mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 07:19:26 +00:00
Backend refactor and additions
This commit is contained in:
parent
052ce611f9
commit
5de99b32cd
4 changed files with 37 additions and 3 deletions
|
|
@ -67,6 +67,8 @@ func ApiPost(w http.ResponseWriter, r *http.Request) {
|
|||
DeleteMacro(w, r)
|
||||
case "/macro/play":
|
||||
PlayMacro("", w, r)
|
||||
case "/device/server/ip":
|
||||
GetServerIP(w, r)
|
||||
case "/device/list":
|
||||
DeviceList(w, r)
|
||||
case "/device/access/check":
|
||||
|
|
@ -82,7 +84,6 @@ func ApiPost(w http.ResponseWriter, r *http.Request) {
|
|||
case "/device/link/remove":
|
||||
RemoveLink("", w, r)
|
||||
case "/device/handshake":
|
||||
log.Println("handshake")
|
||||
Handshake(w, r)
|
||||
case "/panel/list":
|
||||
PanelList(w, r)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -14,6 +15,34 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func GetServerIP(w http.ResponseWriter, r *http.Request) {
|
||||
ifs, err := net.Interfaces()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
for _, ifi := range ifs {
|
||||
addrs, err := ifi.Addrs()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
for _, addr := range addrs {
|
||||
var ip net.IP
|
||||
|
||||
switch v := addr.(type) {
|
||||
case *net.IPNet:
|
||||
ip = v.IP
|
||||
case *net.IPAddr:
|
||||
ip = v.IP
|
||||
}
|
||||
|
||||
if ip != nil && ip.To4() != nil {
|
||||
json.NewEncoder(w).Encode(ip.String())
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func DeviceList(w http.ResponseWriter, r *http.Request) {
|
||||
log.Println("device list")
|
||||
dir := "devices"
|
||||
|
|
@ -29,7 +58,7 @@ func DeviceList(w http.ResponseWriter, r *http.Request) {
|
|||
ext := filepath.Ext(filePath)
|
||||
device := strings.TrimSuffix(file.Name(), ext)
|
||||
|
||||
log.Println(device, ext)
|
||||
// log.Println(device, ext)
|
||||
|
||||
if _, ok := devices[device]; !ok {
|
||||
devices[device] = make(map[string]interface{})
|
||||
|
|
@ -47,6 +76,8 @@ func DeviceList(w http.ResponseWriter, r *http.Request) {
|
|||
"devices": devices,
|
||||
}
|
||||
|
||||
log.Println(result)
|
||||
|
||||
json.NewEncoder(w).Encode(result)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ var Endpoints = Allowed{
|
|||
"/macro/list",
|
||||
"/macro/delete",
|
||||
"/macro/play",
|
||||
"/device/server/ip",
|
||||
"/device/list",
|
||||
"/device/access/check",
|
||||
"/device/access/request",
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"be/app"
|
||||
"be/app/helper"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
@ -12,7 +13,7 @@ func main() {
|
|||
apiInit(w, r)
|
||||
})
|
||||
|
||||
log.Println(http.ListenAndServe(":6970", nil))
|
||||
log.Println(http.ListenAndServe(":"+helper.EnvGet("MCRM__PORT"), nil))
|
||||
}
|
||||
|
||||
func apiInit(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue