55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package apihandler
|
|
|
|
import (
|
|
"net/http"
|
|
"sort"
|
|
|
|
"codeberg.org/vlbeaudoin/pave"
|
|
"git.agecem.com/agecem/agecem-org/apiresponse"
|
|
"git.agecem.com/agecem/agecem-org/config"
|
|
"git.agecem.com/agecem/agecem-org/media"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
type V1Handler struct {
|
|
Config config.Config
|
|
MediaClient *media.MediaClient
|
|
Pave *pave.Pave
|
|
}
|
|
|
|
// API Handlers
|
|
|
|
// V1GET affiche les routes accessibles.
|
|
// Les routes sont triées selon .Path, pour les rendre plus facilement navigables.
|
|
func (h *V1Handler) V1GET(c echo.Context) error {
|
|
routes := c.Echo().Routes()
|
|
sort.Slice(routes, func(i, j int) bool { return routes[i].Path < routes[j].Path })
|
|
return c.JSON(http.StatusOK, routes)
|
|
}
|
|
|
|
// V1SeedPOST créé des buckets dans minio selon la liste de buckets dans server.documents.buckets
|
|
// Les buckets sont créés avec paramètres par défaut, et sont ensuite visible dans /v1/bucket.
|
|
func (h *V1Handler) V1SeedPOST(c echo.Context) error {
|
|
var response apiresponse.V1SeedPOST
|
|
|
|
new_buckets, err := h.MediaClient.Seed()
|
|
response.Data.Buckets = new_buckets
|
|
if err != nil {
|
|
response.StatusCode = http.StatusInternalServerError
|
|
response.Message = "Error during mediaClient.Seed()"
|
|
response.Error = err.Error()
|
|
|
|
return c.JSON(response.StatusCode, response)
|
|
}
|
|
|
|
if len(new_buckets) == 0 {
|
|
response.Message = "All buckets already exist"
|
|
|
|
} else {
|
|
response.Message = "Buckets successfully created"
|
|
}
|
|
|
|
response.StatusCode = http.StatusOK
|
|
|
|
return c.JSON(response.StatusCode, response)
|
|
}
|