History

feat(pluginhost): introduce browser-navigable plugin resources in Management API

- 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.

Luis Pater committed 5 months agov7.1.59

Commit 44ea9ab1 parent 2aeb41c22 files · +341 −69Browse files

Showing the changes to internal/api (1 of 22 files). Show all

Unified · Split

internal/api/server.go+23−1
@@ -382,7 +382,7 @@ func (s *Server) homeHeartbeatMiddleware() gin.HandlerFunc { · 381 unmodified lines
382382 }
383383 if c != nil && c.Request != nil {
384384 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" {
386386 c.Next()
387387 return
388388 }
@@ -811,6 +811,10 @@ func (s *Server) pluginManagementNoRoute(c *gin.Context) { · 422 unmodified lines
811811 return
812812 }
813813 path := c.Request.URL.Path
814+ if strings.HasPrefix(path, "/v0/resource/plugins/") {
815+ s.pluginResourceNoRoute(c)
816+ return
817+ }
814818 if path != "/v0/management" && !strings.HasPrefix(path, "/v0/management/") {
815819 c.AbortWithStatus(http.StatusNotFound)
816820 return
@@ -837,6 +841,24 @@ func (s *Server) pluginManagementNoRoute(c *gin.Context) { · 20 unmodified lines
837841 c.AbortWithStatus(http.StatusNotFound)
838842 }
839843
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+
840862 func (s *Server) serveManagementControlPanel(c *gin.Context) {
841863 cfg := s.cfg
842864 if cfg == nil || cfg.Home.Enabled || cfg.RemoteManagement.DisableControlPanel {