2024-07-29 23:40:26 +02:00
|
|
|
package handlers_build
|
|
|
|
|
|
|
|
import (
|
|
|
|
"brunel/buildqueue"
|
|
|
|
"brunel/domain"
|
|
|
|
"brunel/fastmap"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
type QueueResponse struct {
|
|
|
|
Total int `json:"total"`
|
|
|
|
Packages *fastmap.Fastmap[string, domain.BuildQueueItem] `json:"packages"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func Queue(c *fiber.Ctx) error {
|
|
|
|
pageNum := c.QueryInt("page", 1)
|
|
|
|
pageSize := c.QueryInt("pageSize", 250)
|
|
|
|
search := strings.ToLower(c.Query("search"))
|
|
|
|
filter := c.Query("filter")
|
|
|
|
|
|
|
|
// Adjust pageNum to be 0-based for GetPage
|
|
|
|
adjustedPageNum := pageNum - 1
|
|
|
|
if adjustedPageNum < 0 {
|
|
|
|
adjustedPageNum = 0
|
|
|
|
}
|
|
|
|
|
2024-07-30 00:49:30 +02:00
|
|
|
packs := buildqueue.GetQueue()
|
2024-07-29 23:40:26 +02:00
|
|
|
finalReturn := fastmap.New[string, domain.BuildQueueItem]()
|
|
|
|
|
2024-07-30 00:49:30 +02:00
|
|
|
packs.ForEach(func(k string, source domain.BuildQueueItem) bool {
|
2024-07-29 23:40:26 +02:00
|
|
|
matchesSearch := search == "" || strings.Contains(strings.ToLower(k), search)
|
|
|
|
matchesFilter := filter == "" || source.Status == domain.BuildStatus(filter)
|
|
|
|
source.Source.Packages.Iter(func(key string, value domain.PackageInfo) bool {
|
|
|
|
if !matchesSearch && strings.Contains(strings.ToLower(key), search) {
|
|
|
|
matchesSearch = true
|
|
|
|
}
|
|
|
|
return !(matchesSearch)
|
|
|
|
})
|
|
|
|
|
|
|
|
if matchesFilter && matchesSearch {
|
|
|
|
finalReturn.Set(k, source)
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
result := finalReturn.GetPage(adjustedPageNum, pageSize)
|
|
|
|
|
|
|
|
response := QueueResponse{
|
|
|
|
Total: finalReturn.Len(),
|
|
|
|
Packages: result,
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.Status(fiber.StatusOK).JSON(response)
|
|
|
|
}
|