teldrive/pkg/controller/file.go

103 lines
2 KiB
Go
Raw Normal View History

2023-12-03 03:47:23 +08:00
package controller
import (
"net/http"
"github.com/divyam234/teldrive/pkg/httputil"
"github.com/gin-gonic/gin"
)
func (fc *Controller) CreateFile(c *gin.Context) {
res, err := fc.FileService.CreateFile(c)
if err != nil {
httputil.NewError(c, err.Code, err.Error)
return
}
c.JSON(http.StatusCreated, res)
}
func (fc *Controller) UpdateFile(c *gin.Context) {
res, err := fc.FileService.UpdateFile(c)
if err != nil {
httputil.NewError(c, err.Code, err.Error)
return
}
c.JSON(http.StatusOK, res)
}
func (fc *Controller) GetFileByID(c *gin.Context) {
res, err := fc.FileService.GetFileByID(c)
if err != nil {
httputil.NewError(c, http.StatusNotFound, err)
return
}
c.JSON(http.StatusOK, res)
}
func (fc *Controller) ListFiles(c *gin.Context) {
res, err := fc.FileService.ListFiles(c)
if err != nil {
httputil.NewError(c, err.Code, err.Error)
return
}
c.JSON(http.StatusOK, res)
}
func (fc *Controller) MakeDirectory(c *gin.Context) {
res, err := fc.FileService.MakeDirectory(c)
if err != nil {
httputil.NewError(c, err.Code, err.Error)
return
}
c.JSON(http.StatusOK, res)
}
func (fc *Controller) CopyFile(c *gin.Context) {
res, err := fc.FileService.CopyFile(c)
if err != nil {
httputil.NewError(c, err.Code, err.Error)
return
}
c.JSON(http.StatusOK, res)
}
func (fc *Controller) MoveFiles(c *gin.Context) {
res, err := fc.FileService.MoveFiles(c)
if err != nil {
httputil.NewError(c, err.Code, err.Error)
return
}
c.JSON(http.StatusOK, res)
}
func (fc *Controller) DeleteFiles(c *gin.Context) {
res, err := fc.FileService.DeleteFiles(c)
if err != nil {
httputil.NewError(c, err.Code, err.Error)
return
}
c.JSON(http.StatusOK, res)
}
func (fc *Controller) MoveDirectory(c *gin.Context) {
res, err := fc.FileService.MoveDirectory(c)
if err != nil {
httputil.NewError(c, err.Code, err.Error)
return
}
c.JSON(http.StatusOK, res)
}
func (fc *Controller) GetFileStream(c *gin.Context) {
fc.FileService.GetFileStream(c)
}