56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package registry
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gitea.loveuer.com/loveuer/cluster/internal/model"
|
|
"gitea.loveuer.com/loveuer/cluster/pkg/resp"
|
|
"gitea.loveuer.com/loveuer/cluster/pkg/store"
|
|
"github.com/gofiber/fiber/v3"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// RegistryImageList returns the list of images/repositories
|
|
func RegistryImageList(ctx context.Context, db *gorm.DB, store store.Store) fiber.Handler {
|
|
return func(c fiber.Ctx) error {
|
|
var repositories []model.Repository
|
|
|
|
// Query all repositories from the database
|
|
if err := db.Find(&repositories).Error; err != nil {
|
|
return resp.R500(c, "", nil, err)
|
|
}
|
|
|
|
// Convert to the expected format for the frontend
|
|
var result []map[string]interface{}
|
|
for _, repo := range repositories {
|
|
// Calculate total size of all blobs for this repository
|
|
var totalSize int64
|
|
var sizeResult struct {
|
|
Total int64
|
|
}
|
|
err := db.Model(&model.Blob{}).
|
|
Where("repository = ?", repo.Name).
|
|
Select("COALESCE(SUM(size), 0) as total").
|
|
Scan(&sizeResult).Error
|
|
if err == nil {
|
|
totalSize = sizeResult.Total
|
|
}
|
|
|
|
// Format updated_at to second precision
|
|
uploadTime := repo.UpdatedAt.Format("2006-01-02 15:04:05")
|
|
|
|
repoMap := map[string]interface{}{
|
|
"id": repo.ID,
|
|
"name": repo.Name,
|
|
"upload_time": uploadTime,
|
|
"size": totalSize,
|
|
}
|
|
result = append(result, repoMap)
|
|
}
|
|
|
|
return resp.R200(c, map[string]interface{}{
|
|
"images": result,
|
|
})
|
|
}
|
|
}
|