Commit b1dc3c45 authored by chenhan wang's avatar chenhan wang
Browse files

fix:response format fixed

parent 48db6746
...@@ -2,6 +2,8 @@ package controller ...@@ -2,6 +2,8 @@ package controller
import ( import (
"backend/model" "backend/model"
"bytes"
"encoding/json"
"io" "io"
"math/rand" "math/rand"
"mime/multipart" "mime/multipart"
...@@ -236,3 +238,13 @@ func TypeComplement(typ string) string { ...@@ -236,3 +238,13 @@ func TypeComplement(typ string) string {
} }
return typ return typ
} }
func myMarshal(data interface{}) (string, error) {
bf := bytes.NewBuffer([]byte{})
jsonEncoder := json.NewEncoder(bf)
jsonEncoder.SetEscapeHTML(false)
if err := jsonEncoder.Encode(data); err != nil {
return "", err
}
return bf.String(), nil
}
...@@ -3,7 +3,6 @@ package controller ...@@ -3,7 +3,6 @@ package controller
import ( import (
"backend/app/response" "backend/app/response"
"backend/model" "backend/model"
"encoding/json"
"net/http" "net/http"
"time" "time"
...@@ -74,13 +73,13 @@ func FileUp(c echo.Context) error { ...@@ -74,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 := json.Marshal(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, "文件上传成功", string(dataj)) return response.SendResponse(c, http.StatusOK, "文件上传成功", dataj)
} }
/* /*
...@@ -115,12 +114,11 @@ func Down(c echo.Context) error { ...@@ -115,12 +114,11 @@ func Down(c echo.Context) error {
return response.SendResponse(c, http.StatusForbidden, cookieMsg+"error:密码错误", "") //403 return response.SendResponse(c, http.StatusForbidden, cookieMsg+"error:密码错误", "") //403
case 1: // 鉴权通过 case 1: // 鉴权通过
Data := new(Msg) Data := new(Msg)
Data.Content = model.Find1(info.Url, "content") // 文件内容 Data.Content = model.Find1(info.Url, "content") // 文件内容
Data.Type = model.Find1(info.Url, "TextType") // 文件类型 Data.Type = GetFileContentType(model.Find1(info.Url, "TextType")) // 文件类型
Data.Type = GetFileContentType(Data.Type)
Data.Name = model.Find1(info.Url, "TextName") Data.Name = model.Find1(info.Url, "TextName")
dataj, _ := json.Marshal(Data) // 文件名 dataj, _ := myMarshal(Data) // 文件名
return response.SendResponse(c, http.StatusOK, cookieMsg+"success", string(dataj)) // 返回数据 return response.SendResponse(c, http.StatusOK, cookieMsg+"success", dataj) // 返回数据
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:
......
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