Skip to content

Commit 6add209

Browse files
奇淼(piexlmaxsongzhibin97iceDayshedeqiang
authored
v2.5.1 beta2 (#1048)
* 修复日志中间件报文过大的报错问题 * 修复 Token 失效后导致的白屏问题 * 增加自动创建插件模板功能 * 密码加密方式改为 hash * 增加刷新防抖 Co-authored-by: songzhibin97 <[email protected]> Co-authored-by: icedays <[email protected]> Co-authored-by: hedeqiang <[email protected]>
1 parent 843e5a9 commit 6add209

File tree

42 files changed

+635
-43
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+635
-43
lines changed

server/api/v1/system/sys_auto_code.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,26 @@ func (autoApi *AutoCodeApi) DelPackage(c *gin.Context) {
211211
response.OkWithMessage("删除成功", c)
212212
}
213213
}
214+
215+
// DelPackage
216+
// @Tags AutoCode
217+
// @Summary 创建插件模板
218+
// @Security ApiKeyAuth
219+
// @accept application/json
220+
// @Produce application/json
221+
// @Param data body system.SysAutoCode true "创建插件模板"
222+
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "创建插件模板成功"
223+
// @Router /autoCode/createPlug [post]
224+
func (autoApi *AutoCodeApi) AutoPlug(c *gin.Context) {
225+
var a system.AutoPlugReq
226+
_ = c.ShouldBindJSON(&a)
227+
a.Snake = strings.ToLower(a.PlugName)
228+
a.NeedModel = a.HasRequest || a.HasResponse
229+
err := autoCodeService.CreatePlug(a)
230+
if err != nil {
231+
global.GVA_LOG.Error("预览失败!", zap.Error(err))
232+
response.FailWithMessage("预览失败", c)
233+
} else {
234+
response.Ok(c)
235+
}
236+
}

server/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ autocode:
111111
# 请不要手动配置,他会在项目加载的时候识别出根路径
112112
root: ""
113113
server: /server
114+
server-plug: /plugin/%s
114115
server-api: /api/v1/%s
115116
server-initialize: /initialize
116117
server-model: /model/%s

server/config/auto_code.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type Autocode struct {
55
Root string `mapstructure:"root" json:"root" yaml:"root"`
66
Server string `mapstructure:"server" json:"server" yaml:"server"`
77
SApi string `mapstructure:"server-api" json:"server-api" yaml:"server-api"`
8+
SPlug string `mapstructure:"server-plug" json:"server-plug" yaml:"server-plug"`
89
SInitialize string `mapstructure:"server-initialize" json:"server-initialize" yaml:"server-initialize"`
910
SModel string `mapstructure:"server-model" json:"server-model" yaml:"server-model"`
1011
SRequest string `mapstructure:"server-request" json:"server-request" yaml:"server-request"`

server/middleware/operation.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/url"
99
"strconv"
1010
"strings"
11+
"sync"
1112
"time"
1213

1314
"github.com/flipped-aurora/gin-vue-admin/server/utils"
@@ -21,6 +22,14 @@ import (
2122

2223
var operationRecordService = service.ServiceGroupApp.SystemServiceGroup.OperationRecordService
2324

25+
var respPool sync.Pool
26+
27+
func init() {
28+
respPool.New = func() interface{} {
29+
return make([]byte, 1024)
30+
}
31+
}
32+
2433
func OperationRecord() gin.HandlerFunc {
2534
return func(c *gin.Context) {
2635
var body []byte
@@ -64,12 +73,18 @@ func OperationRecord() gin.HandlerFunc {
6473
Body: string(body),
6574
UserID: userId,
6675
}
76+
6777
// 上传文件时候 中间件日志进行裁断操作
6878
if strings.Index(c.GetHeader("Content-Type"), "multipart/form-data") > -1 {
69-
if len(record.Body) > 512 {
70-
record.Body = "File or Length out of limit"
79+
if len(record.Body) > 1024 {
80+
// 截断
81+
newBody := respPool.Get().([]byte)
82+
copy(newBody, record.Body)
83+
record.Body = string(newBody)
84+
defer respPool.Put(newBody[:0])
7185
}
7286
}
87+
7388
writer := responseBodyWriter{
7489
ResponseWriter: c.Writer,
7590
body: &bytes.Buffer{},
@@ -85,6 +100,24 @@ func OperationRecord() gin.HandlerFunc {
85100
record.Latency = latency
86101
record.Resp = writer.body.String()
87102

103+
if strings.Index(c.Writer.Header().Get("Pragma"), "public") > -1 ||
104+
strings.Index(c.Writer.Header().Get("Expires"), "0") > -1 ||
105+
strings.Index(c.Writer.Header().Get("Cache-Control"), "must-revalidate, post-check=0, pre-check=0") > -1 ||
106+
strings.Index(c.Writer.Header().Get("Content-Type"), "application/force-download") > -1 ||
107+
strings.Index(c.Writer.Header().Get("Content-Type"), "application/octet-stream") > -1 ||
108+
strings.Index(c.Writer.Header().Get("Content-Type"), "application/vnd.ms-excel") > -1 ||
109+
strings.Index(c.Writer.Header().Get("Content-Type"), "application/download") > -1 ||
110+
strings.Index(c.Writer.Header().Get("Content-Disposition"), "attachment") > -1 ||
111+
strings.Index(c.Writer.Header().Get("Content-Transfer-Encoding"), "binary") > -1 {
112+
if len(record.Resp) > 1024 {
113+
// 截断
114+
newBody := respPool.Get().([]byte)
115+
copy(newBody, record.Resp)
116+
record.Body = string(newBody)
117+
defer respPool.Put(newBody[:0])
118+
}
119+
}
120+
88121
if err := operationRecordService.CreateSysOperationRecord(record); err != nil {
89122
global.GVA_LOG.Error("create operation record error:", zap.Error(err))
90123
}

server/model/system/sys_auto_code.go

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ type AutoCodeStruct struct {
1717
AutoMoveFile bool `json:"autoMoveFile"` // 是否自动移动文件
1818
Fields []*Field `json:"fields"`
1919
DictTypes []string `json:"-"`
20-
Package string `json:"package"`
21-
PackageT string `json:"-"`
20+
Package string `json:"package"`
21+
PackageT string `json:"-"`
2222
}
2323

2424
type Field struct {
@@ -38,6 +38,31 @@ var AutoMoveErr error = errors.New("创建代码成功并移动文件成功")
3838
type SysAutoCode struct {
3939
global.GVA_MODEL
4040
PackageName string `json:"packageName" gorm:"comment:包名"`
41-
Label string `json:"label" gorm:"comment:展示名"`
41+
Label string `json:"label" gorm:"comment:展示名"`
4242
Desc string `json:"desc" gorm:"comment:描述"`
4343
}
44+
45+
type AutoPlugReq struct {
46+
PlugName string `json:"plugName"` // 必然大写开头
47+
Snake string `json:"snake"` // 后端自动转为 snake
48+
RouterGroup string `json:"routerGroup"`
49+
HasGlobal bool `json:"hasGlobal"`
50+
HasRequest bool `json:"hasRequest"`
51+
HasResponse bool `json:"hasResponse"`
52+
NeedModel bool `json:"needModel"`
53+
Global []struct {
54+
Key string `json:"key"`
55+
Type string `json:"type"`
56+
Desc string `json:"desc"`
57+
} `json:"global"`
58+
Request []struct {
59+
Key string `json:"key"`
60+
Type string `json:"type"`
61+
Desc string `json:"desc"`
62+
} `json:"request"`
63+
Response []struct {
64+
Key string `json:"key"`
65+
Type string `json:"type"`
66+
Desc string `json:"desc"`
67+
} `json:"response"`
68+
}

0 commit comments

Comments
 (0)