add new function to read files in workspace
This commit is contained in:
@@ -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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user