From 093c55616cee54356c610a9055d95e205445ab5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Z=C3=BCrcher?= Date: Tue, 17 Feb 2026 12:07:56 +0100 Subject: [PATCH] add new function to read files in workspace --- handlers/workspace.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/handlers/workspace.go b/handlers/workspace.go index 3f2ab9a..4db252a 100644 --- a/handlers/workspace.go +++ b/handlers/workspace.go @@ -4,8 +4,10 @@ import ( "fmt" "net/http" "os" + "path/filepath" "slices" "strconv" + "strings" "gitea.tecamino.com/paadi/access-handler/models" "github.com/gin-gonic/gin" @@ -174,3 +176,33 @@ func (aH *AccessHandler) DeleteWorkspace(c *gin.Context) { "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, + }) +}