diff --git a/pkg/serializer/common.go b/pkg/serializer/common.go index 6656100..9819472 100644 --- a/pkg/serializer/common.go +++ b/pkg/serializer/common.go @@ -23,6 +23,10 @@ const ( CodeDBError = 50001 // CodeEncryptError 加密失败 CodeEncryptError = 50002 + // CodePolicyNotAllowed 当前存储策略不允许 + CodePolicyNotAllowed = 50003 + // CodeIOFailed IO操作失败 + CodeIOFailed = 50004 //CodeParamErr 各种奇奇怪怪的参数错误 CodeParamErr = 40001 ) diff --git a/routers/controllers/file.go b/routers/controllers/file.go new file mode 100644 index 0000000..4dc9f7f --- /dev/null +++ b/routers/controllers/file.go @@ -0,0 +1,32 @@ +package controllers + +import ( + "cloudreve/models" + "cloudreve/pkg/serializer" + "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 + } + + name := c.PostForm("name") + path := c.PostForm("path") + + // Source + _, err := c.FormFile("file") + if err != nil { + c.JSON(200, serializer.Err(serializer.CodeIOFailed, "无法获取文件数据", err)) + return + } + + c.JSON(200, serializer.Response{ + Code: 0, + Msg: name + path, + }) +} diff --git a/routers/router.go b/routers/router.go index 584c8b0..d3ffdc4 100644 --- a/routers/router.go +++ b/routers/router.go @@ -46,6 +46,13 @@ func InitRouter() *gin.Engine { user.GET("Me", controllers.UserMe) } + // 文件 + file := auth.Group("File") + { + // 当前登录用户信息 + file.POST("Upload", controllers.FileUpload) + } + } } diff --git a/service/file/upload.go b/service/file/upload.go new file mode 100644 index 0000000..b691ba5 --- /dev/null +++ b/service/file/upload.go @@ -0,0 +1 @@ +package file