plugin

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2022 License: AGPL-3.0 Imports: 25 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

func FindPythonExecutable added in v0.11.0

func FindPythonExecutable() (string, error)

Types

type Cache

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

Cache stores plugin details.

func NewCache

func NewCache(config *config.Instance) *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 []*models.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 (c Cache) ExecutePostHooks(ctx context.Context, id int, hookType HookTriggerEnum, 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) ListPluginTasks

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

ListPluginTasks returns all runnable plugin tasks in all loaded plugins.

func (Cache) ListPlugins

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

ListPlugins returns plugin details for all of the loaded plugins.

func (*Cache) LoadPlugins added in v0.8.0

func (c *Cache) LoadPlugins() error

LoadPlugins clears the plugin cache and loads from the plugin path. In the event of an error during loading, the cache will be left empty.

func (*Cache) RegisterGQLHandler added in v0.8.0

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

func (*Cache) RegisterSessionStore added in v0.8.0

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

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"`
	// 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"

	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 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 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.

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