tracker/routes/package.go
2024-08-13 22:12:27 +03:00

45 lines
792 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
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)
}