Skip to content

Commit

Permalink
修复可能的 context 泄露以及遗漏的错误处理 (#1965)
Browse files Browse the repository at this point in the history
* 修复结构体 tag 字段的错误使用
  • Loading branch information
huiyifyj authored Dec 17, 2024
1 parent f6c2ce4 commit 2bf423b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.idea/
/web/node_modules
/web/dist

Expand Down Expand Up @@ -33,3 +32,11 @@ server/uploads/
*.iml
web/.pnpm-debug.log
web/pnpm-lock.yaml

# binary files
*.exe

# SQLite database files
*.db
*.sqlite
*.sqlite3
8 changes: 4 additions & 4 deletions server/plugin/announcement/model/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
// Info 公告 结构体
type Info struct {
global.GVA_MODEL
Title string `json:"title" form:"title" gorm:"column:title;comment:公告标题;"` //标题
Content string `json:"content" form:"content" gorm:"column:content;comment:公告内容;type:text;"` //内容
UserID *int `json:"userID" form:"userID" gorm:"column:user_id;comment:发布者;"` //作者
Attachments datatypes.JSON `json:"attachments" form:"attachments" gorm:"column:attachments;comment:相关附件;"swaggertype:"array,object"` //附件
Title string `json:"title" form:"title" gorm:"column:title;comment:公告标题;"` //标题
Content string `json:"content" form:"content" gorm:"column:content;comment:公告内容;type:text;"` //内容
UserID *int `json:"userID" form:"userID" gorm:"column:user_id;comment:发布者;"` //作者
Attachments datatypes.JSON `json:"attachments" form:"attachments" gorm:"column:attachments;comment:相关附件;" swaggertype:"array,object"` //附件
}

// TableName 公告 Info自定义表名 gva_announcements_info
Expand Down
6 changes: 3 additions & 3 deletions server/service/system/sys_casbin.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ func (casbinService *CasbinService) UpdateCasbinApi(oldPath string, newPath stri
"v1": newPath,
"v2": newMethod,
}).Error
e := casbinService.Casbin()
err = e.LoadPolicy()
if err != nil {
return err
}
return err

e := casbinService.Casbin()
return e.LoadPolicy()
}

//@author: [piexlmax](https://github.com/piexlmax)
Expand Down
5 changes: 3 additions & 2 deletions server/utils/upload/minio_oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func (m *Minio) UploadFile(file *multipart.FileHeader) (filePathres, key string,
}
f.Close() // 创建文件 defer 关闭


// 对文件名进行加密存储
ext := filepath.Ext(file.Filename)
filename := utils.MD5V([]byte(strings.TrimSuffix(file.Filename, ext))) + ext
Expand All @@ -91,8 +90,10 @@ func (m *Minio) UploadFile(file *multipart.FileHeader) (filePathres, key string,
}

func (m *Minio) DeleteFile(key string) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

// Delete the object from MinIO
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
err := m.Client.RemoveObject(ctx, m.bucket, key, minio.RemoveObjectOptions{})
return err
}

0 comments on commit 2bf423b

Please sign in to comment.