feat: 合并服务端程序代码至主分支

This commit is contained in:
539943419 committed 2024-12-19 22:32:27 +08:00
1 parent 47590ec0db
commit d6816925ed
19 files changed
+672 -4

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
package api
import (
// "fmt"
"net/http"
"os"
"path/filepath"
"github.com/gin-gonic/gin"
"miao-directory/fsOperateEventCenter"
)
func CutHandler(fsOperateEventCenter *fsOperateEventCenter.FsOperateEventCenter) gin.HandlerFunc {
return func(c *gin.Context) {
var req struct {
NewPath string `json:"newPath"`
}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})
return
}
decodedPath, err := filepath.Abs(filepath.Join(staticPath, c.Param("path")))
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Unable to access path"})
return
}
newPath := filepath.Join(staticPath, req.NewPath, filepath.Base(decodedPath))
eventId := fsOperateEventCenter.Push(func() error {
return os.Rename(decodedPath, newPath)
})
c.JSON(http.StatusOK, gin.H{"eventId": eventId})
}
}