frontend_plugin.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. StaticRootAbs string `json:"-"`
  12. }
  13. func (fp *FrontendPluginBase) initFrontendPlugin() {
  14. if fp.StaticRoot != "" {
  15. fp.StaticRootAbs = filepath.Join(fp.PluginDir, fp.StaticRoot)
  16. StaticRoutes = append(StaticRoutes, &PluginStaticRoute{
  17. Directory: fp.StaticRootAbs,
  18. PluginId: fp.Id,
  19. })
  20. }
  21. fp.Info.Logos.Small = evalRelativePluginUrlPath(fp.Info.Logos.Small, fp.Id)
  22. fp.Info.Logos.Large = evalRelativePluginUrlPath(fp.Info.Logos.Large, fp.Id)
  23. fp.handleModuleDefaults()
  24. }
  25. func (fp *FrontendPluginBase) handleModuleDefaults() {
  26. if fp.Module != "" {
  27. return
  28. }
  29. if fp.StaticRoot != "" {
  30. fp.Module = path.Join("plugins", fp.Id, "module")
  31. return
  32. }
  33. fp.Module = path.Join("app/plugins", fp.Type, fp.Id, "module")
  34. }
  35. func evalRelativePluginUrlPath(pathStr string, pluginId string) string {
  36. u, _ := url.Parse(pathStr)
  37. if u.IsAbs() {
  38. return pathStr
  39. }
  40. return path.Join("public/plugins", pluginId, pathStr)
  41. }