mirror of https://github.com/Xhofe/alist
				
				
				
			✨ rename and mkdir api
							parent
							
								
									4a21b6fe1d
								
							
						
					
					
						commit
						dcb4ec695f
					
				| 
						 | 
				
			
			@ -0,0 +1,34 @@
 | 
			
		|||
package file
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/Xhofe/alist/drivers/operate"
 | 
			
		||||
	"github.com/Xhofe/alist/server/common"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type MkdirReq struct {
 | 
			
		||||
	Path string `json:"path"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Mkdir(c *gin.Context) {
 | 
			
		||||
	var req MkdirReq
 | 
			
		||||
	if err := c.ShouldBind(&req); err != nil {
 | 
			
		||||
		common.ErrorResp(c, err, 400)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	account, path_, driver, err := common.ParsePath(req.Path)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		common.ErrorResp(c, err, 500)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if path_ == "/" {
 | 
			
		||||
		common.ErrorStrResp(c, "Folder name can't be empty", 400)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	err = operate.MakeDir(driver, account, path_, true)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		common.ErrorResp(c, err, 500)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	common.SuccessResp(c)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,36 @@
 | 
			
		|||
package file
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/Xhofe/alist/drivers/operate"
 | 
			
		||||
	"github.com/Xhofe/alist/server/common"
 | 
			
		||||
	"github.com/Xhofe/alist/utils"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type RenameReq struct {
 | 
			
		||||
	Path string `json:"path"`
 | 
			
		||||
	Name string `json:"name"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Rename(c *gin.Context) {
 | 
			
		||||
	var req RenameReq
 | 
			
		||||
	if err := c.ShouldBind(&req); err != nil {
 | 
			
		||||
		common.ErrorResp(c, err, 400)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	account, path_, driver, err := common.ParsePath(req.Path)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		common.ErrorResp(c, err, 500)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if path_ == "/" {
 | 
			
		||||
		common.ErrorStrResp(c, "Can't account name here", 400)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	err = operate.Move(driver, account, path_, utils.Join(utils.Dir(path_), req.Name), true)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		common.ErrorResp(c, err, 500)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	common.SuccessResp(c)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -128,6 +128,7 @@ func Proxy(c *gin.Context) {
 | 
			
		|||
		defer func() {
 | 
			
		||||
			_ = res.Body.Close()
 | 
			
		||||
		}()
 | 
			
		||||
		log.Debugf("proxy status: %d", res.StatusCode)
 | 
			
		||||
		w.WriteHeader(res.StatusCode)
 | 
			
		||||
		for h, v := range res.Header {
 | 
			
		||||
			w.Header()[h] = v
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -51,6 +51,8 @@ func InitApiRouter(r *gin.Engine) {
 | 
			
		|||
 | 
			
		||||
		admin.POST("/link", controllers.Link)
 | 
			
		||||
		admin.DELETE("/files", file.DeleteFiles)
 | 
			
		||||
		admin.POST("/mkdir", file.Mkdir)
 | 
			
		||||
		admin.POST("rename", file.Rename)
 | 
			
		||||
	}
 | 
			
		||||
	WebDav(r)
 | 
			
		||||
	Static(r)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue