2023-05-05 18:59:53 -04:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"git.agecem.com/agecem/babillard/data"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
2023-12-04 19:05:56 -05:00
|
|
|
type ContenuHandler struct {
|
2023-12-04 21:23:25 -05:00
|
|
|
ContenuDir string
|
2023-12-04 19:05:56 -05:00
|
|
|
}
|
|
|
|
|
2023-12-04 21:23:25 -05:00
|
|
|
func NewContenuHandler(contenuDir string) (h ContenuHandler) {
|
|
|
|
h.ContenuDir = contenuDir
|
2023-12-04 19:05:56 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h ContenuHandler) HandleAPIContenuList(c echo.Context) error {
|
2023-12-04 21:23:25 -05:00
|
|
|
contenu_dir := h.ContenuDir
|
2023-05-05 18:59:53 -04:00
|
|
|
|
|
|
|
files, err := data.ListContenu(contenu_dir)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
return c.JSON(http.StatusInternalServerError, map[string]string{
|
|
|
|
"message": "Internal Server Error",
|
|
|
|
"error": err.Error(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.String(http.StatusOK, strings.Join(files, ";"))
|
|
|
|
}
|
|
|
|
|
2023-12-04 19:05:56 -05:00
|
|
|
func (h ContenuHandler) HandleAPIContenuFile(c echo.Context) error {
|
2023-05-05 18:59:53 -04:00
|
|
|
filename := c.Param("filename")
|
2023-12-04 21:23:25 -05:00
|
|
|
contenu_dir := h.ContenuDir
|
2023-05-05 18:59:53 -04:00
|
|
|
|
|
|
|
if filename == ".gitkeep" {
|
|
|
|
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.File(fmt.Sprintf("%s/%s", contenu_dir, filename))
|
|
|
|
}
|