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)
|
||||
case "/device/list":
|
||||
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"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func DeviceList(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -60,8 +61,34 @@ func readDeviceSettings(filepath string) (settings structs.Settings) {
|
|||
return settings
|
||||
}
|
||||
|
||||
func DeviceAccess(w http.ResponseWriter, r *http.Request) bool {
|
||||
return true
|
||||
var (
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -13,10 +13,13 @@ var Endpoints = Allowed{
|
|||
"/macro/delete",
|
||||
"/macro/play",
|
||||
"/device/list",
|
||||
"/device/access/check",
|
||||
"/device/access/request",
|
||||
},
|
||||
Remote: []string{
|
||||
"/macro/list",
|
||||
"/device/access",
|
||||
"/device/access/check",
|
||||
"/device/access/request",
|
||||
"/device/auth",
|
||||
},
|
||||
Auth: []string{
|
||||
|
|
|
|||
|
|
@ -4,3 +4,8 @@ type Settings struct {
|
|||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type RemoteWebhook struct {
|
||||
Event string `json:"event"`
|
||||
Data string `json:"data"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"net/http"
|
||||
|
||||
"be/app"
|
||||
"be/app/helper"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
@ -21,7 +20,7 @@ func main() {
|
|||
|
||||
})
|
||||
|
||||
helper.OpenBrowser("http://localhost:6970")
|
||||
// helper.OpenBrowser("http://localhost:6970")
|
||||
|
||||
log.Fatal(http.ListenAndServe(":6970", nil))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue