2023-11-20 14:14:00 -05:00
|
|
|
package apihandler
|
2023-07-24 14:28:55 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"sort"
|
|
|
|
|
2023-11-20 15:13:42 -05:00
|
|
|
"codeberg.org/vlbeaudoin/pave"
|
2023-10-24 17:39:15 -04:00
|
|
|
"git.agecem.com/agecem/agecem-org/apiresponse"
|
2023-07-24 14:28:55 -04:00
|
|
|
"git.agecem.com/agecem/agecem-org/config"
|
|
|
|
"git.agecem.com/agecem/agecem-org/media"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
2023-08-30 13:45:07 -04:00
|
|
|
type V1Handler struct {
|
|
|
|
Config config.Config
|
|
|
|
MediaClient *media.MediaClient
|
2023-11-20 15:13:42 -05:00
|
|
|
Pave *pave.Pave
|
2023-08-30 13:45:07 -04:00
|
|
|
}
|
|
|
|
|
2023-07-24 14:28:55 -04:00
|
|
|
// API Handlers
|
|
|
|
|
|
|
|
// HandleV1 affiche les routes accessibles.
|
|
|
|
// Les routes sont triées selon .Path, pour les rendre plus facilement navigables.
|
2023-08-30 13:45:07 -04:00
|
|
|
func (h *V1Handler) HandleV1(c echo.Context) error {
|
2023-07-24 14:28:55 -04:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
// HandleV1Seed 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.
|
2023-08-30 13:45:07 -04:00
|
|
|
func (h *V1Handler) HandleV1Seed(c echo.Context) error {
|
2023-11-20 15:13:42 -05:00
|
|
|
var response apiresponse.V1SeedPOST
|
2023-08-19 19:58:09 -04:00
|
|
|
|
2023-08-30 13:45:07 -04:00
|
|
|
new_buckets, err := h.MediaClient.Seed()
|
2023-08-19 19:58:09 -04:00
|
|
|
response.Data.Buckets = new_buckets
|
2023-07-24 14:28:55 -04:00
|
|
|
if err != nil {
|
2023-08-19 19:58:09 -04:00
|
|
|
response.StatusCode = http.StatusInternalServerError
|
|
|
|
response.Message = "Error during mediaClient.Seed()"
|
|
|
|
response.Error = err.Error()
|
|
|
|
|
|
|
|
return c.JSON(response.StatusCode, response)
|
2023-07-24 14:28:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(new_buckets) == 0 {
|
2023-08-19 19:58:09 -04:00
|
|
|
response.Message = "All buckets already exist"
|
2023-07-24 14:28:55 -04:00
|
|
|
|
|
|
|
} else {
|
2023-08-19 19:58:09 -04:00
|
|
|
response.Message = "Buckets successfully created"
|
2023-07-24 14:28:55 -04:00
|
|
|
}
|
|
|
|
|
2023-08-19 19:58:09 -04:00
|
|
|
response.StatusCode = http.StatusOK
|
|
|
|
|
|
|
|
return c.JSON(response.StatusCode, response)
|
2023-07-24 14:28:55 -04:00
|
|
|
}
|