Skip to content

Commit

Permalink
parse query after setting cookies. fixes #107
Browse files Browse the repository at this point in the history
  • Loading branch information
rystaf committed Jul 21, 2024
1 parent 0c9f2df commit 1a566e4
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ func Initialize(Host string, r *http.Request) (State, error) {
} else {
state.CollapseMedia = os.Getenv("COLLAPSE_MEDIA") != ""
}
state.ParseQuery(r.URL.RawQuery)
if state.Sort == "" {
state.Sort = getenv("SORT")
}
Expand Down Expand Up @@ -468,6 +467,7 @@ func PostRoot(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
dest, _ := url.Parse(input)
if dest.Host != "" {
state, _ := Initialize(dest.Host, r)
state.ParseQuery(r.URL.RawQuery)
if err := state.LemmyError(dest.Host); err != nil {
data["Error"] = err
} else {
Expand All @@ -489,6 +489,7 @@ func GetIcon(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
w.Write([]byte("404 - Not Found"))
}
state, _ := Initialize(ps.ByName("host"), r)
state.ParseQuery(r.URL.RawQuery)
state.Client.Token = ""
resp, err := state.Client.Site(context.Background())
if err != nil {
Expand Down Expand Up @@ -522,6 +523,7 @@ func GetFrontpage(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
if state.CookieAge != int(time.Now().Month()) {
setCookies(w, &state)
}
state.ParseQuery(r.URL.RawQuery)
if err != nil {
Render(w, "index.html", state)
return
Expand Down Expand Up @@ -584,6 +586,7 @@ func ResolveId(r *http.Request, class string, id string, host string) string {

func GetPost(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
state, err := Initialize(ps.ByName("host"), r)
state.ParseQuery(r.URL.RawQuery)
if err != nil {
Render(w, "index.html", state)
return
Expand Down Expand Up @@ -638,6 +641,7 @@ func GetPost(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
}
func GetComment(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
state, err := Initialize(ps.ByName("host"), r)
state.ParseQuery(r.URL.RawQuery)
if err != nil {
Render(w, "index.html", state)
return
Expand Down Expand Up @@ -702,6 +706,7 @@ func GetComment(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
}
func GetUser(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
state, err := Initialize(ps.ByName("host"), r)
state.ParseQuery(r.URL.RawQuery)
state.Sort = "New"
m, _ := url.ParseQuery(r.URL.RawQuery)
if len(m["sort"]) > 0 {
Expand All @@ -719,6 +724,7 @@ func GetUser(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
}
func GetMessageForm(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
state, err := Initialize(ps.ByName("host"), r)
state.ParseQuery(r.URL.RawQuery)
if err != nil {
Render(w, "index.html", state)
return
Expand All @@ -729,6 +735,7 @@ func GetMessageForm(w http.ResponseWriter, r *http.Request, ps httprouter.Params
}
func SendMessage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
state, err := Initialize(ps.ByName("host"), r)
state.ParseQuery(r.URL.RawQuery)
if err != nil {
Render(w, "index.html", state)
return
Expand All @@ -748,6 +755,7 @@ func SendMessage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
}
func GetCreatePost(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
state, err := Initialize(ps.ByName("host"), r)
state.ParseQuery(r.URL.RawQuery)
if err != nil {
Render(w, "index.html", state)
return
Expand All @@ -770,6 +778,7 @@ func GetCreatePost(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
}
func GetCreateCommunity(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
state, err := Initialize(ps.ByName("host"), r)
state.ParseQuery(r.URL.RawQuery)
if err != nil {
fmt.Println(err)
Render(w, "index.html", state)
Expand All @@ -786,6 +795,7 @@ func GetCreateCommunity(w http.ResponseWriter, r *http.Request, ps httprouter.Pa

func Inbox(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
state, err := Initialize(ps.ByName("host"), r)
state.ParseQuery(r.URL.RawQuery)
if err != nil {
Render(w, "index.html", state)
return
Expand Down Expand Up @@ -878,6 +888,7 @@ func setCookies(w http.ResponseWriter, state *State) {
}
func Settings(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
state, err := Initialize(ps.ByName("host"), r)
state.ParseQuery(r.URL.RawQuery)
if err != nil {
Render(w, "index.html", state)
return
Expand Down Expand Up @@ -923,6 +934,7 @@ func Settings(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

func SignUpOrLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
state, err := Initialize(ps.ByName("host"), r)
state.ParseQuery(r.URL.RawQuery)
if err != nil {
fmt.Println(err)
Render(w, "index.html", state)
Expand Down Expand Up @@ -1014,6 +1026,7 @@ func SignUpOrLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
}
func GetLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
state, err := Initialize(ps.ByName("host"), r)
state.ParseQuery(r.URL.RawQuery)
if err != nil {
Render(w, "index.html", state)
return
Expand All @@ -1030,6 +1043,7 @@ func GetLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
}
func Search(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
state, err := Initialize(ps.ByName("host"), r)
state.ParseQuery(r.URL.RawQuery)
if err != nil {
Render(w, "index.html", state)
return
Expand Down Expand Up @@ -1073,6 +1087,7 @@ type PictrsResponse struct {

func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
state, err := Initialize(ps.ByName("host"), r)
state.ParseQuery(r.URL.RawQuery)
if err != nil {
Render(w, "index.html", state)
return
Expand Down

0 comments on commit 1a566e4

Please sign in to comment.