This commit is contained in:
539943419 committed 2024-08-23 12:35:43 +08:00
commit acd7a8b5f0
14 files changed
+581

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
package api
import (
"github.com/gin-gonic/gin"
"net/http"
"os"
"path/filepath"
)
func MkdirHandler(c *gin.Context) {
var request struct {
FolderName string `json:"folderName"`
}
if err := c.ShouldBindJSON(&request); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"message": "failed", "error": err.Error()})
return
}
decodedPath, err := filepath.Abs(filepath.Join(staticPath, c.Param("path")))
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"message": "failed", "error": "Unable to access path"})
return
}
mkdirPath := filepath.Join(decodedPath, request.FolderName)
if err := os.MkdirAll(mkdirPath, os.ModePerm); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"message": "failed", "error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"message": "success"})
}