- 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 | if c != nil && c.Request != nil { | 383 | if c != nil && c.Request != nil { |
| 384 | path := c.Request.URL.Path | 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 | c.Next() | 386 | c.Next() |
| 387 | return | 387 | return |
| 388 | } | 388 | } |
| @@ -811,6 +811,10 @@ func (s *Server) pluginManagementNoRoute(c *gin.Context) { · 422 unmodified lines | |||
| 811 | return | 811 | return |
| 812 | } | 812 | } |
| 813 | path := c.Request.URL.Path | 813 | path := c.Request.URL.Path |
| 814 | if strings.HasPrefix(path, "/v0/resource/plugins/") { | ||
| 815 | s.pluginResourceNoRoute(c) | ||
| 816 | return | ||
| 817 | } | ||
| 814 | if path != "/v0/management" && !strings.HasPrefix(path, "/v0/management/") { | 818 | if path != "/v0/management" && !strings.HasPrefix(path, "/v0/management/") { |
| 815 | c.AbortWithStatus(http.StatusNotFound) | 819 | c.AbortWithStatus(http.StatusNotFound) |
| 816 | return | 820 | return |
| @@ -837,6 +841,24 @@ func (s *Server) pluginManagementNoRoute(c *gin.Context) { · 20 unmodified lines | |||
| 837 | c.AbortWithStatus(http.StatusNotFound) | 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 | func (s *Server) serveManagementControlPanel(c *gin.Context) { | 862 | func (s *Server) serveManagementControlPanel(c *gin.Context) { |
| 841 | cfg := s.cfg | 863 | cfg := s.cfg |
| 842 | if cfg == nil || cfg.Home.Enabled || cfg.RemoteManagement.DisableControlPanel { | 864 | if cfg == nil || cfg.Home.Enabled || cfg.RemoteManagement.DisableControlPanel { |