plugin

package
v0.25.1 Latest Latest
Warning

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

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

Documentation

Overview

Package plugin implements functions and types for maintaining and running stash plugins.

Stash plugins are configured using yml files in the configured plugins directory. These yml files must follow the Config structure format.

The main entry into the plugin sub-system is via the Cache type.

Index

Constants

View Source
const (
	// InterfaceEnumRPC indicates that the plugin uses the RPCRunner interface
	// declared in common/rpc.go.
	InterfaceEnumRPC interfaceEnum = "rpc"

	// InterfaceEnumRaw interfaces will have the common.PluginInput encoded as
	// json (but may be ignored), and output will be decoded as
	// common.PluginOutput. If this decoding fails, then the raw output will be
	// treated as the output.
	InterfaceEnumRaw interfaceEnum = "raw"

	InterfaceEnumJS interfaceEnum = "js"
)

Valid interfaceEnum values

Variables

Functions

This section is empty.

Types

type Cache

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

Cache stores plugin details.

func NewCache

func NewCache(config ServerConfig) *Cache

NewCache returns a new Cache.

Plugins configurations are loaded from yml files in the plugin directory in the config and any subdirectories.

Does not load plugins. Plugins will need to be loaded explicitly using ReloadPlugins.

func (Cache) CreateTask

func (c Cache) CreateTask(ctx context.Context, pluginID string, operationName *string, args OperationInput, progress chan float64) (Task, error)

CreateTask runs the plugin operation for the pluginID and operation name provided. Returns an error if the plugin or the operation could not be resolved.

func (Cache) ExecutePostHooks added in v0.8.0

func (c Cache) ExecutePostHooks(ctx context.Context, id int, hookType hook.TriggerEnum, input interface{}, inputFields []string)

func (Cache) ExecuteSceneUpdatePostHooks added in v0.11.0

func (c Cache) ExecuteSceneUpdatePostHooks(ctx context.Context, input models.SceneUpdateInput, inputFields []string)

func (Cache) GetPlugin added in v0.24.0

func (c Cache) GetPlugin(id string) *Plugin

GetPlugin returns the plugin with the given ID. Returns nil if the plugin is not found.

func (Cache) ListPluginTasks

func (c Cache) ListPluginTasks() []*PluginTask

ListPluginTasks returns all runnable plugin tasks in all loaded plugins.

func (Cache) ListPlugins

func (c Cache) ListPlugins() []*Plugin

ListPlugins returns plugin details for all of the loaded plugins.

func (*Cache) RegisterGQLHandler added in v0.8.0

func (c *Cache) RegisterGQLHandler(handler http.Handler)

func (Cache) RegisterPostHooks added in v0.17.0

func (c Cache) RegisterPostHooks(ctx context.Context, id int, hookType hook.TriggerEnum, input interface{}, inputFields []string)

func (*Cache) RegisterSessionStore added in v0.8.0

func (c *Cache) RegisterSessionStore(sessionStore *session.Store)

func (*Cache) ReloadPlugins

func (c *Cache) ReloadPlugins()

ReloadPlugins clears the plugin cache and loads from the plugin path. If a plugin cannot be loaded, an error is logged and the plugin is skipped.

func (Cache) RunPlugin added in v0.25.0

func (c Cache) RunPlugin(ctx context.Context, pluginID string, args OperationInput) (interface{}, error)

type Config

type Config struct {

	// The name of the plugin. This will be displayed in the UI.
	Name string `yaml:"name"`

	// An optional description of what the plugin does.
	Description *string `yaml:"description"`

	// An optional URL for the plugin.
	URL *string `yaml:"url"`

	// An optional version string.
	Version *string `yaml:"version"`

	// The communication interface used when communicating with the spawned
	// plugin process. Defaults to 'raw' if not provided.
	Interface interfaceEnum `yaml:"interface"`

	// The command to execute for the operations in this plugin. The first
	// element should be the program name, and subsequent elements are passed
	// as arguments.
	//
	// Note: the execution process will search the path for the program,
	// then will attempt to find the program in the plugins
	// directory. The exe extension is not necessary on Windows platforms.
	// The current working directory is set to that of the stash process.
	Exec []string `yaml:"exec,flow"`

	// The default log level to output the plugin process's stderr stream.
	// Only used if the plugin does not encode its output using log level
	// control characters.
	// See package common/log for valid values.
	// If left unset, defaults to log.ErrorLevel.
	PluginErrLogLevel string `yaml:"errLog"`

	// The task configurations for tasks provided by this plugin.
	Tasks []*OperationConfig `yaml:"tasks"`

	// The hooks configurations for hooks registered by this plugin.
	Hooks []*HookConfig `yaml:"hooks"`

	// Javascript files that will be injected into the stash UI.
	UI UIConfig `yaml:"ui"`

	// Settings that will be used to configure the plugin.
	Settings map[string]SettingConfig `yaml:"settings"`
	// contains filtered or unexported fields
}

