Allow accessing parent folders easily

This commit is contained in:
raul 2024-06-17 12:46:04 +02:00
parent d0cdcae333
commit 65860664b6
1 changed files with 19 additions and 5 deletions

View File

@ -77,14 +77,28 @@ func listFiles(c *gin.Context) {
return
}
var list string
for _, v := range resp.FileList.File {
isDir := ""
if v.IsFolder == true {
isDir = "/"
currentLocation := fmt.Sprintf("Current location: %v<br>", path)
list += currentLocation
split := strings.Split(path, "/")
parentFolder := strings.Join(split[:len(split)-1], "/")
if parentFolder == "" {
parentFolder = "/"
}
entry := fmt.Sprintf("<p><a hx-post=\"/ls/%v\" hx-target=\"#files\" hx-vals='{\"cmd\": \"%v\"}' id=\"pointer\">%v%v</a></p>",
client.ClientID, v.FullPath, v.FullPath, isDir)
parentFolderLink := fmt.Sprintf("<a hx-post=\"/ls/%v\" hx-target=\"#files\" hx-vals='{\"cmd\": \"%v\"}' id=\"pointer\">../</a><br>",
client.ClientID, parentFolder)
list += parentFolderLink
for _, v := range resp.FileList.File {
if v.IsFolder == true {
entry := fmt.Sprintf("<a hx-post=\"/ls/%v\" hx-target=\"#files\" hx-vals='{\"cmd\": \"%v\"}' id=\"pointer\">[DIR] %v</a><br>",
client.ClientID, v.FullPath, v.Name)
list += entry
} else {
entry := fmt.Sprintf("<a id=\"pointer\">%v</a><br>", v.Name)
list += entry
}
}
c.String(http.StatusOK, list)