mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-05-07 20:59:37 -05:00
38 lines
969 B
Go
38 lines
969 B
Go
package fs
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/shroff/phylum/server/internal/api/authenticator"
|
|
"github.com/shroff/phylum/server/internal/api/v1/responses"
|
|
"github.com/shroff/phylum/server/internal/core"
|
|
)
|
|
|
|
type moveParams struct {
|
|
Src string `json:"src" form:"src" binding:"required"`
|
|
Dest string `json:"dest" form:"dest" binding:"required"`
|
|
Conflict core.ResourceBindConflictResolution `json:"conflict" form:"conflict"`
|
|
}
|
|
|
|
func handleMoveRequest(c *gin.Context) {
|
|
var params moveParams
|
|
err := c.ShouldBind(¶ms)
|
|
if err != nil {
|
|
err = c.BindQuery(¶ms)
|
|
if err != nil {
|
|
panic(errInvalidParams)
|
|
}
|
|
}
|
|
|
|
fs := authenticator.GetFileSystem(c)
|
|
r, err := fs.ResourceByPathWithRoot(params.Src)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
if r, _, err := fs.Move(r, params.Dest, params.Conflict); err != nil {
|
|
panic(err)
|
|
} else {
|
|
c.JSON(200, responses.ResourceFromFS(r))
|
|
}
|
|
}
|