优化结构
This commit is contained in:
@@ -123,7 +123,26 @@ func seedSystem(ctx context.Context, db *gorm.DB, input *system.DatabaseConfig,
|
||||
for _, item := range DefaultIgnoredAPIs("uploads/file") {
|
||||
ignoredAPIs = append(ignoredAPIs, ignoredAPIPO{Method: item.Method, Path: item.Path})
|
||||
}
|
||||
// The local storage prefix is configurable. Add the concrete catch-all
|
||||
// routes supplied by the initialization request so API sync and policy
|
||||
// generation keep every static file endpoint public, regardless of the
|
||||
// configured prefix.
|
||||
for _, item := range input.APIs {
|
||||
if item == nil {
|
||||
continue
|
||||
}
|
||||
candidate := ignoredAPIPO{Method: strings.ToUpper(item.Method), Path: item.Path}
|
||||
if isStaticFileAPI(apiPO{Method: candidate.Method, Path: candidate.Path}) {
|
||||
ignoredAPIs = append(ignoredAPIs, candidate)
|
||||
}
|
||||
}
|
||||
seenIgnored := make(map[string]struct{}, len(ignoredAPIs))
|
||||
for _, ignored := range ignoredAPIs {
|
||||
key := ignored.Method + "\x00" + ignored.Path
|
||||
if _, exists := seenIgnored[key]; exists {
|
||||
continue
|
||||
}
|
||||
seenIgnored[key] = struct{}{}
|
||||
if err := tx.FirstOrCreate(&ignored, ignored).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -137,7 +156,7 @@ func seedSystem(ctx context.Context, db *gorm.DB, input *system.DatabaseConfig,
|
||||
return err
|
||||
}
|
||||
for _, api := range apiRows {
|
||||
if _, ignored := ignoreSet[api.Method+"\x00"+api.Path]; ignored {
|
||||
if _, ignored := ignoreSet[api.Method+"\x00"+api.Path]; ignored || isStaticFileAPI(api) {
|
||||
continue
|
||||
}
|
||||
exists, err := policyExists(tx, 888, api.Path, api.Method)
|
||||
@@ -155,6 +174,14 @@ func seedSystem(ctx context.Context, db *gorm.DB, input *system.DatabaseConfig,
|
||||
})
|
||||
}
|
||||
|
||||
// isStaticFileAPI keeps dynamically configured local-storage routes public.
|
||||
// The route prefix is runtime configuration, so it cannot be hard-coded in
|
||||
// DefaultIgnoredAPIs; initialization already receives the concrete Gin route
|
||||
// list and can identify the catch-all file handlers directly.
|
||||
func isStaticFileAPI(api apiPO) bool {
|
||||
return (api.Method == "GET" || api.Method == "HEAD") && strings.HasSuffix(strings.TrimSpace(api.Path), "/*filepath")
|
||||
}
|
||||
|
||||
func seedAdminSurface(tx *gorm.DB, surface platformmodule.Surface) error {
|
||||
for _, item := range surface.Menus {
|
||||
parentID := uint(0)
|
||||
|
||||
Reference in New Issue
Block a user