feat: publish sanitized custom.97 source

This commit is contained in:
cneicy committed 2026-10-27 20:43:39 +08:00
1 parent 8e6ed0317b
commit 86c0276156
1022 files changed
+69903 -19207

No files matched your search

+22 -4
View File
@@ -2,6 +2,7 @@ package router
import (
"net/http"
"path"
"github.com/QuantumNous/new-api/controller"
"github.com/QuantumNous/new-api/middleware"
@@ -16,6 +17,26 @@ type permissionRoute struct {
handler gin.HandlerFunc
}
// handlePermissionRoute registers a Casbin-guarded route and declares the same
// permission as the access token scope that route requires.
func handlePermissionRoute(group *gin.RouterGroup, method, relativePath string, permission authz.Permission, handlers ...gin.HandlerFunc) {
middleware.DeclareAccessTokenPermissionRoute(method, joinPaths(group.BasePath(), relativePath), permission)
group.Handle(method, relativePath, append([]gin.HandlerFunc{middleware.RequirePermission(permission)}, handlers...)...)
}
// joinPaths matches gin's route path joining, which keeps a trailing slash
// from the relative path, so declared keys equal c.FullPath().
func joinPaths(absolutePath, relativePath string) string {
if relativePath == "" {
return absolutePath
}
finalPath := path.Join(absolutePath, relativePath)
if relativePath[len(relativePath)-1] == '/' && finalPath[len(finalPath)-1] != '/' {
return finalPath + "/"
}
return finalPath
}
func registerChannelRoutes(apiRouter *gin.RouterGroup) {
channelRoute := apiRouter.Group("/channel")
channelRoute.Use(middleware.AdminAuth())
@@ -29,10 +50,7 @@ func registerChannelRoutes(apiRouter *gin.RouterGroup) {
)
for _, route := range channelPermissionRoutes {
channelRoute.Handle(route.method, route.path,
middleware.RequirePermission(route.permission),
route.handler,
)
handlePermissionRoute(channelRoute, route.method, route.path, route.permission, route.handler)
}
}