Plugins: Don't auto prepend app sub url to plugin asset paths (#81658)

* don't prepend app sub url to paths

* simplify logo path

* fix(plugins): dynamically prepend appSubUrl for System module resolving to work

* fix(sandbox): support dynamic appSuburl prepend when loading plugin module.js

* fix tests

* update test name

* fix tests

* update fe + add some tests

* refactor(plugins): move wrangleurl to utils, rename to resolveModulePath, update usage

* chore: fix a typo

* test(plugins): add missing name to utils test

* reset test flag

---------

Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
This commit is contained in:
Will Browne
2024-02-08 12:19:28 +01:00
committed by GitHub
parent 18963dc3ae
commit 99feb928cf
11 changed files with 289 additions and 252 deletions

View File

@ -47,12 +47,12 @@ func DefaultService(cfg *config.Cfg) *Service {
func (s *Service) Base(n PluginInfo) (string, error) {
if n.class == plugins.ClassCore {
baseDir := getBaseDir(n.dir)
return path.Join("/", s.cfg.GrafanaAppSubURL, "/public/app/plugins", string(n.pluginJSON.Type), baseDir), nil
return path.Join("public/app/plugins", string(n.pluginJSON.Type), baseDir), nil
}
if s.cdn.PluginSupported(n.pluginJSON.ID) {
return s.cdn.AssetURL(n.pluginJSON.ID, n.pluginJSON.Info.Version, "")
}
return path.Join("/", s.cfg.GrafanaAppSubURL, "/public/plugins", n.pluginJSON.ID), nil
return path.Join("public/plugins", n.pluginJSON.ID), nil
}
// Module returns the module.js path for the specified plugin.
@ -70,7 +70,7 @@ func (s *Service) Module(n PluginInfo) (string, error) {
if s.cdn.PluginSupported(n.pluginJSON.ID) {
return s.cdn.AssetURL(n.pluginJSON.ID, n.pluginJSON.Info.Version, "module.js")
}
return path.Join("/", s.cfg.GrafanaAppSubURL, "/public/plugins", n.pluginJSON.ID, "module.js"), nil
return path.Join("public/plugins", n.pluginJSON.ID, "module.js"), nil
}
// RelativeURL returns the relative URL for an arbitrary plugin asset.
@ -101,7 +101,7 @@ func (s *Service) RelativeURL(n PluginInfo, pathStr string) (string, error) {
// DefaultLogoPath returns the default logo path for the specified plugin type.
func (s *Service) DefaultLogoPath(pluginType plugins.Type) string {
return path.Join("/", s.cfg.GrafanaAppSubURL, fmt.Sprintf("/public/img/icn-%s.svg", string(pluginType)))
return path.Join("public/img", fmt.Sprintf("icn-%s.svg", string(pluginType)))
}
func getBaseDir(pluginDir string) string {