Commit c2b1723b authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Fail early when a group doesn't exist.

parent c9865830
...@@ -346,9 +346,6 @@ type groupDescription struct { ...@@ -346,9 +346,6 @@ type groupDescription struct {
func descriptionChanged(name string, old *groupDescription) (bool, error) { func descriptionChanged(name string, old *groupDescription) (bool, error) {
fi, err := os.Stat(filepath.Join(groupsDir, name+".json")) fi, err := os.Stat(filepath.Join(groupsDir, name+".json"))
if err != nil { if err != nil {
if os.IsNotExist(err) {
err = userError("group does not exist")
}
return false, err return false, err
} }
if fi.Size() != old.fileSize || fi.ModTime() != old.modTime { if fi.Size() != old.fileSize || fi.ModTime() != old.modTime {
...@@ -360,9 +357,6 @@ func descriptionChanged(name string, old *groupDescription) (bool, error) { ...@@ -360,9 +357,6 @@ func descriptionChanged(name string, old *groupDescription) (bool, error) {
func getDescription(name string) (*groupDescription, error) { func getDescription(name string) (*groupDescription, error) {
r, err := os.Open(filepath.Join(groupsDir, name+".json")) r, err := os.Open(filepath.Join(groupsDir, name+".json"))
if err != nil { if err != nil {
if os.IsNotExist(err) {
err = userError("group does not exist")
}
return nil, err return nil, err
} }
defer r.Close() defer r.Close()
......
...@@ -704,6 +704,9 @@ func startClient(conn *websocket.Conn) (err error) { ...@@ -704,6 +704,9 @@ func startClient(conn *websocket.Conn) (err error) {
g, err := addClient(m.Group, c) g, err := addClient(m.Group, c)
if err != nil { if err != nil {
if os.IsNotExist(err) {
err = userError("group does not exist")
}
return return
} }
c.group = g c.group = g
......
...@@ -21,12 +21,7 @@ import ( ...@@ -21,12 +21,7 @@ import (
func webserver() { func webserver() {
http.Handle("/", mungeHandler{http.FileServer(http.Dir(staticRoot))}) http.Handle("/", mungeHandler{http.FileServer(http.Dir(staticRoot))})
http.HandleFunc("/group/", http.HandleFunc("/group/", groupHandler)
func(w http.ResponseWriter, r *http.Request) {
mungeHeader(w)
http.ServeFile(w, r,
filepath.Join(staticRoot, "sfu.html"))
})
http.HandleFunc("/recordings", http.HandleFunc("/recordings",
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, http.Redirect(w, r,
...@@ -74,6 +69,44 @@ func (h mungeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ...@@ -74,6 +69,44 @@ func (h mungeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.h.ServeHTTP(w, r) h.h.ServeHTTP(w, r)
} }
func parseGroupName(path string) string {
if !strings.HasPrefix(path, "/group/") {
return ""
}
name := path[len("/group/"):]
if name == "" {
return ""
}
if name[len(name)-1] == '/' {
name = name[:len(name)-1]
}
return name
}
func groupHandler(w http.ResponseWriter, r *http.Request) {
mungeHeader(w)
name := parseGroupName(r.URL.Path)
if name == "" {
http.NotFound(w, r)
return
}
_, err := addGroup(name, nil)
if err != nil {
if os.IsNotExist(err) {
http.NotFound(w, r)
} else {
log.Println("addGroup: %v", err)
http.Error(w, "Internal server error",
http.StatusInternalServerError)
}
return
}
http.ServeFile(w, r, filepath.Join(staticRoot, "sfu.html"))
}
func publicHandler(w http.ResponseWriter, r *http.Request) { func publicHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("content-type", "application/json") w.Header().Set("content-type", "application/json")
w.Header().Set("cache-control", "no-cache") w.Header().Set("cache-control", "no-cache")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment