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
- Variables
- type Cache
- func (c Cache) CreateTask(ctx context.Context, pluginID string, operationName string, ...) (Task, error)
- func (c Cache) ExecutePostHooks(ctx context.Context, id int, hookType HookTriggerEnum, input interface{}, ...)
- func (c Cache) ExecuteSceneUpdatePostHooks(ctx context.Context, input models.SceneUpdateInput, inputFields []string)
- func (c Cache) GetPlugin(id string) *Plugin
- func (c Cache) ListPluginTasks() []*PluginTask
- func (c Cache) ListPlugins() []*Plugin
- func (c *Cache) RegisterGQLHandler(handler http.Handler)
- func (c Cache) RegisterPostHooks(ctx context.Context, id int, hookType HookTriggerEnum, input interface{}, ...)
- func (c *Cache) RegisterSessionStore(sessionStore *session.Store)
- func (c *Cache) ReloadPlugins()
- type Config
- type GalleryDestroyInput
- type HookConfig
- type HookTriggerEnum
- type ImageDestroyInput
- type ImagesDestroyInput
- type OperationConfig
- type Plugin
- type PluginArgInput
- type PluginCSP
- type PluginHook
- type PluginSetting
- type PluginSettingTypeEnum
- type PluginTask
- type PluginUI
- type PluginValueInput
- type SceneDestroyInput
- type ScenesDestroyInput
- type ServerConfig
- type SettingConfig
- type Task
- type UIConfig
Constants ¶
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 ¶
var AllHookTriggerEnum = []HookTriggerEnum{ SceneMarkerCreatePost, SceneMarkerUpdatePost, SceneMarkerDestroyPost, SceneCreatePost, SceneUpdatePost, SceneDestroyPost, ImageCreatePost, ImageUpdatePost, ImageDestroyPost, GalleryCreatePost, GalleryUpdatePost, GalleryDestroyPost, GalleryChapterCreatePost, GalleryChapterUpdatePost, GalleryChapterDestroyPost, MovieCreatePost, MovieUpdatePost, MovieDestroyPost, PerformerCreatePost, PerformerUpdatePost, PerformerDestroyPost, StudioCreatePost, StudioUpdatePost, StudioDestroyPost, TagCreatePost, TagUpdatePost, TagMergePost, TagDestroyPost, }
var AllPluginSettingTypeEnum = []PluginSettingTypeEnum{ PluginSettingTypeEnumString, PluginSettingTypeEnumNumber, PluginSettingTypeEnumBoolean, }
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 []*PluginArgInput, 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 (Cache) ExecuteSceneUpdatePostHooks ¶ added in v0.11.0
func (Cache) GetPlugin ¶ added in v0.24.0
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 ¶
ListPlugins returns plugin details for all of the loaded plugins.
func (*Cache) RegisterGQLHandler ¶ added in v0.8.0
func (Cache) RegisterPostHooks ¶ added in v0.17.0
func (*Cache) RegisterSessionStore ¶ added in v0.8.0
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.
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 []HookTriggerEnum `yaml:"triggeredBy"` }
type HookTriggerEnum ¶ added in v0.8.0
type HookTriggerEnum string
const ( SceneMarkerCreatePost HookTriggerEnum = "SceneMarker.Create.Post" SceneMarkerUpdatePost HookTriggerEnum = "SceneMarker.Update.Post" SceneMarkerDestroyPost HookTriggerEnum = "SceneMarker.Destroy.Post" SceneCreatePost HookTriggerEnum = "Scene.Create.Post" SceneUpdatePost HookTriggerEnum = "Scene.Update.Post" SceneDestroyPost HookTriggerEnum = "Scene.Destroy.Post" ImageCreatePost HookTriggerEnum = "Image.Create.Post" ImageUpdatePost HookTriggerEnum = "Image.Update.Post" ImageDestroyPost HookTriggerEnum = "Image.Destroy.Post" GalleryCreatePost HookTriggerEnum = "Gallery.Create.Post" GalleryUpdatePost HookTriggerEnum = "Gallery.Update.Post" GalleryDestroyPost HookTriggerEnum = "Gallery.Destroy.Post" GalleryChapterCreatePost HookTriggerEnum = "GalleryChapter.Create.Post" GalleryChapterUpdatePost HookTriggerEnum = "GalleryChapter.Update.Post" GalleryChapterDestroyPost HookTriggerEnum = "GalleryChapter.Destroy.Post" MovieCreatePost HookTriggerEnum = "Movie.Create.Post" MovieUpdatePost HookTriggerEnum = "Movie.Update.Post" MovieDestroyPost HookTriggerEnum = "Movie.Destroy.Post" PerformerCreatePost HookTriggerEnum = "Performer.Create.Post" PerformerUpdatePost HookTriggerEnum = "Performer.Update.Post" PerformerDestroyPost HookTriggerEnum = "Performer.Destroy.Post" StudioCreatePost HookTriggerEnum = "Studio.Create.Post" StudioUpdatePost HookTriggerEnum = "Studio.Update.Post" StudioDestroyPost HookTriggerEnum = "Studio.Destroy.Post" TagCreatePost HookTriggerEnum = "Tag.Create.Post" TagUpdatePost HookTriggerEnum = "Tag.Update.Post" TagMergePost HookTriggerEnum = "Tag.Merge.Post" TagDestroyPost HookTriggerEnum = "Tag.Destroy.Post" )
func (HookTriggerEnum) IsValid ¶ added in v0.8.0
func (e HookTriggerEnum) IsValid() bool
func (HookTriggerEnum) String ¶ added in v0.8.0
func (e HookTriggerEnum) String() string
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 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 PluginHook ¶ added in v0.17.0
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 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 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"` }
Source Files ¶
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. |