Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func main() {

r.Use(gin.Recovery())
r.Use(middleware.XssPreventionHeaders())
r.Use(middleware.NoCacheMiddleware())
r.Use(middleware.OptionsMiddleware())
r.Use(middleware.Ratelimit())

Expand Down
26 changes: 14 additions & 12 deletions public/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
--link-color: #92adff;
}

[data-theme='light'] {
--main-bg: #dbdbdb;
--text-color: #000;
--muted-text-color: #636363;
--code-bg: #36383d;
--code-fg: #ffffff;
--input-bg: #bcbcbc;
--input-bg-hover: #a8a8a8;
--meta-bg: #aaa8a8;
--divider-color: #b5b5b5;
--link-color: #335ad0;
@media (prefers-color-scheme: light) {
:root {
--main-bg: #dbdbdb;
--text-color: #000;
--muted-text-color: #636363;
--code-bg: #36383d;
--code-fg: #ffffff;
--input-bg: #bcbcbc;
--input-bg-hover: #a8a8a8;
--meta-bg: #aaa8a8;
--divider-color: #b5b5b5;
--link-color: #335ad0;
}
}

a {
Expand Down Expand Up @@ -76,4 +78,4 @@ details {

.fw-nowrap {
flex-wrap: nowrap;
}
}
12 changes: 0 additions & 12 deletions src/middleware/noCache.go

This file was deleted.

8 changes: 0 additions & 8 deletions src/middleware/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
func OptionsMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
c.Set("disable_images", false)
c.Set("theme", "dark")

imagesCookie, err := c.Cookie("disable_images")
if err == nil {
Expand All @@ -16,13 +15,6 @@ func OptionsMiddleware() gin.HandlerFunc {
}
}

themeCookie, err := c.Cookie("theme")
if err == nil {
if themeCookie == "light" {
c.Set("theme", "light")
}
}

c.Next()
}
}
1 change: 0 additions & 1 deletion src/middleware/ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func Ratelimit() gin.HandlerFunc {
if val.(int) > 30 {
c.HTML(429, "home.html", gin.H{
"errorMessage": "You have exceeded the request limit. Please try again in a minute.",
"theme": c.MustGet("theme").(string),
"version": config.Version,
})
c.Abort()
Expand Down
3 changes: 0 additions & 3 deletions src/routes/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
func GetHome(c *gin.Context) {
c.HTML(200, "home.html", gin.H{
"version": config.Version,
"theme": c.MustGet("theme").(string),
})
}

Expand Down Expand Up @@ -62,7 +61,6 @@ func PostHome(c *gin.Context) {
if err := c.ShouldBind(&body); err != nil {
c.HTML(400, "home.html", gin.H{
"errorMessage": "Invalid request body",
"theme": c.MustGet("theme").(string),
})
return
}
Expand All @@ -72,7 +70,6 @@ func PostHome(c *gin.Context) {
if translated == "" {
c.HTML(400, "home.html", gin.H{
"errorMessage": "Invalid stack overflow/exchange URL",
"theme": c.MustGet("theme").(string),
})
return
}
Expand Down
20 changes: 0 additions & 20 deletions src/routes/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package routes
import (
"anonymousoverflow/config"
"fmt"
"os"
"strings"

"github.com/gin-gonic/gin"
)
Expand All @@ -21,26 +19,8 @@ func ChangeOptions(c *gin.Context) {
c.SetCookie("disable_images", fmt.Sprintf("%t", !c.MustGet("disable_images").(bool)), 60*60*24*365*10, "/", "", false, true)
c.HTML(200, "home.html", gin.H{
"successMessage": "Images are now " + text,
"theme": c.MustGet("theme").(string),
"version": config.Version,
})

case "theme":
text := "dark"
if c.MustGet("theme").(string) == "dark" {
text = "light"
}

c.SetCookie("theme", text, 60*60*24*365*10, "/", "", false, true)
// get redirect url from query
redirectUrl := c.Query("redirect_url")

if !strings.HasPrefix(redirectUrl, os.Getenv("APP_URL")) {
redirectUrl = os.Getenv("APP_URL")
}

c.Redirect(302, redirectUrl)

default:
c.String(400, "400 Bad Request")
}
Expand Down
7 changes: 0 additions & 7 deletions src/routes/question.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func ViewQuestion(c *gin.Context) {
if _, err := strconv.Atoi(questionId); err != nil {
c.HTML(400, "home.html", gin.H{
"errorMessage": "Invalid question ID",
"theme": c.MustGet("theme").(string),
"version": config.Version,
})
return
Expand All @@ -60,7 +59,6 @@ func ViewQuestion(c *gin.Context) {
if resp.StatusCode() != 200 {
c.HTML(500, "home.html", gin.H{
"errorMessage": fmt.Sprintf("Received a non-OK status code %d", resp.StatusCode()),
"theme": c.MustGet("theme").(string),
"version": config.Version,
})
return
Expand All @@ -74,7 +72,6 @@ func ViewQuestion(c *gin.Context) {
if err != nil {
c.HTML(500, "home.html", gin.H{
"errorMessage": "Unable to parse question data",
"theme": c.MustGet("theme").(string),
"version": config.Version,
})
return
Expand All @@ -84,7 +81,6 @@ func ViewQuestion(c *gin.Context) {
if err != nil {
c.HTML(500, "home.html", gin.H{
"errorMessage": "Failed to extract question data",
"theme": c.MustGet("theme").(string),
"version": config.Version,
})
return
Expand All @@ -94,7 +90,6 @@ func ViewQuestion(c *gin.Context) {
if err != nil {
c.HTML(500, "home.html", gin.H{
"errorMessage": "Failed to extract answer data",
"theme": c.MustGet("theme").(string),
"version": config.Version,
})
return
Expand All @@ -110,7 +105,6 @@ func ViewQuestion(c *gin.Context) {
"question": newFilteredQuestion,
"answers": answers,
"imagePolicy": imagePolicy,
"theme": c.MustGet("theme").(string),
"currentUrl": fmt.Sprintf("%s%s", os.Getenv("APP_URL"), c.Request.URL.Path),
"sortValue": params.SoSortValue,
"domain": domain,
Expand All @@ -132,7 +126,6 @@ func parseAndValidateParameters(c *gin.Context) (inputs viewQuestionInputs, err
if _, err = strconv.Atoi(questionId); err != nil {
c.HTML(400, "home.html", gin.H{
"errorMessage": "Invalid question ID",
"theme": c.MustGet("theme").(string),
"version": config.Version,
})
return
Expand Down
2 changes: 0 additions & 2 deletions src/routes/shortened.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ func RedirectShortenedOverflowURL(c *gin.Context) {
if err != nil {
c.HTML(400, "home.html", gin.H{
"errorMessage": "Unable to fetch stack overflow URL",
"theme": c.MustGet("theme").(string),
})
return
}

if resp.StatusCode() != 302 {
c.HTML(400, "home.html", gin.H{
"errorMessage": fmt.Sprintf("Unexpected HTTP status from origin: %d", resp.StatusCode()),
"theme": c.MustGet("theme").(string),
})
return
}
Expand Down
5 changes: 2 additions & 3 deletions templates/home.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html data-theme="{{ .theme }}">
<html>

<head>
<title>AnonymousOverflow - Private frontend for StackOverflow</title>
Expand Down Expand Up @@ -43,10 +43,9 @@ <h2>Get programming help without compromising your privacy.</h2>
<div class="options">
<div class="icon">
<a href="/options/images">
<img src="/static/icons/image.svg" alt="Toggle theme" />
<img src="/static/icons/image.svg" alt="Toggle images" />
</a>
</div>
{{ template "themeSwitcher.html" .}}
</div>
<p class="footer">
Brought to you by
Expand Down
3 changes: 1 addition & 2 deletions templates/question.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html data-theme="{{ .theme }}">
<html>

<head>
<title>{{ .question.Title }} | AnonymousOverflow</title>
Expand All @@ -25,7 +25,6 @@
<a href="/" class="logo-link">
<img class="logo" src="/static/codecircles.webp" alt="AnonymousOverflow home" />
</a>
{{ template "themeSwitcher.html" . }}
</div>
<div class="card">
<div class="card-header">
Expand Down
6 changes: 0 additions & 6 deletions templates/themeSwitcher.html

This file was deleted.