Updating css to match with the website, changing search route to GET from POST
This commit is contained in:
45
main.go
45
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)
|
||||
|
Reference in New Issue
Block a user