diff --git a/lib/util.go b/lib/util.go index 4742f9d..2938646 100644 --- a/lib/util.go +++ b/lib/util.go @@ -94,9 +94,9 @@ func GetTimePassed(t time.Time) string { } func CleanString(s string) string{ - var possible_bad_char_list_that_i_made_up_which_may_contain_bad_xss_chars_look_im_not_gonna_search_for_a_xss_charlist_just_to_prevent_self_xss []string = []string{"'", "\"", "/", "<", ">", "?", "=", "#", "(", ")", "{", "}", "*", "!", "`", "[", "]"} + var badchars []string = []string{"~", "'", "\"", "/", "<", ">", "?", "=", "#", "(", ")", "{", "}", "*", "!", "`", "[", "]"} - for _, c := range possible_bad_char_list_that_i_made_up_which_may_contain_bad_xss_chars_look_im_not_gonna_search_for_a_xss_charlist_just_to_prevent_self_xss { + for _, c := range badchars { s = strings.ReplaceAll(s, c, "") } diff --git a/main.go b/main.go index f7d2ef8..a5811c9 100644 --- a/main.go +++ b/main.go @@ -30,11 +30,6 @@ import ( "github.com/gofiber/template/html/v2" ) -type PostData struct { - Repo string `form:"repo"` - Name string `form:"name"` -} - var lastupdate time.Time var updatetick = time.NewTicker(time.Hour) var stopchan = make(chan struct{}) @@ -59,39 +54,44 @@ func UpdatePackages() { } func GETIndex(c *fiber.Ctx) error { - return c.Render("index", fiber.Map{ - "last": lib.GetTimePassed(lastupdate), - "repos": lib.Repos, - "pkgs": lib.Packages, - }) -} - -func POSTIndex(c *fiber.Ctx) error { - var pdata PostData - err := c.BodyParser(&pdata) - if err != nil || pdata.Name == ""{ - return c.Redirect("/") + repo := c.Query("r") + name := c.Query("n") + exact := c.Query("e") + + if repo == "" && name == "" { + return c.Render("index", fiber.Map{ + "last": lib.GetTimePassed(lastupdate), + "repos": lib.Repos, + "pkgs": lib.Packages, + }) } + name = lib.CleanString(name) var res []lib.Package - pdata.Name = lib.CleanString(pdata.Name) for _, p := range lib.Packages { - if(pdata.Repo != "all" && p.Repo != pdata.Repo){ + if(repo != "all" && p.Repo != repo){ continue } - if(strings.Contains(p.Name, pdata.Name)){ - res = append(res, p) + if(exact == ""){ + if(strings.Contains(p.Name, name)){ + res = append(res, p) + } + }else { + if (p.Name == name) { + res = append(res, p) + } } } return c.Render("index", fiber.Map{ - "search": pdata.Name, + "search": name, "last": lib.GetTimePassed(lastupdate), "repos": lib.Repos, "pkgs": res, }) + } func main(){ @@ -103,7 +103,6 @@ func main(){ app.Static("/", "./public") app.Get("/", GETIndex) - app.Post("/", POSTIndex) app.Get("*", func(c *fiber.Ctx) error { return lib.RenderError(c, 404) diff --git a/public/style.css b/public/style.css index 40679e0..32f011c 100644 --- a/public/style.css +++ b/public/style.css @@ -2,8 +2,8 @@ :root { --dark-main: black; - --dark-second: #070707; - --dark-third: #151515; + --dark-second: #090909; + --dark-third: #181818; --bright-main: white; --bright-second: #DFDFDF; --bright-third: #777777; @@ -38,30 +38,19 @@ main { border-bottom: solid 1px white; } -.logo-div { - display: flex; - flex-direction: row; - color: white; - gap: 15px; -} - -.logo-text{ - font-family: JetBrainsMono; - font-size: 25px; -} - .logo { font-family: JetBrainsItalic; + color: white; font-size: 25px; } .links { - display: flex; - flex-direction: row; - gap: 10px; + display: block; + text-align: right; } .links a{ + margin-left: 7px; color: var(--bright-main); font-family: Ubuntu; font-size: 20px; diff --git a/templates/index.html b/templates/index.html index 66bacee..82739ef 100644 --- a/templates/index.html +++ b/templates/index.html @@ -10,13 +10,13 @@ {{template "parts/bar" .}}