From 4bdd7c7665e1d146b2c888505c1203d9f313de79 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Thu, 10 Sep 2020 13:55:57 +0200 Subject: [PATCH] Implement group redirection. --- README | 4 +++- group.go | 1 + webclient.go | 6 ++++++ webserver.go | 9 ++++++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README b/README index cfa552e..d9a67ed 100644 --- a/README +++ b/README @@ -75,7 +75,9 @@ fields, all of which are optional. - `allow-recording`: if true, then recording is allowed in this group; - `allow-anonymous`: if true, then users may connect with an empty username; this is not recommended, since anonymous users are not - allowed to participate in the chat. + allowed to participate in the chat; + - `redirect`: if set, then attempts to join the group will be redirected + to the given URL; most other fields are ignored in this case. A user definition is a dictionary with the following fields: diff --git a/group.go b/group.go index d81ffea..a954190 100644 --- a/group.go +++ b/group.go @@ -334,6 +334,7 @@ type groupDescription struct { loadTime time.Time `json:"-"` modTime time.Time `json:"-"` fileSize int64 `json:"-"` + Redirect string `json:"redirect,omitempty"` Public bool `json:"public,omitempty"` MaxClients int `json:"max-clients,omitempty"` AllowAnonymous bool `json:"allow-anonymous,omitempty"` diff --git a/webclient.go b/webclient.go index ea2cb7b..8af2019 100644 --- a/webclient.go +++ b/webclient.go @@ -709,6 +709,12 @@ func startClient(conn *websocket.Conn) (err error) { } return } + if g.description.Redirect != "" { + // We normally redirect at the HTTP level, but the group + // description could have been edited in the meantime. + err = userError("group is now at " + g.description.Redirect) + return + } c.group = g defer delClient(c) diff --git a/webserver.go b/webserver.go index 95c0dec..85f0a83 100644 --- a/webserver.go +++ b/webserver.go @@ -93,7 +93,7 @@ func groupHandler(w http.ResponseWriter, r *http.Request) { return } - _, err := addGroup(name, nil) + g, err := addGroup(name, nil) if err != nil { if os.IsNotExist(err) { http.NotFound(w, r) @@ -104,6 +104,13 @@ func groupHandler(w http.ResponseWriter, r *http.Request) { } return } + + if g.description.Redirect != "" { + http.Redirect(w, r, g.description.Redirect, + http.StatusPermanentRedirect) + return + } + http.ServeFile(w, r, filepath.Join(staticRoot, "sfu.html")) }