mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
8261613b51
See, $ gometalinter --vendor --deadline 10m --disable-all --enable=golint ./... ip.go:8:6⚠️ func SplitIpPort should be SplitIPPort (golint) url.go:14:6⚠️ func NewUrlQueryReader should be NewURLQueryReader (golint) url.go:9:6⚠️ type UrlQueryReader should be URLQueryReader (golint) url.go:37:6⚠️ func JoinUrlFragments should be JoinURLFragments (golint)
82 lines
2.0 KiB
Go
82 lines
2.0 KiB
Go
package plugins
|
|
|
|
import (
|
|
"net/url"
|
|
"path"
|
|
"strings"
|
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
"github.com/grafana/grafana/pkg/util"
|
|
)
|
|
|
|
type FrontendPluginBase struct {
|
|
PluginBase
|
|
}
|
|
|
|
func (fp *FrontendPluginBase) initFrontendPlugin() {
|
|
if isExternalPlugin(fp.PluginDir) {
|
|
StaticRoutes = append(StaticRoutes, &PluginStaticRoute{
|
|
Directory: fp.PluginDir,
|
|
PluginId: fp.Id,
|
|
})
|
|
}
|
|
|
|
fp.handleModuleDefaults()
|
|
|
|
fp.Info.Logos.Small = getPluginLogoUrl(fp.Type, fp.Info.Logos.Small, fp.BaseUrl)
|
|
fp.Info.Logos.Large = getPluginLogoUrl(fp.Type, fp.Info.Logos.Large, fp.BaseUrl)
|
|
|
|
for i := 0; i < len(fp.Info.Screenshots); i++ {
|
|
fp.Info.Screenshots[i].Path = evalRelativePluginUrlPath(fp.Info.Screenshots[i].Path, fp.BaseUrl)
|
|
}
|
|
}
|
|
|
|
func getPluginLogoUrl(pluginType, path, baseUrl string) string {
|
|
if path == "" {
|
|
return "public/img/icn-" + pluginType + ".svg"
|
|
}
|
|
|
|
return evalRelativePluginUrlPath(path, baseUrl)
|
|
}
|
|
|
|
func (fp *FrontendPluginBase) setPathsBasedOnApp(app *AppPlugin) {
|
|
appSubPath := strings.Replace(strings.Replace(fp.PluginDir, app.PluginDir, "", 1), "\\", "/", -1)
|
|
fp.IncludedInAppId = app.Id
|
|
fp.BaseUrl = app.BaseUrl
|
|
|
|
if isExternalPlugin(app.PluginDir) {
|
|
fp.Module = util.JoinURLFragments("plugins/"+app.Id, appSubPath) + "/module"
|
|
} else {
|
|
fp.Module = util.JoinURLFragments("app/plugins/app/"+app.Id, appSubPath) + "/module"
|
|
}
|
|
}
|
|
|
|
func (fp *FrontendPluginBase) handleModuleDefaults() {
|
|
|
|
if isExternalPlugin(fp.PluginDir) {
|
|
fp.Module = path.Join("plugins", fp.Id, "module")
|
|
fp.BaseUrl = path.Join("public/plugins", fp.Id)
|
|
return
|
|
}
|
|
|
|
fp.IsCorePlugin = true
|
|
fp.Module = path.Join("app/plugins", fp.Type, fp.Id, "module")
|
|
fp.BaseUrl = path.Join("public/app/plugins", fp.Type, fp.Id)
|
|
}
|
|
|
|
func isExternalPlugin(pluginDir string) bool {
|
|
return !strings.Contains(pluginDir, setting.StaticRootPath)
|
|
}
|
|
|
|
func evalRelativePluginUrlPath(pathStr string, baseUrl string) string {
|
|
if pathStr == "" {
|
|
return ""
|
|
}
|
|
|
|
u, _ := url.Parse(pathStr)
|
|
if u.IsAbs() {
|
|
return pathStr
|
|
}
|
|
return path.Join(baseUrl, pathStr)
|
|
}
|