Cloudreve/routers/controllers/objects.go

85 lines
1.9 KiB
Go
Raw Normal View History

2019-11-30 02:09:56 -05:00
package controllers
import (
"context"
"github.com/cloudreve/Cloudreve/v3/service/explorer"
2019-11-30 02:09:56 -05:00
"github.com/gin-gonic/gin"
)
// Delete 删除文件或目录
func Delete(c *gin.Context) {
// 创建上下文
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var service explorer.ItemIDService
2019-11-30 02:09:56 -05:00
if err := c.ShouldBindJSON(&service); err == nil {
res := service.Delete(ctx, c)
c.JSON(200, res)
} else {
c.JSON(200, ErrorResponse(err))
}
}
2019-12-01 05:31:29 -05:00
// Move 移动文件或目录
func Move(c *gin.Context) {
// 创建上下文
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var service explorer.ItemMoveService
if err := c.ShouldBindJSON(&service); err == nil {
res := service.Move(ctx, c)
c.JSON(200, res)
} else {
c.JSON(200, ErrorResponse(err))
}
}
2019-12-03 01:20:23 -05:00
// Copy 复制文件或目录
func Copy(c *gin.Context) {
// 创建上下文
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var service explorer.ItemMoveService
if err := c.ShouldBindJSON(&service); err == nil {
res := service.Copy(ctx, c)
c.JSON(200, res)
} else {
c.JSON(200, ErrorResponse(err))
}
}
2019-12-07 02:54:07 -05:00
// Rename 重命名文件或目录
func Rename(c *gin.Context) {
// 创建上下文
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var service explorer.ItemRenameService
if err := c.ShouldBindJSON(&service); err == nil {
res := service.Rename(ctx, c)
c.JSON(200, res)
} else {
c.JSON(200, ErrorResponse(err))
}
}
2021-03-11 01:50:02 -05:00
// Rename 重命名文件或目录
func GetProperty(c *gin.Context) {
// 创建上下文
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var service explorer.ItemPropertyService
service.ID = c.Param("id")
if err := c.ShouldBindQuery(&service); err == nil {
res := service.GetProperty(ctx, c)
c.JSON(200, res)
} else {
c.JSON(200, ErrorResponse(err))
}
}