47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
/*
|
|
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
|
*
|
|
* This work is published and licensed under a Creative Commons
|
|
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
|
|
*
|
|
* Distribution of this work is permitted, but commercial use and
|
|
* modifications are strictly prohibited.
|
|
*/
|
|
package imageoper
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"slices"
|
|
)
|
|
|
|
type ListManifestsParams struct {
|
|
N int64
|
|
}
|
|
type ListManifestsResult struct {
|
|
Repositories []string `json:"repositories"`
|
|
}
|
|
|
|
func (oper *Operator) ListManifests(ctx context.Context, params *ListManifestsParams) (*ListManifestsResult, int, error) {
|
|
var err error
|
|
res := &ListManifestsResult{
|
|
Repositories: make([]string, 0),
|
|
}
|
|
refMap := make(map[string]bool)
|
|
descrs, err := oper.mdb.ListAllManifests(ctx)
|
|
if err != nil {
|
|
return res, http.StatusInternalServerError, err
|
|
}
|
|
for _, descr := range descrs {
|
|
_, already := refMap[descr.Name]
|
|
if !already {
|
|
refMap[descr.Name] = true
|
|
}
|
|
}
|
|
for key, _ := range refMap {
|
|
res.Repositories = append(res.Repositories, key)
|
|
}
|
|
slices.Sort(res.Repositories)
|
|
return res, http.StatusOK, err
|
|
}
|