dashboard: move public.json files into a dedicated directory
This commit is contained in:
parent
485ffafc9a
commit
7970b552e9
5 changed files with 25 additions and 22 deletions
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
var TeamsDir string
|
||||
var DashboardDir string
|
||||
|
||||
func init() {
|
||||
router.GET("/api/public/:sid", apiHandler(getPublic))
|
||||
|
@ -54,15 +54,15 @@ func savePublicTo(path string, s []FICPublicScene) error {
|
|||
}
|
||||
|
||||
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"))))
|
||||
if _, err := os.Stat(path.Join(DashboardDir, fmt.Sprintf("public%s.json", ps.ByName("sid")))); !os.IsNotExist(err) {
|
||||
return readPublic(path.Join(DashboardDir, fmt.Sprintf("public%s.json", ps.ByName("sid"))))
|
||||
} else {
|
||||
return []FICPublicScene{}, 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 {
|
||||
if err := savePublicTo(path.Join(DashboardDir, fmt.Sprintf("public%s.json", ps.ByName("sid"))), []FICPublicScene{}); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return []FICPublicScene{}, err
|
||||
|
@ -75,13 +75,7 @@ func savePublic(ps httprouter.Params, body []byte) (interface{}, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := os.Stat(path.Join(TeamsDir, "public")); os.IsNotExist(err) {
|
||||
if err := os.Mkdir(path.Join(TeamsDir, "public"), 0750); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if err := savePublicTo(path.Join(TeamsDir, "public", fmt.Sprintf("public%s.json", ps.ByName("sid"))), scenes); err != nil {
|
||||
if err := savePublicTo(path.Join(DashboardDir, fmt.Sprintf("public%s.json", ps.ByName("sid"))), scenes); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return scenes, err
|
||||
|
|
Reference in a new issue