删除服务端材质渲染功能及system_config表,转为环境变量配置,初步配置管理员功能
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"carrotskin/internal/middleware"
|
||||
"carrotskin/internal/model"
|
||||
"carrotskin/pkg/auth"
|
||||
"carrotskin/pkg/config"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
swaggerFiles "github.com/swaggo/files"
|
||||
@@ -20,6 +21,7 @@ type Handlers struct {
|
||||
Captcha *CaptchaHandler
|
||||
Yggdrasil *YggdrasilHandler
|
||||
CustomSkin *CustomSkinHandler
|
||||
Admin *AdminHandler
|
||||
}
|
||||
|
||||
// NewHandlers 创建所有Handler实例
|
||||
@@ -32,6 +34,7 @@ func NewHandlers(c *container.Container) *Handlers {
|
||||
Captcha: NewCaptchaHandler(c),
|
||||
Yggdrasil: NewYggdrasilHandler(c),
|
||||
CustomSkin: NewCustomSkinHandler(c),
|
||||
Admin: NewAdminHandler(c),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,10 +71,13 @@ func RegisterRoutesWithDI(router *gin.Engine, c *container.Container) {
|
||||
registerYggdrasilRoutesWithDI(v1, h.Yggdrasil)
|
||||
|
||||
// 系统路由
|
||||
registerSystemRoutes(v1)
|
||||
registerSystemRoutes(v1, c)
|
||||
|
||||
// CustomSkinAPI 路由
|
||||
registerCustomSkinRoutes(v1, h.CustomSkin)
|
||||
|
||||
// 管理员路由(需要管理员权限)
|
||||
registerAdminRoutes(v1, c, h.Admin)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,10 +119,6 @@ func registerTextureRoutes(v1 *gin.RouterGroup, h *TextureHandler, jwtService *a
|
||||
// 公开路由(无需认证)
|
||||
textureGroup.GET("", h.Search)
|
||||
textureGroup.GET("/:id", h.Get)
|
||||
textureGroup.GET("/:id/render", h.RenderTexture) // type/front/back/full/head/isometric
|
||||
textureGroup.GET("/:id/avatar", h.RenderAvatar) // mode=2d/3d
|
||||
textureGroup.GET("/:id/cape", h.RenderCape)
|
||||
textureGroup.GET("/:id/preview", h.RenderPreview) // 自动根据类型预览
|
||||
|
||||
// 需要认证的路由
|
||||
textureAuth := textureGroup.Group("")
|
||||
@@ -192,17 +194,46 @@ func registerYggdrasilRoutesWithDI(v1 *gin.RouterGroup, h *YggdrasilHandler) {
|
||||
}
|
||||
|
||||
// registerSystemRoutes 注册系统路由
|
||||
func registerSystemRoutes(v1 *gin.RouterGroup) {
|
||||
func registerSystemRoutes(v1 *gin.RouterGroup, c *container.Container) {
|
||||
system := v1.Group("/system")
|
||||
{
|
||||
system.GET("/config", func(c *gin.Context) {
|
||||
// TODO: 实现从数据库读取系统配置
|
||||
c.JSON(200, model.NewSuccessResponse(gin.H{
|
||||
"site_name": "CarrotSkin",
|
||||
"site_description": "A Minecraft Skin Station",
|
||||
"registration_enabled": true,
|
||||
"max_textures_per_user": 100,
|
||||
"max_profiles_per_user": 5,
|
||||
// 公开配置(无需认证)
|
||||
system.GET("/config", func(ctx *gin.Context) {
|
||||
cfg, _ := config.GetConfig()
|
||||
ctx.JSON(200, model.NewSuccessResponse(gin.H{
|
||||
"site_name": cfg.Site.Name,
|
||||
"site_description": cfg.Site.Description,
|
||||
"registration_enabled": cfg.Site.RegistrationEnabled,
|
||||
"max_textures_per_user": cfg.Site.MaxTexturesPerUser,
|
||||
"max_profiles_per_user": cfg.Site.MaxProfilesPerUser,
|
||||
}))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// registerAdminRoutes 注册管理员路由
|
||||
func registerAdminRoutes(v1 *gin.RouterGroup, c *container.Container, h *AdminHandler) {
|
||||
admin := v1.Group("/admin")
|
||||
admin.Use(middleware.AuthMiddleware(c.JWT))
|
||||
admin.Use(middleware.RequireAdmin())
|
||||
{
|
||||
|
||||
// 用户管理
|
||||
admin.GET("/users", h.GetUserList)
|
||||
admin.GET("/users/:id", h.GetUserDetail)
|
||||
admin.PUT("/users/role", h.SetUserRole)
|
||||
admin.PUT("/users/status", h.SetUserStatus)
|
||||
|
||||
// 材质管理(审核)
|
||||
admin.GET("/textures", h.GetTextureList)
|
||||
admin.DELETE("/textures/:id", h.DeleteTexture)
|
||||
|
||||
// 权限管理
|
||||
admin.GET("/permissions", func(ctx *gin.Context) {
|
||||
// 获取所有权限规则
|
||||
policies, _ := c.Casbin.GetEnforcer().GetPolicy()
|
||||
ctx.JSON(200, model.NewSuccessResponse(gin.H{
|
||||
"policies": policies,
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user