mirror of
https://github.com/rystaf/mlmym.git
synced 2024-11-08 08:04:26 +00:00
dont set default cookies
This commit is contained in:
parent
313265a1fa
commit
9775db753f
31
routes.go
31
routes.go
|
@ -264,10 +264,17 @@ func RegReplace(input string, match string, replace string) string {
|
||||||
return re.ReplaceAllString(input, replace)
|
return re.ReplaceAllString(input, replace)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getenv(key, fallback string) string {
|
func getenv(key string) string {
|
||||||
value := os.Getenv(key)
|
value := os.Getenv(key)
|
||||||
if len(value) == 0 {
|
if len(value) == 0 {
|
||||||
return fallback
|
switch key {
|
||||||
|
case "SORT", "COMMENT_SORT":
|
||||||
|
return "Hot"
|
||||||
|
case "LISTING":
|
||||||
|
return "All"
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
@ -343,13 +350,13 @@ func Initialize(Host string, r *http.Request) (State, error) {
|
||||||
}
|
}
|
||||||
state.ParseQuery(r.URL.RawQuery)
|
state.ParseQuery(r.URL.RawQuery)
|
||||||
if state.Sort == "" {
|
if state.Sort == "" {
|
||||||
state.Sort = getenv("SORT", "Hot")
|
state.Sort = getenv("SORT")
|
||||||
}
|
}
|
||||||
if state.CommentSort == "" {
|
if state.CommentSort == "" {
|
||||||
state.CommentSort = getenv("COMMENT_SORT", "Hot")
|
state.CommentSort = getenv("COMMENT_SORT")
|
||||||
}
|
}
|
||||||
if state.Listing == "" || state.Session == nil && state.Listing == "Subscribed" {
|
if state.Listing == "" || state.Session == nil && state.Listing == "Subscribed" {
|
||||||
state.Listing = getenv("LISTING", "All")
|
state.Listing = getenv("LISTING")
|
||||||
}
|
}
|
||||||
if linksInNewWindow := getCookie(r, "LinksInNewWindow"); linksInNewWindow != "" {
|
if linksInNewWindow := getCookie(r, "LinksInNewWindow"); linksInNewWindow != "" {
|
||||||
state.LinksInNewWindow = linksInNewWindow != "0"
|
state.LinksInNewWindow = linksInNewWindow != "0"
|
||||||
|
@ -832,10 +839,12 @@ func setCookies(w http.ResponseWriter, state *State) {
|
||||||
bools["CollapseMedia"] = state.CollapseMedia
|
bools["CollapseMedia"] = state.CollapseMedia
|
||||||
bools["LinksInNewWindow"] = state.LinksInNewWindow
|
bools["LinksInNewWindow"] = state.LinksInNewWindow
|
||||||
for k, v := range bools {
|
for k, v := range bools {
|
||||||
if v {
|
e, ok := env[k]
|
||||||
setCookie(w, "", k, "1")
|
ev := (ok && os.Getenv(e) != "")
|
||||||
} else if e, ok := env[k]; ok && os.Getenv(e) != "" {
|
if !v && ev {
|
||||||
setCookie(w, "", k, "0")
|
setCookie(w, "", k, "0")
|
||||||
|
} else if v && !ev {
|
||||||
|
setCookie(w, "", k, "1")
|
||||||
} else {
|
} else {
|
||||||
deleteCookie(w, "", k)
|
deleteCookie(w, "", k)
|
||||||
}
|
}
|
||||||
|
@ -845,7 +854,11 @@ func setCookies(w http.ResponseWriter, state *State) {
|
||||||
strings["DefaultListingType"] = state.Listing
|
strings["DefaultListingType"] = state.Listing
|
||||||
strings["DefaultCommentSortType"] = state.CommentSort
|
strings["DefaultCommentSortType"] = state.CommentSort
|
||||||
for k, v := range strings {
|
for k, v := range strings {
|
||||||
setCookie(w, "", k, v)
|
if e, ok := env[k]; ok && getenv(e) == v {
|
||||||
|
deleteCookie(w, "", k)
|
||||||
|
} else {
|
||||||
|
setCookie(w, "", k, v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if state.Dark == nil {
|
if state.Dark == nil {
|
||||||
deleteCookie(w, "", "Dark")
|
deleteCookie(w, "", "Dark")
|
||||||
|
|
Loading…
Reference in a new issue