update: make things work with the new package system
This commit is contained in:
75
routes/index.go
Normal file
75
routes/index.go
Normal file
@ -0,0 +1,75 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.matterlinux.xyz/matter/tracker/lib"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func GET_index(c *fiber.Ctx) error {
|
||||
var (
|
||||
result []lib.Package
|
||||
list *[]lib.Package
|
||||
config *lib.Config
|
||||
pools_str string
|
||||
pools []string
|
||||
last *time.Time
|
||||
)
|
||||
|
||||
result = []lib.Package{}
|
||||
pools = []string{}
|
||||
|
||||
config = c.Locals("config").(*lib.Config)
|
||||
list = c.Locals("list").(*[]lib.Package)
|
||||
last = c.Locals("last").(*time.Time)
|
||||
|
||||
is_exact := c.Query("exact") == "1"
|
||||
is_json := c.Query("json") == "1"
|
||||
|
||||
if pools_str = c.Query("pools"); pools_str != "" {
|
||||
pools = strings.Split(pools_str, ",")
|
||||
}
|
||||
query := c.Query("q")
|
||||
|
||||
for _, pkg := range *list {
|
||||
found := false
|
||||
|
||||
if is_exact && query != "" && pkg.Name != query {
|
||||
continue
|
||||
}
|
||||
|
||||
if !is_exact && query != "" && !strings.Contains(pkg.Name, query) {
|
||||
continue
|
||||
}
|
||||
|
||||
if len(pools) != 0 {
|
||||
for _, p := range pools {
|
||||
if p == pkg.Pool.Name {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
found = true
|
||||
}
|
||||
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
|
||||
result = append(result, pkg)
|
||||
}
|
||||
|
||||
if is_json {
|
||||
return c.JSON(result)
|
||||
}
|
||||
|
||||
return c.Render("index", &fiber.Map{
|
||||
"query": query,
|
||||
"list": result,
|
||||
"last": lib.TimePassed(*last),
|
||||
"pools": config.Pools,
|
||||
})
|
||||
}
|
8
routes/package.go
Normal file
8
routes/package.go
Normal file
@ -0,0 +1,8 @@
|
||||
package routes
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
|
||||
func GET_package(c *fiber.Ctx) error {
|
||||
//name := c.Params("name")
|
||||
return c.Render("package", &fiber.Map{})
|
||||
}
|
Reference in New Issue
Block a user