package web import ( "fmt" "net/http" "github.com/labstack/echo/v4" "gitnet.fr/deblan/mu-go/internal/api" "gitnet.fr/deblan/mu-go/internal/fs" ) func Stream(e echo.Context, directory, url string) error { files, err := fs.DirectoryFiles(directory, url) path := e.QueryParam("path") if err != nil { return e.JSON(http.StatusInternalServerError, api.ApiError{Error: fmt.Sprintf("%s", err)}) } if path == "" { return e.JSON(http.StatusBadRequest, api.ApiError{Error: "\"path\" query param is missing"}) } for _, file := range files { if file.RelativePath == path { e.Response().Header().Del("Content-Length") http.ServeFile(e.Response(), e.Request(), file.Path) } } return e.JSON(http.StatusNotFound, api.ApiError{Error: "file not found"}) }