From e7585a638fdfe5bfb8d4b6104566274389ef6f6d Mon Sep 17 00:00:00 2001 From: yangduo Date: Mon, 12 Aug 2024 15:41:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=82=AE=E4=BB=B6=E8=BF=87?= =?UTF-8?q?=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/adminserver/api/v1/system/mail.go | 31 ++++++++++++++++++++++++ server/adminserver/mt/Item.go | 27 +++++++++++++++++++++ server/adminserver/mt/export.go | 6 +++++ 3 files changed, 64 insertions(+) create mode 100644 server/adminserver/mt/Item.go diff --git a/server/adminserver/api/v1/system/mail.go b/server/adminserver/api/v1/system/mail.go index 911a974a..d42f08a8 100644 --- a/server/adminserver/api/v1/system/mail.go +++ b/server/adminserver/api/v1/system/mail.go @@ -6,6 +6,7 @@ import ( "main/common" "main/constant" "main/model/system" + "main/mt" "net/http" "q5" @@ -141,6 +142,10 @@ func (this *MailApi) AddMail(c *gin.Context) { return } + if !this.CheckAttachment(reqJson.Attachments, c) { + return + } + s := c.MustGet("session").(common.Session) acc := s.GetAccountAddress() @@ -222,6 +227,10 @@ func (this *MailApi) EditMail(c *gin.Context) { return } + if !this.CheckAttachment(reqJson.Attachments, c) { + return + } + nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) mail.MailId = reqJson.MailId mail.MailType = reqJson.MailType @@ -289,3 +298,25 @@ func (this *MailApi) DelMail(c *gin.Context) { "message": "", }) } + +func (this *MailApi) CheckAttachment(list []common.Attachment, c *gin.Context) bool { + if len(list) > 7 { + c.JSON(http.StatusOK, gin.H{ + "code": 2, + "message": "附件过多", + }) + return false + } + + for _, item := range list { + if !mt.Table.Item.Search(item.ItemId) { + c.JSON(http.StatusOK, gin.H{ + "code": 2, + "message": "item id error:" + q5.SafeToString(item.ItemId), + }) + return false + } + } + + return true +} diff --git a/server/adminserver/mt/Item.go b/server/adminserver/mt/Item.go new file mode 100644 index 00000000..33e0261f --- /dev/null +++ b/server/adminserver/mt/Item.go @@ -0,0 +1,27 @@ +package mt + +import ( + "f5" + "main/mtb" +) + +type Item struct { + mtb.Item +} + +type ItemTable struct { + f5.IdMetaTable[Item] +} + +func (this *ItemTable) Search(id int32) bool { + // _, ret := it.itemIdHash[id] + ret := false + this.Traverse(func(ele *Item) bool { + if ele.GetId() == id { + ret = true + return false + } + return true + }) + return ret +} diff --git a/server/adminserver/mt/export.go b/server/adminserver/mt/export.go index 46214206..88927028 100644 --- a/server/adminserver/mt/export.go +++ b/server/adminserver/mt/export.go @@ -16,6 +16,7 @@ type table struct { NFTDb *NFTDbTable Permission *PermissionTable ConfDb *ConfDbTable + Item *ItemTable } var Table = f5.New(func(this *table) { @@ -69,4 +70,9 @@ var Table = f5.New(func(this *table) { }) this.Permission = new(PermissionTable) + + this.Item = f5.New(func(this *ItemTable) { + this.FileName = "../res/item@item.json" + this.PrimKey = "id" + }) })