Config describes the configuration for a single plugin.

type GalleryDestroyInput added in v0.12.0

type GalleryDestroyInput struct {
	models.GalleryDestroyInput
	Checksum string `json:"checksum"`
	Path     string `json:"path"`
}

type HookConfig added in v0.8.0

type HookConfig struct {
	OperationConfig `yaml:",inline"`

	// A list of stash operations that will be used to trigger this hook operation.
	TriggeredBy []hook.TriggerEnum `yaml:"triggeredBy"`
}

type ImageDestroyInput added in v0.12.0

type ImageDestroyInput struct {
	models.ImageDestroyInput
	Checksum string `json:"checksum"`
	Path     string `json:"path"`
}

type ImagesDestroyInput added in v0.12.0

type ImagesDestroyInput struct {
	models.ImagesDestroyInput
	Checksum string `json:"checksum"`
	Path     string `json:"path"`
}

type OperationConfig

type OperationConfig struct {
	// Used to identify the operation. Must be unique within a plugin
	// configuration. This name is shown in the button for the operation
	// in the UI.
	Name string `yaml:"name"`

	// A short description of the operation. This description is shown below
	// the button in the UI.
	Description string `yaml:"description"`

	// A list of arguments that will be appended to the plugin's Exec arguments
	// when executing this operation.
	ExecArgs []string `yaml:"execArgs"`

	// A map of argument keys to their default values. The default value is
	// used if the applicable argument is not provided during the operation
	// call.
	DefaultArgs map[string]string `yaml:"defaultArgs"`
}

OperationConfig describes the configuration for a single plugin operation provided by a plugin.

type OperationInput added in v0.25.0

type OperationInput map[string]interface{}

type Plugin added in v0.17.0

type Plugin struct {
	ID          string          `json:"id"`
	Name        string          `json:"name"`
	Description *string         `json:"description"`
	URL         *string         `json:"url"`
	Version     *string         `json:"version"`
	Tasks       []*PluginTask   `json:"tasks"`
	Hooks       []*PluginHook   `json:"hooks"`
	UI          PluginUI        `json:"ui"`
	Settings    []PluginSetting `json:"settings"`

	Enabled bool `json:"enabled"`

	// ConfigPath is the path to the plugin's configuration file.
	ConfigPath string `json:"-"`
}

type PluginArgInput added in v0.17.0

type PluginArgInput struct {
	Key   string            `json:"key"`
	Value *PluginValueInput `json:"value"`
}

type PluginCSP added in v0.24.0

type PluginCSP struct {
	ScriptSrc  []string `json:"script-src" yaml:"script-src"`
	StyleSrc   []string `json:"style-src" yaml:"style-src"`
	ConnectSrc []string `json:"connect-src" yaml:"connect-src"`
}

type PluginHook added in v0.17.0

type PluginHook struct {
	Name        string   `json:"name"`
	Description *string  `json:"description"`
	Hooks       []string `json:"hooks"`
	Plugin      *Plugin  `json:"plugin"`
}

type PluginSetting added in v0.24.0

type PluginSetting struct {
	Name string `json:"name"`
	// defaults to string
	Type PluginSettingTypeEnum `json:"type"`
	// defaults to key name
	DisplayName string `json:"displayName"`
	Description string `json:"description"`
}

type PluginSettingTypeEnum added in v0.24.0

type PluginSettingTypeEnum string
const (
	PluginSettingTypeEnumString  PluginSettingTypeEnum = "STRING"
	PluginSettingTypeEnumNumber  PluginSettingTypeEnum = "NUMBER"
	PluginSettingTypeEnumBoolean PluginSettingTypeEnum = "BOOLEAN"
)

func (PluginSettingTypeEnum) IsValid added in v0.24.0

func (e PluginSettingTypeEnum) IsValid() bool

func (PluginSettingTypeEnum) MarshalGQL added in v0.24.0

func (e PluginSettingTypeEnum) MarshalGQL(w io.Writer)

func (PluginSettingTypeEnum) String added in v0.24.0

func (e PluginSettingTypeEnum) String() string

func (*PluginSettingTypeEnum) UnmarshalGQL added in v0.24.0

func (e *PluginSettingTypeEnum) UnmarshalGQL(v interface{}) error

type PluginTask added in v0.17.0

type PluginTask struct {
	Name        string  `json:"name"`
	Description *string `json:"description"`
	Plugin      *Plugin `json:"plugin"`
}

type PluginUI added in v0.19.0

type PluginUI struct {
	// Requires is a list of plugin IDs that this plugin depends on.
	// These plugins will be loaded before this plugin.
	Requires []string `json:"requires"`

	// Content Security Policy configuration for the plugin.
	CSP PluginCSP `json:"csp"`

	// External Javascript files that will be injected into the stash UI.
	ExternalScript []string `json:"external_script"`

	// External CSS files that will be injected into the stash UI.
	ExternalCSS []string `json:"external_css"`

	// Javascript files that will be injected into the stash UI.
	Javascript []string `json:"javascript"`

	// CSS files that will be injected into the stash UI.
	CSS []string `json:"css"`

	// Assets is a map of URL prefixes to hosted directories.
	// This allows plugins to serve static assets from a URL path.
	// Plugin assets are exposed via the /plugin/{pluginId}/assets path.
	// For example, if the plugin configuration file contains:
	// /foo: bar
	// /bar: baz
	// /: root
	// Then the following requests will be mapped to the following files:
	// /plugin/{pluginId}/assets/foo/file.txt -> {pluginDir}/foo/file.txt
	// /plugin/{pluginId}/assets/bar/file.txt -> {pluginDir}/baz/file.txt
	// /plugin/{pluginId}/assets/file.txt -> {pluginDir}/root/file.txt
	Assets utils.URLMap `json:"assets"`
}

type PluginValueInput added in v0.17.0

type PluginValueInput struct {
	Str *string             `json:"str"`
	I   *int                `json:"i"`
	B   *bool               `json:"b"`
	F   *float64            `json:"f"`
	O   []*PluginArgInput   `json:"o"`
	A   []*PluginValueInput `json:"a"`
}

type SceneDestroyInput added in v0.12.0

type SceneDestroyInput struct {
	models.SceneDestroyInput
	Checksum string `json:"checksum"`
	OSHash   string `json:"oshash"`
	Path     string `json:"path"`
}

types for destroy hooks, to provide a little more information

type ScenesDestroyInput added in v0.12.0

type ScenesDestroyInput struct {
	models.ScenesDestroyInput
	Checksum string `json:"checksum"`
	OSHash   string `json:"oshash"`
	Path     string `json:"path"`
}

type ServerConfig added in v0.14.0

type ServerConfig interface {
	GetHost() string
	GetPort() int
	GetConfigPath() string
	HasTLSConfig() bool
	GetPluginsPath() string
	GetDisabledPlugins() []string
	GetPythonPath() string
}

type SettingConfig added in v0.24.0

type SettingConfig struct {
	// defaults to string
	Type PluginSettingTypeEnum `yaml:"type"`
	// defaults to key name
	DisplayName string `yaml:"displayName"`
	Description string `yaml:"description"`
}

type Task

type Task interface {
	// Start starts the plugin task. Returns an error if task could not be
	// started or the task has already been started.
	Start() error

	// Stop instructs a running plugin task to stop and returns immediately.
	// Use Wait to subsequently wait for the task to stop.
	Stop() error

	// Wait blocks until the plugin task is complete. Returns immediately if
	// task has not been started.
	Wait()

	// GetResult returns the output of the plugin task. Returns nil if the task
	// has not completed.
	GetResult() *common.PluginOutput
}

Task is the interface that handles management of a single plugin task.

type UIConfig added in v0.19.0

type UIConfig struct {
	// Requires is a list of plugin IDs that this plugin depends on.
	// These plugins will be loaded before this plugin.
	Requires []string `yaml:"requires"`

	// Content Security Policy configuration for the plugin.
	CSP PluginCSP `yaml:"csp"`

	// Javascript files that will be injected into the stash UI.
	// These may be URLs or paths to files relative to the plugin configuration file.
	Javascript []string `yaml:"javascript"`

	// CSS files that will be injected into the stash UI.
	// These may be URLs or paths to files relative to the plugin configuration file.
	CSS []string `yaml:"css"`

	// Assets is a map of URL prefixes to hosted directories.
	// This allows plugins to serve static assets from a URL path.
	// Plugin assets are exposed via the /plugin/{pluginId}/assets path.
	// For example, if the plugin configuration file contains:
	// /foo: bar
	// /bar: baz
	// /: root
	// Then the following requests will be mapped to the following files:
	// /plugin/{pluginId}/assets/foo/file.txt -> {pluginDir}/foo/file.txt
	// /plugin/{pluginId}/assets/bar/file.txt -> {pluginDir}/baz/file.txt
	// /plugin/{pluginId}/assets/file.txt -> {pluginDir}/root/file.txt
	Assets utils.URLMap `yaml:"assets"`
}

Directories

Path Synopsis
Package common encapulates data structures and functions that will be used by plugin executables and the plugin subsystem in the stash server.
Package common encapulates data structures and functions that will be used by plugin executables and the plugin subsystem in the stash server.
log
Package log provides a number of logging utility functions for encoding and decoding log messages between a stash server and a plugin instance.
Package log provides a number of logging utility functions for encoding and decoding log messages between a stash server and a plugin instance.
Package util implements utility and convenience methods for plugins.
Package util implements utility and convenience methods for plugins.

Jump to

Keyboard shortcuts

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