Cloudreve/routers/controllers/file.go

28 lines
664 B
Go
Raw Normal View History

2019-11-15 18:12:34 +08:00
package controllers
import (
2019-11-16 16:11:37 +08:00
"github.com/HFO4/cloudreve/models"
"github.com/HFO4/cloudreve/pkg/serializer"
"github.com/HFO4/cloudreve/service/file"
2019-11-15 18:12:34 +08:00
"github.com/gin-gonic/gin"
)
// FileUpload 本地策略文件上传
func FileUpload(c *gin.Context) {
// 非本地策略时拒绝上传
if user, ok := c.Get("user"); ok && user.(*model.User).Policy.Type != "local" {
c.JSON(200, serializer.Err(serializer.CodePolicyNotAllowed, "当前上传策略无法使用", nil))
return
}
2019-11-16 13:37:42 +08:00
var service file.UploadService
2019-11-15 18:12:34 +08:00
2019-11-16 13:37:42 +08:00
if err := c.ShouldBind(&service); err == nil {
res := service.Upload(c)
c.JSON(200, res)
} else {
c.JSON(200, ErrorResponse(err))
2019-11-15 18:12:34 +08:00
}
}