Commit 1bc30dc4 authored by chenhan wang's avatar chenhan wang
Browse files

fix:fix the format of response's data,change it to fully json format

parent ec8d3984
...@@ -61,7 +61,7 @@ func FileUp(c echo.Context) error { ...@@ -61,7 +61,7 @@ func FileUp(c echo.Context) error {
return err return err
} }
info.Name = file.Filename info.Name = file.Filename
data := new(Msg2) data := new(response.Msg2)
info.Content, data.Size, _ = FileRead(file) info.Content, data.Size, _ = FileRead(file)
info.MaxView = uint(Settings.MaxDefaultView) info.MaxView = uint(Settings.MaxDefaultView)
...@@ -73,13 +73,13 @@ func FileUp(c echo.Context) error { ...@@ -73,13 +73,13 @@ func FileUp(c echo.Context) error {
// 更新数据库 // 更新数据库
_, data.Url = DBupdate(c, info) // 不分配uid _, data.Url = DBupdate(c, info) // 不分配uid
data.Name = info.Name data.Name = info.Name
dataj, err := myMarshal(data) //dataj, err := myMarshal(data)
if err != nil { if err != nil {
logrus.Println(err) logrus.Println(err)
return err return err
} }
//return response.SendResponse2(c, http.StatusOK, "文件上传成功", info.TextName, GetTextContentType(info.TextType), url) //return response.SendResponse2(c, http.StatusOK, "文件上传成功", info.TextName, GetTextContentType(info.TextType), url)
return response.SendResponse(c, http.StatusOK, "文件上传成功", dataj) return response.SendResponse2(c, http.StatusOK, "文件上传成功", *data)
} }
/* /*
...@@ -103,6 +103,7 @@ func Down(c echo.Context) error { ...@@ -103,6 +103,7 @@ func Down(c echo.Context) error {
SetCookie(c, cookie, IdGen(8), 1800, time.Time{}) SetCookie(c, cookie, IdGen(8), 1800, time.Time{})
} }
//c.Request().URL.
// 鉴权 // 鉴权
stat := Autheticate(cookie, info.Url, info.Passwd, time.Now().Add(1800)) // 包含创建链接Createlink stat := Autheticate(cookie, info.Url, info.Passwd, time.Now().Add(1800)) // 包含创建链接Createlink
// response // response
...@@ -111,12 +112,13 @@ func Down(c echo.Context) error { ...@@ -111,12 +112,13 @@ func Down(c echo.Context) error {
case 0: case 0:
return response.SendResponse(c, http.StatusForbidden, cookieMsg+"error:密码错误", info.Url) //403 return response.SendResponse(c, http.StatusForbidden, cookieMsg+"error:密码错误", info.Url) //403
case 1: // 鉴权通过 case 1: // 鉴权通过
Data := new(Msg) Data := new(response.Msg)
Data.Content = model.Find1(info.Url, "content") // 文件内容 Data.Content = model.Find1(info.Url, "content") // 文件内容
Data.Type = GetFileContentType(model.Find1(info.Url, "TextType")) // 文件类型 Data.Type = GetFileContentType(model.Find1(info.Url, "TextType")) // 文件类型
Data.Name = model.Find1(info.Url, "TextName") Data.Name = model.Find1(info.Url, "TextName")
dataj, _ := myMarshal(Data) // 文件名 Data.Url = info.Url
return response.SendResponse(c, http.StatusOK, cookieMsg+"success", dataj) // 返回数据 //dataj, _ := myMarshal(Data) // 文件名
return response.SendResponse1(c, http.StatusOK, cookieMsg+"success", *Data) // 返回数据
case 2: case 2:
return response.SendResponse(c, http.StatusGone, cookieMsg+"error:内容过期", "") //410 return response.SendResponse(c, http.StatusGone, cookieMsg+"error:内容过期", "") //410
case 3: case 3:
......
...@@ -22,18 +22,6 @@ type Download struct { ...@@ -22,18 +22,6 @@ type Download struct {
Url string `json:"Url" form:"Url" query:"Url"` Url string `json:"Url" form:"Url" query:"Url"`
} }
type Msg struct {
Name string
Type string
Content string
}
type Msg2 struct {
Url string
Name string
Size int
}
// 从config文件获取 // 从config文件获取
type Setting struct { type Setting struct {
Url string // 配置的域名 Url string // 配置的域名
......
...@@ -6,12 +6,37 @@ import ( ...@@ -6,12 +6,37 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
type Msg struct {
Name string
Type string
Content string
Url string
}
type Msg2 struct {
Url string
Name string
Size int
}
type Response struct { type Response struct {
Code int `json:"Code"` Code int `json:"Code"`
Msg string `json:"Msg"` Msg string `json:"Msg"`
Data interface{} `json:"Data"` Data interface{} `json:"Data"`
} }
type Response1 struct {
Code int `json:"Code"`
Msg string `json:"Msg"`
Data Msg `json:"Data"`
}
type Response2 struct {
Code int `json:"Code"`
Msg string `json:"Msg"`
Data Msg2 `json:"Data"`
}
func SendResponse(c echo.Context, code int, msg string, data ...interface{}) error { func SendResponse(c echo.Context, code int, msg string, data ...interface{}) error {
return c.JSON(http.StatusOK, Response{ return c.JSON(http.StatusOK, Response{
Code: code, Code: code,
...@@ -20,6 +45,22 @@ func SendResponse(c echo.Context, code int, msg string, data ...interface{}) err ...@@ -20,6 +45,22 @@ func SendResponse(c echo.Context, code int, msg string, data ...interface{}) err
}) })
} }
func SendResponse1(c echo.Context, code int, msg string, data Msg) error {
return c.JSON(http.StatusOK, Response1{
Code: code,
Msg: msg,
Data: data,
})
}
func SendResponse2(c echo.Context, code int, msg string, data Msg2) error {
return c.JSON(http.StatusOK, Response2{
Code: code,
Msg: msg,
Data: data,
})
}
// 返回err // 返回err
func SendResponse4(c echo.Context, err error) error { func SendResponse4(c echo.Context, err error) error {
return c.JSON(http.StatusBadRequest, err.Error()) return c.JSON(http.StatusBadRequest, err.Error())
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment