@@ -63,6 +63,10 @@ func (i *initApi) InitializeData(ctx context.Context) (context.Context, error) {
|
||||
{ApiGroup: "api", Method: "POST", Path: "/api/getAllApis", Description: "获取所有api"},
|
||||
{ApiGroup: "api", Method: "POST", Path: "/api/getApiById", Description: "获取api详细信息"},
|
||||
{ApiGroup: "api", Method: "DELETE", Path: "/api/deleteApisByIds", Description: "批量删除api"},
|
||||
{ApiGroup: "api", Method: "GET", Path: "/api/syncApi", Description: "获取待同步API"},
|
||||
{ApiGroup: "api", Method: "GET", Path: "/api/getApiGroups", Description: "获取路由组"},
|
||||
{ApiGroup: "api", Method: "POST", Path: "/api/enterSyncApi", Description: "确认同步API"},
|
||||
{ApiGroup: "api", Method: "POST", Path: "/api/ignoreApi", Description: "忽略API"},
|
||||
|
||||
{ApiGroup: "角色", Method: "POST", Path: "/authority/copyAuthority", Description: "拷贝角色"},
|
||||
{ApiGroup: "角色", Method: "POST", Path: "/authority/createAuthority", Description: "创建角色"},
|
||||
@@ -145,7 +149,7 @@ func (i *initApi) InitializeData(ctx context.Context) (context.Context, error) {
|
||||
{ApiGroup: "断点续传(插件版)", Method: "GET", Path: "/simpleUploader/mergeFileMd5", Description: "上传完成合并文件"},
|
||||
|
||||
{ApiGroup: "email", Method: "POST", Path: "/email/emailTest", Description: "发送测试邮件"},
|
||||
{ApiGroup: "email", Method: "POST", Path: "/email/emailSend", Description: "发送邮件示例"},
|
||||
{ApiGroup: "email", Method: "POST", Path: "/email/sendEmail", Description: "发送邮件"},
|
||||
|
||||
{ApiGroup: "按钮权限", Method: "POST", Path: "/authorityBtn/setAuthorityBtn", Description: "设置按钮权限"},
|
||||
{ApiGroup: "按钮权限", Method: "POST", Path: "/authorityBtn/getAuthorityBtn", Description: "获取已有按钮权限"},
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
sysModel "github.com/flipped-aurora/gin-vue-admin/server/model/system"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/service/system"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type initApiIgnore struct{}
|
||||
|
||||
const initOrderApiIgnore = initOrderApi + 1
|
||||
|
||||
// auto run
|
||||
func init() {
|
||||
system.RegisterInit(initOrderApiIgnore, &initApiIgnore{})
|
||||
}
|
||||
|
||||
func (i initApiIgnore) InitializerName() string {
|
||||
return sysModel.SysIgnoreApi{}.TableName()
|
||||
}
|
||||
|
||||
func (i *initApiIgnore) MigrateTable(ctx context.Context) (context.Context, error) {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
return ctx, system.ErrMissingDBContext
|
||||
}
|
||||
return ctx, db.AutoMigrate(&sysModel.SysIgnoreApi{})
|
||||
}
|
||||
|
||||
func (i *initApiIgnore) TableCreated(ctx context.Context) bool {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return db.Migrator().HasTable(&sysModel.SysIgnoreApi{})
|
||||
}
|
||||
|
||||
func (i *initApiIgnore) InitializeData(ctx context.Context) (context.Context, error) {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
return ctx, system.ErrMissingDBContext
|
||||
}
|
||||
entities := []sysModel.SysIgnoreApi{
|
||||
{Method: "GET", Path: "/swagger/*any"},
|
||||
{Method: "GET", Path: "/api/freshCasbin"},
|
||||
{Method: "GET", Path: "/uploads/file/*filepath"},
|
||||
{Method: "GET", Path: "/health"},
|
||||
{Method: "HEAD", Path: "/uploads/file/*filepath"},
|
||||
{Method: "POST", Path: "/autoCode/llmAuto"},
|
||||
{Method: "POST", Path: "/system/reloadSystem"},
|
||||
{Method: "POST", Path: "/base/login"},
|
||||
{Method: "POST", Path: "/base/captcha"},
|
||||
{Method: "POST", Path: "/init/initdb"},
|
||||
{Method: "POST", Path: "/init/checkdb"},
|
||||
}
|
||||
if err := db.Create(&entities).Error; err != nil {
|
||||
return ctx, errors.Wrap(err, sysModel.SysIgnoreApi{}.TableName()+"表数据初始化失败!")
|
||||
}
|
||||
next := context.WithValue(ctx, i.InitializerName(), entities)
|
||||
return next, nil
|
||||
}
|
||||
|
||||
func (i *initApiIgnore) DataInserted(ctx context.Context) bool {
|
||||
db, ok := ctx.Value("db").(*gorm.DB)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if errors.Is(db.Where("path = ? AND method = ?", "/swagger/*any", "GET").
|
||||
First(&sysModel.SysIgnoreApi{}).Error, gorm.ErrRecordNotFound) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const initOrderCasbin = initOrderApi + 1
|
||||
const initOrderCasbin = initOrderApiIgnore + 1
|
||||
|
||||
type initCasbin struct{}
|
||||
|
||||
@@ -54,6 +54,10 @@ func (i *initCasbin) InitializeData(ctx context.Context) (context.Context, error
|
||||
{Ptype: "p", V0: "888", V1: "/api/updateApi", V2: "POST"},
|
||||
{Ptype: "p", V0: "888", V1: "/api/getAllApis", V2: "POST"},
|
||||
{Ptype: "p", V0: "888", V1: "/api/deleteApisByIds", V2: "DELETE"},
|
||||
{Ptype: "p", V0: "888", V1: "/api/syncApi", V2: "GET"},
|
||||
{Ptype: "p", V0: "888", V1: "/api/getApiGroups", V2: "GET"},
|
||||
{Ptype: "p", V0: "888", V1: "/api/enterSyncApi", V2: "POST"},
|
||||
{Ptype: "p", V0: "888", V1: "/api/ignoreApi", V2: "POST"},
|
||||
|
||||
{Ptype: "p", V0: "888", V1: "/authority/copyAuthority", V2: "POST"},
|
||||
{Ptype: "p", V0: "888", V1: "/authority/updateAuthority", V2: "PUT"},
|
||||
@@ -143,6 +147,7 @@ func (i *initCasbin) InitializeData(ctx context.Context) (context.Context, error
|
||||
{Ptype: "p", V0: "888", V1: "/sysOperationRecord/deleteSysOperationRecordByIds", V2: "DELETE"},
|
||||
|
||||
{Ptype: "p", V0: "888", V1: "/email/emailTest", V2: "POST"},
|
||||
{Ptype: "p", V0: "888", V1: "/email/sendEmail", V2: "POST"},
|
||||
|
||||
{Ptype: "p", V0: "888", V1: "/simpleUploader/upload", V2: "POST"},
|
||||
{Ptype: "p", V0: "888", V1: "/simpleUploader/checkFileMd5", V2: "GET"},
|
||||
|
||||
Reference in New Issue
Block a user