Files
cluster/internal/module/registry/catalog.go
loveuer 8b655d3496 refactor: reorganize models to pkg/model and add authentication module
- Move ORM models from internal/model to pkg/model organized by module (auth/k8s/registry)
- Add authentication module with login, user management handlers
- Update all import paths to use new model locations
- Add frontend auth pages (Login, UserManagement) and authStore
- Remove deprecated internal/model/model.go
2025-11-20 14:55:48 +08:00

67 lines
1.3 KiB
Go

package registry
import (
"strconv"
"strings"
"gitea.loveuer.com/loveuer/cluster/pkg/model/registry"
"gitea.loveuer.com/loveuer/cluster/pkg/resp"
"gitea.loveuer.com/loveuer/cluster/pkg/store"
"github.com/gofiber/fiber/v3"
"gorm.io/gorm"
)
// HandleCatalog ????????
// GET /v2/_catalog?n={limit}&last={last}
func HandleCatalog(c fiber.Ctx, db *gorm.DB, store store.Store) error {
path := c.Path()
// ????: /v2/_catalog
parts := strings.Split(strings.TrimPrefix(path, "/v2/"), "/")
if len(parts) < 1 || parts[0] != "_catalog" {
return resp.R404(c, "INVALID_PATH", nil, "invalid path")
}
// ??????
nStr := c.Query("n", "100")
n, err := strconv.Atoi(nStr)
if err != nil || n <= 0 {
n = 100
}
last := c.Query("last")
// ????
var repos []registry.Repository
query := db.Order("name ASC").Limit(n + 1)
if last != "" {
query = query.Where("name > ?", last)
}
if err := query.Find(&repos).Error; err != nil {
return resp.R500(c, "", nil, err)
}
// ????
repoNames := make([]string, 0, len(repos))
hasMore := false
for i, repo := range repos {
if i >= n {
hasMore = true
break
}
repoNames = append(repoNames, repo.Name)
}
response := map[string]interface{}{
"repositories": repoNames,
}
// ??????????????
if hasMore && len(repoNames) > 0 {
response["last"] = repoNames[len(repoNames)-1]
}
return resp.R200(c, response)
}