mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 07:19:26 +00:00
Update to api: WIP device access
This commit is contained in:
parent
e9e6f9e798
commit
22f4fecce2
5 changed files with 46 additions and 5 deletions
|
|
@ -63,5 +63,12 @@ func ApiPost(w http.ResponseWriter, r *http.Request) {
|
||||||
PlayMacro(w, r)
|
PlayMacro(w, r)
|
||||||
case "/device/list":
|
case "/device/list":
|
||||||
DeviceList(w, r)
|
DeviceList(w, r)
|
||||||
|
case "/device/access/check":
|
||||||
|
DeviceAccessCheck(w, r)
|
||||||
|
case "/device/access/request":
|
||||||
|
DeviceAccessRequest(w, r)
|
||||||
|
case "/poll/remote":
|
||||||
|
PollRemote(w, r)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeviceList(w http.ResponseWriter, r *http.Request) {
|
func DeviceList(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -60,8 +61,34 @@ func readDeviceSettings(filepath string) (settings structs.Settings) {
|
||||||
return settings
|
return settings
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeviceAccess(w http.ResponseWriter, r *http.Request) bool {
|
var (
|
||||||
return true
|
mu sync.Mutex
|
||||||
|
queue = make(map[string][]structs.RemoteWebhook)
|
||||||
|
)
|
||||||
|
|
||||||
|
func PollRemote(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeviceAccessCheck(w http.ResponseWriter, r *http.Request) {
|
||||||
|
log.Println("device access check")
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeviceAccessRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req structs.RemoteWebhook
|
||||||
|
|
||||||
|
err := json.NewDecoder(r.Body).Decode(&req)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println(req)
|
||||||
|
// mu.Lock()
|
||||||
|
// queue[req.Device] = append(queue[req.Device], req)
|
||||||
|
// mu.Unlock()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeviceAuth(w http.ResponseWriter, r *http.Request) bool {
|
func DeviceAuth(w http.ResponseWriter, r *http.Request) bool {
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,13 @@ var Endpoints = Allowed{
|
||||||
"/macro/delete",
|
"/macro/delete",
|
||||||
"/macro/play",
|
"/macro/play",
|
||||||
"/device/list",
|
"/device/list",
|
||||||
|
"/device/access/check",
|
||||||
|
"/device/access/request",
|
||||||
},
|
},
|
||||||
Remote: []string{
|
Remote: []string{
|
||||||
"/macro/list",
|
"/macro/list",
|
||||||
"/device/access",
|
"/device/access/check",
|
||||||
|
"/device/access/request",
|
||||||
"/device/auth",
|
"/device/auth",
|
||||||
},
|
},
|
||||||
Auth: []string{
|
Auth: []string{
|
||||||
|
|
|
||||||
|
|
@ -4,3 +4,8 @@ type Settings struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RemoteWebhook struct {
|
||||||
|
Event string `json:"event"`
|
||||||
|
Data string `json:"data"`
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"be/app"
|
"be/app"
|
||||||
"be/app/helper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -21,7 +20,7 @@ func main() {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
helper.OpenBrowser("http://localhost:6970")
|
// helper.OpenBrowser("http://localhost:6970")
|
||||||
|
|
||||||
log.Fatal(http.ListenAndServe(":6970", nil))
|
log.Fatal(http.ListenAndServe(":6970", nil))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue