pluginscdn

package
v0.0.0-cloud Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2023 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPluginNotCDN = errors.New("plugin is not a cdn plugin")

Functions

This section is empty.

Types

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service provides methods for the plugins CDN.

func ProvideService

func ProvideService(cfg *config.Cfg) *Service

func (*Service) AssetURL

func (s *Service) AssetURL(pluginID, pluginVersion, assetPath string) (string, error)

AssetURL returns the URL of a CDN asset for a CDN plugin. If the specified plugin is not a CDN plugin, it returns ErrPluginNotCDN.

func (*Service) BaseURL

func (s *Service) BaseURL() (string, error)

BaseURL returns the absolute base URL of the plugins CDN. This is the "fixed" part of the URL (protocol + host + root url). If the plugins CDN is disabled, it returns an empty string.

func (*Service) IsEnabled

func (s *Service) IsEnabled() bool

IsEnabled returns true if the plugins cdn is enabled.

func (*Service) NewCDNURLConstructor

func (s *Service) NewCDNURLConstructor(pluginID, pluginVersion string) URLConstructor

NewCDNURLConstructor returns a new URLConstructor for the provided plugin id and version. The CDN should be enabled for the plugin, otherwise the returned URLConstructor will have and invalid base url.

func (*Service) PluginSupported

func (s *Service) PluginSupported(pluginID string) bool

PluginSupported returns true if the CDN is enabled in the config and if the specified plugin ID has CDN enabled.

func (*Service) SystemJSAssetPath

func (s *Service) SystemJSAssetPath(pluginID, pluginVersion, assetPath string) (string, error)

SystemJSAssetPath returns a system-js path for the specified asset on the plugins CDN. The returned path will follow the template specified in systemJSCDNURLTemplate. If assetPath is an empty string, the base path for the plugin is returned.

type URLConstructor

type URLConstructor struct {
	// contains filtered or unexported fields
}

URLConstructor is a struct that can build CDN URLs for plugins on a remote CDN.

func (URLConstructor) Path

func (c URLConstructor) Path(assetPath string) (*url.URL, error)

Path returns a new *url.URL that points to an asset file for the CDN, plugin and plugin version specified by the current URLConstructor.

c.cdnURLTemplate is used to build the string, the following substitutions are performed in it:

- {id} -> plugin id

- {version} -> plugin version

- {assetPath} -> assetPath

The asset Path is sanitized via path.Clean (double slashes are removed, "../" is resolved, etc).

The returned URL will be for a file, so it won't have a trailing slash.

func (URLConstructor) StringPath

func (c URLConstructor) StringPath(assetPath string) (string, error)

StringPath is like Path, but it returns the absolute URL as a string rather than *url.URL.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL