tracker/routes/package.go

45 lines
792 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
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")
for _, pkg := range *list {
if pkg.Name != name || (version != "ANY" && pkg.Version != version) {
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)
}