Append pathname to bootloader request
This commit is contained in:
parent
ed40b956b7
commit
fd6c8a70e2
7 changed files with 49 additions and 46 deletions
|
@ -5,9 +5,8 @@ import (
|
|||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/khlieng/dispatch/storage"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type connectDefaults struct {
|
||||
|
@ -36,7 +35,7 @@ type indexData struct {
|
|||
Messages *Messages
|
||||
}
|
||||
|
||||
func getIndexData(r *http.Request, state *State) *indexData {
|
||||
func getIndexData(r *http.Request, path string, state *State) *indexData {
|
||||
data := indexData{
|
||||
HexIP: viper.GetBool("hexIP"),
|
||||
}
|
||||
|
@ -84,13 +83,13 @@ func getIndexData(r *http.Request, state *State) *indexData {
|
|||
}
|
||||
data.Channels = channels
|
||||
|
||||
server, channel := getTabFromPath(r.URL.EscapedPath())
|
||||
server, channel := getTabFromPath(path)
|
||||
if isInChannel(channels, server, channel) {
|
||||
data.addUsersAndMessages(server, channel, state)
|
||||
return &data
|
||||
}
|
||||
|
||||
server, channel = parseTabCookie(r, r.URL.Path)
|
||||
server, channel = parseTabCookie(r, path)
|
||||
if isInChannel(channels, server, channel) {
|
||||
data.addUsersAndMessages(server, channel, state)
|
||||
}
|
||||
|
@ -137,10 +136,10 @@ func isInChannel(channels []*storage.Channel, server, channel string) bool {
|
|||
|
||||
func getTabFromPath(rawPath string) (string, string) {
|
||||
path := strings.Split(strings.Trim(rawPath, "/"), "/")
|
||||
if len(path) == 2 {
|
||||
name, err := url.PathUnescape(path[1])
|
||||
if len(path) >= 2 {
|
||||
name, err := url.PathUnescape(path[len(path)-1])
|
||||
if err == nil && isChannel(name) {
|
||||
return path[0], name
|
||||
return path[len(path)-2], name
|
||||
}
|
||||
}
|
||||
return "", ""
|
||||
|
|
|
@ -32,6 +32,10 @@ func TestGetTabFromPath(t *testing.T) {
|
|||
"/chat.freenode.net/%23stuff/cake",
|
||||
"",
|
||||
"",
|
||||
}, {
|
||||
"/data/chat.freenode.net/%23apples",
|
||||
"chat.freenode.net",
|
||||
"#apples",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -323,7 +323,7 @@ func (d *Dispatch) serveIndex(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
var data *indexData
|
||||
if !sw {
|
||||
data = getIndexData(r, state)
|
||||
data = getIndexData(r, r.URL.EscapedPath(), state)
|
||||
}
|
||||
|
||||
inline := inlineScript
|
||||
|
|
|
@ -189,7 +189,7 @@ func (d *Dispatch) serve(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
easyjson.MarshalToHTTPResponseWriter(getIndexData(r, state), w)
|
||||
easyjson.MarshalToHTTPResponseWriter(getIndexData(r, r.URL.EscapedPath()[5:], state), w)
|
||||
} else {
|
||||
d.serveFiles(w, r)
|
||||
}
|
||||
|
|
|
@ -72,9 +72,9 @@ func (h *wsHandler) init(r *http.Request) {
|
|||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
path := r.URL.EscapedPath()[3:]
|
||||
path := r.URL.EscapedPath()
|
||||
pathServer, pathChannel := getTabFromPath(path)
|
||||
cookieServer, cookieChannel := parseTabCookie(r, path)
|
||||
cookieServer, cookieChannel := parseTabCookie(r, path[3:])
|
||||
|
||||
for _, channel := range channels {
|
||||
if (channel.Server == pathServer && channel.Name == pathChannel) ||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue