Include path and hashes in destroy hook input (#2102)

This commit is contained in:
WithoutPants
2021-12-13 14:38:00 +11:00
committed by GitHub
parent 9a8f05d826
commit 79e01589ca
6 changed files with 91 additions and 10 deletions

View File

@@ -494,12 +494,19 @@ func (r *mutationResolver) GalleryDestroy(ctx context.Context, input models.Gall
// call post hook after performing the other actions // call post hook after performing the other actions
for _, gallery := range galleries { for _, gallery := range galleries {
r.hookExecutor.ExecutePostHooks(ctx, gallery.ID, plugin.GalleryDestroyPost, input, nil) r.hookExecutor.ExecutePostHooks(ctx, gallery.ID, plugin.GalleryDestroyPost, plugin.GalleryDestroyInput{
GalleryDestroyInput: input,
Checksum: gallery.Checksum,
Path: gallery.Path.String,
}, nil)
} }
// call image destroy post hook as well // call image destroy post hook as well
for _, img := range imgsDestroyed { for _, img := range imgsDestroyed {
r.hookExecutor.ExecutePostHooks(ctx, img.ID, plugin.ImageDestroyPost, nil, nil) r.hookExecutor.ExecutePostHooks(ctx, img.ID, plugin.ImageDestroyPost, plugin.ImageDestroyInput{
Checksum: img.Checksum,
Path: img.Path,
}, nil)
} }
return true, nil return true, nil

View File

@@ -310,7 +310,11 @@ func (r *mutationResolver) ImageDestroy(ctx context.Context, input models.ImageD
fileDeleter.Commit() fileDeleter.Commit()
// call post hook after performing the other actions // call post hook after performing the other actions
r.hookExecutor.ExecutePostHooks(ctx, i.ID, plugin.ImageDestroyPost, input, nil) r.hookExecutor.ExecutePostHooks(ctx, i.ID, plugin.ImageDestroyPost, plugin.ImageDestroyInput{
ImageDestroyInput: input,
Checksum: i.Checksum,
Path: i.Path,
}, nil)
return true, nil return true, nil
} }
@@ -358,7 +362,11 @@ func (r *mutationResolver) ImagesDestroy(ctx context.Context, input models.Image
for _, image := range images { for _, image := range images {
// call post hook after performing the other actions // call post hook after performing the other actions
r.hookExecutor.ExecutePostHooks(ctx, image.ID, plugin.ImageDestroyPost, input, nil) r.hookExecutor.ExecutePostHooks(ctx, image.ID, plugin.ImageDestroyPost, plugin.ImagesDestroyInput{
ImagesDestroyInput: input,
Checksum: image.Checksum,
Path: image.Path,
}, nil)
} }
return true, nil return true, nil

View File

@@ -494,7 +494,12 @@ func (r *mutationResolver) SceneDestroy(ctx context.Context, input models.SceneD
fileDeleter.Commit() fileDeleter.Commit()
// call post hook after performing the other actions // call post hook after performing the other actions
r.hookExecutor.ExecutePostHooks(ctx, s.ID, plugin.SceneDestroyPost, input, nil) r.hookExecutor.ExecutePostHooks(ctx, s.ID, plugin.SceneDestroyPost, plugin.SceneDestroyInput{
SceneDestroyInput: input,
Checksum: s.Checksum.String,
OSHash: s.OSHash.String,
Path: s.Path,
}, nil)
return true, nil return true, nil
} }
@@ -545,7 +550,12 @@ func (r *mutationResolver) ScenesDestroy(ctx context.Context, input models.Scene
for _, scene := range scenes { for _, scene := range scenes {
// call post hook after performing the other actions // call post hook after performing the other actions
r.hookExecutor.ExecutePostHooks(ctx, scene.ID, plugin.SceneDestroyPost, input, nil) r.hookExecutor.ExecutePostHooks(ctx, scene.ID, plugin.SceneDestroyPost, plugin.ScenesDestroyInput{
ScenesDestroyInput: input,
Checksum: scene.Checksum.String,
OSHash: scene.OSHash.String,
Path: scene.Path,
}, nil)
} }
return true, nil return true, nil

View File

@@ -411,19 +411,35 @@ func (j *cleanJob) deleteScene(ctx context.Context, fileNamingAlgorithm models.H
// perform the post-commit actions // perform the post-commit actions
fileDeleter.Commit() fileDeleter.Commit()
GetInstance().PluginCache.ExecutePostHooks(ctx, sceneID, plugin.SceneDestroyPost, nil, nil) GetInstance().PluginCache.ExecutePostHooks(ctx, sceneID, plugin.SceneDestroyPost, plugin.SceneDestroyInput{
Checksum: s.Checksum.String,
OSHash: s.OSHash.String,
Path: s.Path,
}, nil)
} }
func (j *cleanJob) deleteGallery(ctx context.Context, galleryID int) { func (j *cleanJob) deleteGallery(ctx context.Context, galleryID int) {
var g *models.Gallery
if err := j.txnManager.WithTxn(context.TODO(), func(repo models.Repository) error { if err := j.txnManager.WithTxn(context.TODO(), func(repo models.Repository) error {
qb := repo.Gallery() qb := repo.Gallery()
var err error
g, err = qb.Find(galleryID)
if err != nil {
return err
}
return qb.Destroy(galleryID) return qb.Destroy(galleryID)
}); err != nil { }); err != nil {
logger.Errorf("Error deleting gallery from database: %s", err.Error()) logger.Errorf("Error deleting gallery from database: %s", err.Error())
return return
} }
GetInstance().PluginCache.ExecutePostHooks(ctx, galleryID, plugin.GalleryDestroyPost, nil, nil) GetInstance().PluginCache.ExecutePostHooks(ctx, galleryID, plugin.GalleryDestroyPost, plugin.GalleryDestroyInput{
Checksum: g.Checksum,
Path: g.Path.String,
}, nil)
} }
func (j *cleanJob) deleteImage(ctx context.Context, imageID int) { func (j *cleanJob) deleteImage(ctx context.Context, imageID int) {
@@ -432,10 +448,12 @@ func (j *cleanJob) deleteImage(ctx context.Context, imageID int) {
Paths: GetInstance().Paths, Paths: GetInstance().Paths,
} }
var i *models.Image
if err := j.txnManager.WithTxn(context.TODO(), func(repo models.Repository) error { if err := j.txnManager.WithTxn(context.TODO(), func(repo models.Repository) error {
qb := repo.Image() qb := repo.Image()
i, err := qb.Find(imageID) var err error
i, err = qb.Find(imageID)
if err != nil { if err != nil {
return err return err
} }
@@ -454,7 +472,10 @@ func (j *cleanJob) deleteImage(ctx context.Context, imageID int) {
// perform the post-commit actions // perform the post-commit actions
fileDeleter.Commit() fileDeleter.Commit()
GetInstance().PluginCache.ExecutePostHooks(ctx, imageID, plugin.ImageDestroyPost, nil, nil) GetInstance().PluginCache.ExecutePostHooks(ctx, imageID, plugin.ImageDestroyPost, plugin.ImageDestroyInput{
Checksum: i.Checksum,
Path: i.Path,
}, nil)
} }
func getStashFromPath(pathToCheck string) *models.StashConfig { func getStashFromPath(pathToCheck string) *models.StashConfig {

View File

@@ -1,6 +1,7 @@
package plugin package plugin
import ( import (
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/plugin/common" "github.com/stashapp/stash/pkg/plugin/common"
) )
@@ -125,3 +126,36 @@ func (e HookTriggerEnum) String() string {
func addHookContext(argsMap common.ArgsMap, hookContext common.HookContext) { func addHookContext(argsMap common.ArgsMap, hookContext common.HookContext) {
argsMap[common.HookContextKey] = hookContext argsMap[common.HookContextKey] = hookContext
} }
// types for destroy hooks, to provide a little more information
type SceneDestroyInput struct {
models.SceneDestroyInput
Checksum string `json:"checksum"`
OSHash string `json:"oshash"`
Path string `json:"path"`
}
type ScenesDestroyInput struct {
models.ScenesDestroyInput
Checksum string `json:"checksum"`
OSHash string `json:"oshash"`
Path string `json:"path"`
}
type GalleryDestroyInput struct {
models.GalleryDestroyInput
Checksum string `json:"checksum"`
Path string `json:"path"`
}
type ImageDestroyInput struct {
models.ImageDestroyInput
Checksum string `json:"checksum"`
Path string `json:"path"`
}
type ImagesDestroyInput struct {
models.ImagesDestroyInput
Checksum string `json:"checksum"`
Path string `json:"path"`
}

View File

@@ -5,6 +5,7 @@
* Add forward jump 10 second button to video player. ([#1973](https://github.com/stashapp/stash/pull/1973)) * Add forward jump 10 second button to video player. ([#1973](https://github.com/stashapp/stash/pull/1973))
### 🎨 Improvements ### 🎨 Improvements
* Include path and hashes in destroy scene/image/gallery post hook input. ([#2102](https://github.com/stashapp/stash/pull/2102/files))
* Rollback operation if files fail to be deleted. ([#1954](https://github.com/stashapp/stash/pull/1954)) * Rollback operation if files fail to be deleted. ([#1954](https://github.com/stashapp/stash/pull/1954))
* Prefer right-most Studio match in the file path when autotagging. ([#2057](https://github.com/stashapp/stash/pull/2057)) * Prefer right-most Studio match in the file path when autotagging. ([#2057](https://github.com/stashapp/stash/pull/2057))
* Added plugin hook for Tag merge operation. ([#2010](https://github.com/stashapp/stash/pull/2010)) * Added plugin hook for Tag merge operation. ([#2010](https://github.com/stashapp/stash/pull/2010))