Merge branch 'refs/heads/feat-file'
This commit is contained in:
commit
1ca9dde471
|
|
@ -22,7 +22,7 @@ func SetUpFileGroup(router *gin.Engine) {
|
||||||
func AddConfigFile(c *gin.Context) {
|
func AddConfigFile(c *gin.Context) {
|
||||||
id, _ := c.Get("id")
|
id, _ := c.Get("id")
|
||||||
user_id := int(id.(float64))
|
user_id := int(id.(float64))
|
||||||
var req proto.ConfigFileReq
|
var req proto.AddConfigFileReq
|
||||||
if err := c.ShouldBind(&req); err == nil {
|
if err := c.ShouldBind(&req); err == nil {
|
||||||
err2 := service.CreateConfigFile(&req, user_id)
|
err2 := service.CreateConfigFile(&req, user_id)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,10 @@ type ConfigFileReq struct {
|
||||||
Content string `json:"content" form:"content"`
|
Content string `json:"content" form:"content"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AddConfigFileReq struct {
|
||||||
|
FileName string `json:"file_name" form:"file_name" required:"true"`
|
||||||
|
FilePath string `json:"file_path" form:"file_path" required:"true"`
|
||||||
|
}
|
||||||
type SearchOneConfigFileResp struct {
|
type SearchOneConfigFileResp struct {
|
||||||
ID uint `json:"id" form:"id"`
|
ID uint `json:"id" form:"id"`
|
||||||
CreatedAt time.Time `json:"created_at" form:"created_at"`
|
CreatedAt time.Time `json:"created_at" form:"created_at"`
|
||||||
|
|
|
||||||
|
|
@ -75,13 +75,17 @@ func CheckUploadRequestParameters(req *proto.FileUploadReq) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateConfigFile(req *proto.ConfigFileReq, userId int) error {
|
func CreateConfigFile(req *proto.AddConfigFileReq, userId int) error {
|
||||||
var err error
|
var err error
|
||||||
user := GetUserByIDWithCache(userId)
|
user := GetUserByIDWithCache(userId)
|
||||||
if user.ID == 0 || user.Role != "admin" {
|
if user.ID == 0 || user.Role != "admin" {
|
||||||
err = fmt.Errorf("user not found or no permission")
|
err = fmt.Errorf("user not found or no permission")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if req.FileName == "" || req.FilePath == "" {
|
||||||
|
err = fmt.Errorf("file name or file path is empty")
|
||||||
|
return err
|
||||||
|
}
|
||||||
//查看系统中是否存在文件,不存在则创建
|
//查看系统中是否存在文件,不存在则创建
|
||||||
file := req.FilePath + "/" + req.FileName
|
file := req.FilePath + "/" + req.FileName
|
||||||
//正则判断文件名是否合法
|
//正则判断文件名是否合法
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue