tracker/routes/package.go

46 lines
870 B
Go
Raw Normal View History

package routes
2024-08-13 19:12:27 +00:00
import (
"fmt"
"path"
"git.matterlinux.xyz/matter/tracker/lib"
"github.com/gofiber/fiber/v2"
)
func GET_package(c *fiber.Ctx) error {
2024-08-13 19:12:27 +00:00
var (
name string
version string
2024-08-25 21:51:20 +00:00
pool string
2024-08-13 19:12:27 +00:00
list *[]lib.Package
)
is_json := c.Query("json") == "1"
is_download := c.Query("download") == "1"
list = c.Locals("list").(*[]lib.Package)
version = c.Params("version")
name = c.Params("name")
2024-08-25 21:51:20 +00:00
pool = c.Query("p")
2024-08-13 19:12:27 +00:00
for _, pkg := range *list {
2024-08-25 21:51:20 +00:00
if pkg.Name != name || (version != "ANY" && pkg.Version != version) || (pool != "" && pkg.Pool.ID() != pool) {
2024-08-13 19:12:27 +00:00
continue
}
if is_download {
c.Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s", path.Base(pkg.Archive)))
return c.SendFile(pkg.Archive)
}
if is_json {
return c.JSON(pkg)
}
return c.Render("package", &pkg)
}
return lib.RenderError(c, 404)
}