46 lines
870 B
Go
46 lines
870 B
Go
package routes
|
|
|
|
import (
|
|
"fmt"
|
|
"path"
|
|
|
|
"git.matterlinux.xyz/matter/tracker/lib"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func GET_package(c *fiber.Ctx) error {
|
|
var (
|
|
name string
|
|
version string
|
|
pool string
|
|
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")
|
|
pool = c.Query("p")
|
|
|
|
for _, pkg := range *list {
|
|
if pkg.Name != name || (version != "ANY" && pkg.Version != version) || (pool != "" && pkg.Pool.ID() != pool) {
|
|
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)
|
|
}
|