make switchlanguage work with POST
All checks were successful
mozhi pipeline / Push Docker image to Codeberg docker registry (push) Successful in 15m6s
mozhi pipeline / Build and publish artifacts (push) Successful in 24m43s

This commit is contained in:
2023-10-11 15:57:28 +05:30
parent d4d45832c8
commit 99a4eca07b
4 changed files with 28 additions and 23 deletions

View File

@@ -11,6 +11,7 @@ import (
"codeberg.org/aryak/mozhi/pages"
"codeberg.org/aryak/mozhi/public"
"codeberg.org/aryak/mozhi/views"
"codeberg.org/aryak/mozhi/utils"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/compress"
"github.com/gofiber/fiber/v2/middleware/filesystem"
@@ -97,14 +98,14 @@ func Serve(port string) {
api.Get("/swagger/*", swagger.HandlerDefault) // default
app.All("/", pages.HandleIndex)
app.Get("/about", pages.HandleAbout)
app.Get("/switchlanguages", func(c *fiber.Ctx) error {
engine := c.Query("engine")
from := c.Query("from")
to := c.Query("to")
text := c.Query("text")
app.All("/switchlanguages", func(c *fiber.Ctx) error {
engine := utils.Sanitize(utils.GetQueryOrFormValue(c, "engine"), "alpha")
from := utils.Sanitize(utils.GetQueryOrFormValue(c, "from"), "alpha")
to := utils.Sanitize(utils.GetQueryOrFormValue(c, "to"), "alpha")
text := utils.Sanitize(utils.GetQueryOrFormValue(c, "text"), "alpha")
return c.Redirect("/?engine="+engine+"&from="+to+"&to="+from+"&text="+text+"&redirected=true", 301)
})
app.Get("/about", pages.HandleAbout)
app.Use("/", filesystem.New(filesystem.Config{
MaxAge: 2592000,
Root: http.FS(public.GetFiles()),