add new function to read files in workspace

This commit is contained in:
Adrian Zürcher
2026-02-17 12:07:56 +01:00
parent a99189b31a
commit 093c55616c

View File

@@ -4,8 +4,10 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"os" "os"
"path/filepath"
"slices" "slices"
"strconv" "strconv"
"strings"
"gitea.tecamino.com/paadi/access-handler/models" "gitea.tecamino.com/paadi/access-handler/models"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@@ -174,3 +176,33 @@ func (aH *AccessHandler) DeleteWorkspace(c *gin.Context) {
"message": "workspace(s) deleted", "message": "workspace(s) deleted",
}) })
} }
func (aH *AccessHandler) ReadWorkspaceData(c *gin.Context) {
var workspace models.Workspace
err := c.ShouldBindBodyWithJSON(&workspace)
if err != nil {
aH.logger.Error("ReadWorkspaceData", err)
c.JSON(http.StatusBadRequest, nil)
return
}
files, err := os.ReadDir(workspace.Uuid.String())
if err != nil {
aH.logger.Error("ReadWorkspaceData", err)
c.JSON(http.StatusBadRequest, nil)
return
}
var response []string
for _, f := range files {
if f.IsDir() || !strings.Contains(filepath.Ext(f.Name()), ".db") {
continue
}
response = append(response, f.Name())
}
c.JSON(http.StatusOK, gin.H{
"data": response,
})
}