- Added `resources` field in `management.register` for defining browser-accessible resources. - Updated examples and documentation to reflect resource-based paths under `/v0/resource/plugins/<pluginID>/...`. - Replaced legacy `GET` menu routes with resource-based implementations for consistent plugin behavior. - Enhanced request handling for resource paths, including proper response headers and streamlined test coverage.
Showing the changes to internal/api (1 of 22 files). Show all
Unified · Split
| @@ -382,7 +382,7 @@ func (s *Server) homeHeartbeatMiddleware() gin.HandlerFunc { · 381 unmodified lines | ||
| 382 | 382 | } |
| 383 | 383 | if c != nil && c.Request != nil { |
| 384 | 384 | path := c.Request.URL.Path |
| 385 | − if strings.HasPrefix(path, "/v0/management/") || path == "/v0/management" || path == "/management.html" { | |
| 385 | + if strings.HasPrefix(path, "/v0/management/") || path == "/v0/management" || strings.HasPrefix(path, "/v0/resource/plugins/") || path == "/management.html" { | |
| 386 | 386 | c.Next() |
| 387 | 387 | return |
| 388 | 388 | } |
| @@ -811,6 +811,10 @@ func (s *Server) pluginManagementNoRoute(c *gin.Context) { · 422 unmodified lines | ||
| 811 | 811 | return |
| 812 | 812 | } |
| 813 | 813 | path := c.Request.URL.Path |
| 814 | + if strings.HasPrefix(path, "/v0/resource/plugins/") { | |
| 815 | + s.pluginResourceNoRoute(c) | |
| 816 | + return | |
| 817 | + } | |
| 814 | 818 | if path != "/v0/management" && !strings.HasPrefix(path, "/v0/management/") { |
| 815 | 819 | c.AbortWithStatus(http.StatusNotFound) |
| 816 | 820 | return |
| @@ -837,6 +841,24 @@ func (s *Server) pluginManagementNoRoute(c *gin.Context) { · 20 unmodified lines | ||
| 837 | 841 | c.AbortWithStatus(http.StatusNotFound) |
| 838 | 842 | } |
| 839 | 843 | |
| 844 | +func (s *Server) pluginResourceNoRoute(c *gin.Context) { | |
| 845 | + if s == nil || c == nil || c.Request == nil || c.Request.URL == nil { | |
| 846 | + if c != nil { | |
| 847 | + c.AbortWithStatus(http.StatusNotFound) | |
| 848 | + } | |
| 849 | + return | |
| 850 | + } | |
| 851 | + if s.cfg == nil || s.cfg.Home.Enabled || s.pluginHost == nil { | |
| 852 | + c.AbortWithStatus(http.StatusNotFound) | |
| 853 | + return | |
| 854 | + } | |
| 855 | + if s.pluginHost.ServeResourceHTTP(c.Writer, c.Request) { | |
| 856 | + c.Abort() | |
| 857 | + return | |
| 858 | + } | |
| 859 | + c.AbortWithStatus(http.StatusNotFound) | |
| 860 | +} | |
| 861 | + | |
| 840 | 862 | func (s *Server) serveManagementControlPanel(c *gin.Context) { |
| 841 | 863 | cfg := s.cfg |
| 842 | 864 | if cfg == nil || cfg.Home.Enabled || cfg.RemoteManagement.DisableControlPanel { |