mirror of
https://github.com/flipped-aurora/gin-vue-admin.git
synced 2026-09-21 20:35:16 +00:00
修复漏洞,重构初始化功能,优化媒体库 (#1024)
* 媒体库增加 普通上传、压缩上传按钮,方便媒体库直接上传图片 * 增加数据类型切换后的的校验,避免使用错误的查询条件和字典条件。 * refactor: 重构初始化逻辑 * 媒体库功能丰富 * 修复注入漏洞和路径穿越 * 修复自动化接口获取数据库表失败后未能终止的bug * 微调媒体库样式 Co-authored-by: bypanghu <bypanghu@163.com> Co-authored-by: tesun <36953434+tesun@users.noreply.github.com> Co-authored-by: pnck <hio131@gmail.com> Co-authored-by: task <121913992@qq.com>
This commit is contained in:
committed by
GitHub
co-authored by
bypanghu
tesun
pnck
task
parent
fe539baa34
commit
6fb6ac2d6c
@@ -11,3 +11,7 @@ type SysApi struct {
|
||||
ApiGroup string `json:"apiGroup" gorm:"comment:api组"` // api组
|
||||
Method string `json:"method" gorm:"default:POST;comment:方法"` // 方法:创建POST(默认)|查看GET|更新PUT|删除DELETE
|
||||
}
|
||||
|
||||
func (SysApi) TableName() string {
|
||||
return "sys_apis"
|
||||
}
|
||||
|
||||
@@ -5,15 +5,19 @@ import (
|
||||
)
|
||||
|
||||
type SysAuthority struct {
|
||||
CreatedAt time.Time // 创建时间
|
||||
UpdatedAt time.Time // 更新时间
|
||||
DeletedAt *time.Time `sql:"index"`
|
||||
AuthorityId string `json:"authorityId" gorm:"not null;unique;primary_key;comment:角色ID;size:90"` // 角色ID
|
||||
AuthorityName string `json:"authorityName" gorm:"comment:角色名"` // 角色名
|
||||
ParentId string `json:"parentId" gorm:"comment:父角色ID"` // 父角色ID
|
||||
DataAuthorityId []SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id"`
|
||||
Children []SysAuthority `json:"children" gorm:"-"`
|
||||
SysBaseMenus []SysBaseMenu `json:"menus" gorm:"many2many:sys_authority_menus;"`
|
||||
Users []SysUser `json:"-" gorm:"many2many:sys_user_authority;"`
|
||||
DefaultRouter string `json:"defaultRouter" gorm:"comment:默认菜单;default:dashboard"` // 默认菜单(默认dashboard)
|
||||
CreatedAt time.Time // 创建时间
|
||||
UpdatedAt time.Time // 更新时间
|
||||
DeletedAt *time.Time `sql:"index"`
|
||||
AuthorityId string `json:"authorityId" gorm:"not null;unique;primary_key;comment:角色ID;size:90"` // 角色ID
|
||||
AuthorityName string `json:"authorityName" gorm:"comment:角色名"` // 角色名
|
||||
ParentId string `json:"parentId" gorm:"comment:父角色ID"` // 父角色ID
|
||||
DataAuthorityId []*SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id;"`
|
||||
Children []SysAuthority `json:"children" gorm:"-"`
|
||||
SysBaseMenus []SysBaseMenu `json:"menus" gorm:"many2many:sys_authority_menus;"`
|
||||
Users []SysUser `json:"-" gorm:"many2many:sys_user_authority;"`
|
||||
DefaultRouter string `json:"defaultRouter" gorm:"comment:默认菜单;default:dashboard"` // 默认菜单(默认dashboard)
|
||||
}
|
||||
|
||||
func (SysAuthority) TableName() string {
|
||||
return "sys_authorities"
|
||||
}
|
||||
|
||||
@@ -35,3 +35,7 @@ type SysBaseMenuParameter struct {
|
||||
Key string `json:"key" gorm:"comment:地址栏携带参数的key"` // 地址栏携带参数的key
|
||||
Value string `json:"value" gorm:"comment:地址栏携带参数的值"` // 地址栏携带参数的值
|
||||
}
|
||||
|
||||
func (SysBaseMenu) TableName() string {
|
||||
return "sys_base_menus"
|
||||
}
|
||||
|
||||
@@ -14,3 +14,7 @@ type SysDictionary struct {
|
||||
Desc string `json:"desc" form:"desc" gorm:"column:desc;comment:描述"` // 描述
|
||||
SysDictionaryDetails []SysDictionaryDetail `json:"sysDictionaryDetails" form:"sysDictionaryDetails"`
|
||||
}
|
||||
|
||||
func (SysDictionary) TableName() string {
|
||||
return "sys_dictionaries"
|
||||
}
|
||||
|
||||
@@ -14,3 +14,7 @@ type SysDictionaryDetail struct {
|
||||
Sort int `json:"sort" form:"sort" gorm:"column:sort;comment:排序标记"` // 排序标记
|
||||
SysDictionaryID int `json:"sysDictionaryID" form:"sysDictionaryID" gorm:"column:sys_dictionary_id;comment:关联标记"` // 关联标记
|
||||
}
|
||||
|
||||
func (SysDictionaryDetail) TableName() string {
|
||||
return "sys_dictionary_details"
|
||||
}
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
package system
|
||||
|
||||
import "github.com/gookit/color"
|
||||
|
||||
type InitDBFunc interface {
|
||||
Init() (err error)
|
||||
}
|
||||
|
||||
const (
|
||||
Mysql = "mysql"
|
||||
Pgsql = "pgsql"
|
||||
InitSuccess = "\n[%v] --> 初始数据成功!\n"
|
||||
AuthorityMenu = "\n[%v] --> %v 视图已存在!\n"
|
||||
InitDataExist = "\n[%v] --> %v 表的初始数据已存在!\n"
|
||||
InitDataFailed = "\n[%v] --> %v 表初始数据失败! \nerr: %+v\n"
|
||||
InitDataSuccess = "\n[%v] --> %v 表初始数据成功!\n"
|
||||
)
|
||||
|
||||
type InitData interface {
|
||||
TableName() string
|
||||
Initialize() error
|
||||
CheckDataExist() bool
|
||||
}
|
||||
|
||||
// MysqlDataInitialize Mysql 初始化接口使用封装
|
||||
// Author [SliverHorn](https://github.com/SliverHorn)
|
||||
func MysqlDataInitialize(inits ...InitData) error {
|
||||
var entity SysMenu
|
||||
for i := 0; i < len(inits); i++ {
|
||||
if inits[i].TableName() == entity.TableName() {
|
||||
if k := inits[i].CheckDataExist(); k {
|
||||
color.Info.Printf(AuthorityMenu, Mysql, inits[i].TableName())
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
if inits[i].CheckDataExist() {
|
||||
color.Info.Printf(InitDataExist, Mysql, inits[i].TableName())
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if err := inits[i].Initialize(); err != nil {
|
||||
color.Info.Printf(InitDataFailed, Mysql, err)
|
||||
return err
|
||||
} else {
|
||||
color.Info.Printf(InitDataSuccess, Mysql, inits[i].TableName())
|
||||
}
|
||||
}
|
||||
color.Info.Printf(InitSuccess, Mysql)
|
||||
return nil
|
||||
}
|
||||
|
||||
// PgsqlDataInitialize Pgsql 初始化接口使用封装
|
||||
// Author [SliverHorn](https://github.com/SliverHorn)
|
||||
func PgsqlDataInitialize(inits ...InitData) error {
|
||||
var entity SysMenu
|
||||
for i := 0; i < len(inits); i++ {
|
||||
if inits[i].TableName() == entity.TableName() {
|
||||
if k := inits[i].CheckDataExist(); k {
|
||||
color.Info.Printf(AuthorityMenu, Pgsql, inits[i].TableName())
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
if inits[i].CheckDataExist() {
|
||||
color.Info.Printf(InitDataExist, Pgsql, inits[i].TableName())
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if err := inits[i].Initialize(); err != nil {
|
||||
color.Info.Printf(InitDataFailed, Pgsql, err)
|
||||
continue
|
||||
} else {
|
||||
color.Info.Printf(InitDataSuccess, Pgsql, inits[i].TableName())
|
||||
}
|
||||
}
|
||||
color.Info.Printf(InitSuccess, Pgsql)
|
||||
return nil
|
||||
}
|
||||
@@ -21,3 +21,7 @@ type SysUser struct {
|
||||
Phone string `json:"phone" gorm:"comment:用户手机号"` // 用户手机号
|
||||
Email string `json:"email" gorm:"comment:用户邮箱"` // 用户邮箱
|
||||
}
|
||||
|
||||
func (SysUser) TableName() string {
|
||||
return "sys_users"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user