update: add pool query to package page

This commit is contained in:
ngn 2024-08-26 00:51:20 +03:00
parent 6815f1a762
commit 5bf6876558
3 changed files with 21 additions and 3 deletions

View File

@ -8,6 +8,8 @@ import (
"io" "io"
"os" "os"
"path" "path"
"strings"
"unicode"
"github.com/bigkevmcd/go-configparser" "github.com/bigkevmcd/go-configparser"
) )
@ -25,6 +27,21 @@ type Pool struct {
Dir string `json:"dir"` Dir string `json:"dir"`
} }
func (p *Pool) ID() string {
var res string = ""
for _, c := range p.Display {
if unicode.IsDigit(c) || unicode.IsLetter(c) {
res += string(c)
continue
}
res += "-"
}
return strings.TrimSuffix(res, "-")
}
func (p *Pool) Load(list *[]Package) error { func (p *Pool) Load(list *[]Package) error {
var err error var err error

View File

@ -12,6 +12,7 @@ func GET_package(c *fiber.Ctx) error {
var ( var (
name string name string
version string version string
pool string
list *[]lib.Package list *[]lib.Package
) )
@ -21,11 +22,11 @@ func GET_package(c *fiber.Ctx) error {
list = c.Locals("list").(*[]lib.Package) list = c.Locals("list").(*[]lib.Package)
version = c.Params("version") version = c.Params("version")
name = c.Params("name") name = c.Params("name")
pool = c.Query("p")
for _, pkg := range *list { for _, pkg := range *list {
if pkg.Name != name || (version != "ANY" && pkg.Version != version) { if pkg.Name != name || (version != "ANY" && pkg.Version != version) || (pool != "" && pkg.Pool.ID() != pool) {
continue continue
} }
if is_download { if is_download {

View File

@ -49,7 +49,7 @@
</tr> </tr>
{{range .list}} {{range .list}}
<tr> <tr>
<td><a href="/p/{{.Name}}/{{.Version}}">{{.Name}}</a></td> <td><a href="/p/{{.Name}}/{{.Version}}?p={{.Pool.ID}}">{{.Name}}</a></td>
{{if .Pool}} {{if .Pool}}
<td>{{.Pool.Display}}</td> <td>{{.Pool.Display}}</td>
{{else}} {{else}}