public: can control up to 9 separate displays
This commit is contained in:
parent
baf992bccb
commit
bc9d27aa94
7 changed files with 31 additions and 19 deletions
|
@ -2,6 +2,7 @@ package api
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
|
@ -11,9 +12,9 @@ import (
|
|||
var TeamsDir string
|
||||
|
||||
func init() {
|
||||
router.GET("/api/public.json", apiHandler(getPublic))
|
||||
router.DELETE("/api/public.json", apiHandler(deletePublic))
|
||||
router.PUT("/api/public.json", apiHandler(savePublic))
|
||||
router.GET("/api/public/:sid", apiHandler(getPublic))
|
||||
router.DELETE("/api/public/:sid", apiHandler(deletePublic))
|
||||
router.PUT("/api/public/:sid", apiHandler(savePublic))
|
||||
}
|
||||
|
||||
type FICPublicScene struct {
|
||||
|
@ -52,23 +53,23 @@ func savePublicTo(path string, s []FICPublicScene) error {
|
|||
}
|
||||
}
|
||||
|
||||
func getPublic(_ httprouter.Params, body []byte) (interface{}, error) {
|
||||
if _, err := os.Stat(path.Join(TeamsDir, "_public", "public.json")); !os.IsNotExist(err) {
|
||||
return readPublic(path.Join(TeamsDir, "_public", "public.json"))
|
||||
func getPublic(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if _, err := os.Stat(path.Join(TeamsDir, "_public", fmt.Sprintf("public%s.json", ps.ByName("sid")))); !os.IsNotExist(err) {
|
||||
return readPublic(path.Join(TeamsDir, "_public", fmt.Sprintf("public%s.json", ps.ByName("sid"))))
|
||||
} else {
|
||||
return []FICPublicScene{}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func deletePublic(_ httprouter.Params, body []byte) (interface{}, error) {
|
||||
if err := savePublicTo(path.Join(TeamsDir, "_public", "public.json"), []FICPublicScene{}); err != nil {
|
||||
func deletePublic(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if err := savePublicTo(path.Join(TeamsDir, "_public", fmt.Sprintf("public%s.json", ps.ByName("sid"))), []FICPublicScene{}); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return []FICPublicScene{}, err
|
||||
}
|
||||
}
|
||||
|
||||
func savePublic(_ httprouter.Params, body []byte) (interface{}, error) {
|
||||
func savePublic(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
var scenes []FICPublicScene
|
||||
if err := json.Unmarshal(body, &scenes); err != nil {
|
||||
return nil, err
|
||||
|
@ -80,7 +81,7 @@ func savePublic(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if err := savePublicTo(path.Join(TeamsDir, "_public", "public.json"), scenes); err != nil {
|
||||
if err := savePublicTo(path.Join(TeamsDir, "_public", fmt.Sprintf("public%s.json", ps.ByName("sid"))), scenes); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return scenes, err
|
||||
|
|
Reference in a new issue