|
@@ -24,6 +24,7 @@ import (
|
|
"io"
|
|
"io"
|
|
"math"
|
|
"math"
|
|
"net/http"
|
|
"net/http"
|
|
|
|
+ "net/textproto"
|
|
"net/url"
|
|
"net/url"
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
@@ -31,19 +32,67 @@ import (
|
|
"github.com/88250/gulu"
|
|
"github.com/88250/gulu"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/imroc/req/v3"
|
|
"github.com/imroc/req/v3"
|
|
|
|
+ "github.com/siyuan-note/logging"
|
|
"github.com/siyuan-note/siyuan/kernel/util"
|
|
"github.com/siyuan-note/siyuan/kernel/util"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+type File struct {
|
|
|
|
+ Filename string
|
|
|
|
+ Header textproto.MIMEHeader
|
|
|
|
+ Size int64
|
|
|
|
+ Content string
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type MultipartForm struct {
|
|
|
|
+ Value map[string][]string
|
|
|
|
+ File map[string][]File
|
|
|
|
+}
|
|
|
|
+
|
|
func echo(c *gin.Context) {
|
|
func echo(c *gin.Context) {
|
|
ret := gulu.Ret.NewResult()
|
|
ret := gulu.Ret.NewResult()
|
|
defer c.JSON(http.StatusOK, ret)
|
|
defer c.JSON(http.StatusOK, ret)
|
|
|
|
|
|
- password, passwordSet := c.Request.URL.User.Password()
|
|
|
|
|
|
+ var (
|
|
|
|
+ password string
|
|
|
|
+ passwordSet bool
|
|
|
|
+ multipartForm *MultipartForm
|
|
|
|
+ rawData any
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ password, passwordSet = c.Request.URL.User.Password()
|
|
|
|
+
|
|
|
|
+ if form, err := c.MultipartForm(); nil != err || nil == form {
|
|
|
|
+ multipartForm = nil
|
|
|
|
+ } else {
|
|
|
|
+ multipartForm = &MultipartForm{
|
|
|
|
+ Value: form.Value,
|
|
|
|
+ File: map[string][]File{},
|
|
|
|
+ }
|
|
|
|
+ for k, handlers := range form.File {
|
|
|
|
+ files := make([]File, len(handlers))
|
|
|
|
+ multipartForm.File[k] = files
|
|
|
|
+ for i, handler := range handlers {
|
|
|
|
+ files[i].Filename = handler.Filename
|
|
|
|
+ files[i].Header = handler.Header
|
|
|
|
+ files[i].Size = handler.Size
|
|
|
|
+ if file, err := handler.Open(); nil != err {
|
|
|
|
+ logging.LogWarnf("echo open form [%s] file [%s] error: %s", k, handler.Filename, err.Error())
|
|
|
|
+ } else {
|
|
|
|
+ content := make([]byte, handler.Size)
|
|
|
|
+ if _, err := file.Read(content); nil != err {
|
|
|
|
+ logging.LogWarnf("echo read form [%s] file [%s] error: %s", k, handler.Filename, err.Error())
|
|
|
|
+ } else {
|
|
|
|
+ files[i].Content = base64.StdEncoding.EncodeToString(content)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- var rawData any
|
|
|
|
if data, err := c.GetRawData(); nil == err {
|
|
if data, err := c.GetRawData(); nil == err {
|
|
rawData = base64.StdEncoding.EncodeToString(data)
|
|
rawData = base64.StdEncoding.EncodeToString(data)
|
|
} else {
|
|
} else {
|
|
|
|
+ logging.LogWarnf("echo get raw data error: %s", err.Error())
|
|
rawData = nil
|
|
rawData = nil
|
|
}
|
|
}
|
|
c.Request.ParseForm()
|
|
c.Request.ParseForm()
|
|
@@ -73,7 +122,7 @@ func echo(c *gin.Context) {
|
|
"Host": c.Request.Host,
|
|
"Host": c.Request.Host,
|
|
"Form": c.Request.Form,
|
|
"Form": c.Request.Form,
|
|
"PostForm": c.Request.PostForm,
|
|
"PostForm": c.Request.PostForm,
|
|
- "MultipartForm": c.Request.MultipartForm,
|
|
|
|
|
|
+ "MultipartForm": multipartForm,
|
|
"Trailer": c.Request.Trailer,
|
|
"Trailer": c.Request.Trailer,
|
|
"RemoteAddr": c.Request.RemoteAddr,
|
|
"RemoteAddr": c.Request.RemoteAddr,
|
|
"TLS": c.Request.TLS,
|
|
"TLS": c.Request.TLS,
|