frontend_plugin.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package plugins
  2. import (
  3. "net/url"
  4. "path"
  5. "path/filepath"
  6. )
  7. type FrontendPluginBase struct {
  8. PluginBase
  9. Module string `json:"module"`
  10. StaticRoot string `json:"staticRoot"`
  11. }
  12. func (fp *FrontendPluginBase) initFrontendPlugin() {
  13. if fp.StaticRoot != "" {
  14. StaticRoutes = append(StaticRoutes, &PluginStaticRoute{
  15. Directory: filepath.Join(fp.PluginDir, fp.StaticRoot),
  16. PluginId: fp.Id,
  17. })
  18. }
  19. fp.Info.Logos.Small = evalRelativePluginUrlPath(fp.Info.Logos.Small, fp.Id)
  20. fp.Info.Logos.Large = evalRelativePluginUrlPath(fp.Info.Logos.Large, fp.Id)
  21. fp.handleModuleDefaults()
  22. }
  23. func (fp *FrontendPluginBase) handleModuleDefaults() {
  24. if fp.Module != "" {
  25. return
  26. }
  27. if fp.StaticRoot != "" {
  28. fp.Module = path.Join("plugins", fp.Id, "module")
  29. return
  30. }
  31. fp.Module = path.Join("app/plugins", fp.Type, fp.Id, "module")
  32. }
  33. func evalRelativePluginUrlPath(pathStr string, pluginId string) string {
  34. u, _ := url.Parse(pathStr)
  35. if u.IsAbs() {
  36. return pathStr
  37. }
  38. return path.Join("public/plugins", pluginId, pathStr)
  39. }