1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-26 02:25:58 +01:00

Fail early when a group doesn't exist.

This commit is contained in:
Juliusz Chroboczek 2020-09-10 13:39:38 +02:00
parent c9865830cc
commit c2b1723bd4
3 changed files with 42 additions and 12 deletions

View file

@ -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) {
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()

View file

@ -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

View file

@ -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) {
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")