mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Add: route for uploading file
This commit is contained in:
32
routers/controllers/file.go
Normal file
32
routers/controllers/file.go
Normal file
@@ -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,
|
||||
})
|
||||
}
|
||||
@@ -46,6 +46,13 @@ func InitRouter() *gin.Engine {
|
||||
user.GET("Me", controllers.UserMe)
|
||||
}
|
||||
|
||||
// 文件
|
||||
file := auth.Group("File")
|
||||
{
|
||||
// 当前登录用户信息
|
||||
file.POST("Upload", controllers.FileUpload)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user