mirror of
https://github.com/stashapp/stash.git
synced 2025-12-16 20:07:05 +03:00
Correct Stash box endpoint inputs (#4924)
* Use stashbox endpoint instead of index * Update UI to not use deprecated fields
This commit is contained in:
@@ -128,7 +128,7 @@ input ScraperSourceInput {
|
||||
stash_box_index: Int @deprecated(reason: "use stash_box_endpoint")
|
||||
"Stash-box endpoint"
|
||||
stash_box_endpoint: String
|
||||
"Scraper ID to scrape with. Should be unset if stash_box_index is set"
|
||||
"Scraper ID to scrape with. Should be unset if stash_box_endpoint/stash_box_index is set"
|
||||
scraper_id: ID
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ type ScraperSource {
|
||||
stash_box_index: Int @deprecated(reason: "use stash_box_endpoint")
|
||||
"Stash-box endpoint"
|
||||
stash_box_endpoint: String
|
||||
"Scraper ID to scrape with. Should be unset if stash_box_index is set"
|
||||
"Scraper ID to scrape with. Should be unset if stash_box_endpoint/stash_box_index is set"
|
||||
scraper_id: ID
|
||||
}
|
||||
|
||||
@@ -196,7 +196,9 @@ input ScrapeSingleMovieInput {
|
||||
|
||||
input StashBoxSceneQueryInput {
|
||||
"Index of the configured stash-box instance to use"
|
||||
stash_box_index: Int!
|
||||
stash_box_index: Int @deprecated(reason: "use stash_box_endpoint")
|
||||
"Endpoint of the stash-box instance to use"
|
||||
stash_box_endpoint: String
|
||||
"Instructs query by scene fingerprints"
|
||||
scene_ids: [ID!]
|
||||
"Query by query string"
|
||||
@@ -205,7 +207,9 @@ input StashBoxSceneQueryInput {
|
||||
|
||||
input StashBoxPerformerQueryInput {
|
||||
"Index of the configured stash-box instance to use"
|
||||
stash_box_index: Int!
|
||||
stash_box_index: Int @deprecated(reason: "use stash_box_endpoint")
|
||||
"Endpoint of the stash-box instance to use"
|
||||
stash_box_endpoint: String
|
||||
"Instructs query by scene fingerprints"
|
||||
performer_ids: [ID!]
|
||||
"Query by query string"
|
||||
@@ -226,7 +230,9 @@ type StashBoxFingerprint {
|
||||
"If neither ids nor names are set, tag all items"
|
||||
input StashBoxBatchTagInput {
|
||||
"Stash endpoint to use for the tagging"
|
||||
endpoint: Int!
|
||||
endpoint: Int @deprecated(reason: "use stash_box_endpoint")
|
||||
"Endpoint of the stash-box instance to use"
|
||||
stash_box_endpoint: String
|
||||
"Fields to exclude when executing the tagging"
|
||||
exclude_fields: [String!]
|
||||
"Refresh items already tagged by StashBox if true. Only tag items with no StashBox tagging if false"
|
||||
|
||||
@@ -22,10 +22,12 @@ input StashIDInput {
|
||||
|
||||
input StashBoxFingerprintSubmissionInput {
|
||||
scene_ids: [String!]!
|
||||
stash_box_index: Int!
|
||||
stash_box_index: Int @deprecated(reason: "use stash_box_endpoint")
|
||||
stash_box_endpoint: String
|
||||
}
|
||||
|
||||
input StashBoxDraftSubmissionInput {
|
||||
id: String!
|
||||
stash_box_index: Int!
|
||||
stash_box_index: Int @deprecated(reason: "use stash_box_endpoint")
|
||||
stash_box_endpoint: String
|
||||
}
|
||||
|
||||
@@ -6,41 +6,46 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/stashapp/stash/internal/manager"
|
||||
"github.com/stashapp/stash/internal/manager/config"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/scraper/stashbox"
|
||||
)
|
||||
|
||||
func (r *mutationResolver) SubmitStashBoxFingerprints(ctx context.Context, input StashBoxFingerprintSubmissionInput) (bool, error) {
|
||||
boxes := config.GetInstance().GetStashBoxes()
|
||||
|
||||
if input.StashBoxIndex < 0 || input.StashBoxIndex >= len(boxes) {
|
||||
return false, fmt.Errorf("invalid stash_box_index %d", input.StashBoxIndex)
|
||||
b, err := resolveStashBox(input.StashBoxIndex, input.StashBoxEndpoint)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
client := stashbox.NewClient(*boxes[input.StashBoxIndex], r.stashboxRepository())
|
||||
|
||||
return client.SubmitStashBoxFingerprints(ctx, input.SceneIds, boxes[input.StashBoxIndex].Endpoint)
|
||||
client := r.newStashBoxClient(*b)
|
||||
return client.SubmitStashBoxFingerprints(ctx, input.SceneIds)
|
||||
}
|
||||
|
||||
func (r *mutationResolver) StashBoxBatchPerformerTag(ctx context.Context, input manager.StashBoxBatchTagInput) (string, error) {
|
||||
jobID := manager.GetInstance().StashBoxBatchPerformerTag(ctx, input)
|
||||
b, err := resolveStashBoxBatchTagInput(input.Endpoint, input.StashBoxEndpoint)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
jobID := manager.GetInstance().StashBoxBatchPerformerTag(ctx, b, input)
|
||||
return strconv.Itoa(jobID), nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) StashBoxBatchStudioTag(ctx context.Context, input manager.StashBoxBatchTagInput) (string, error) {
|
||||
jobID := manager.GetInstance().StashBoxBatchStudioTag(ctx, input)
|
||||
b, err := resolveStashBoxBatchTagInput(input.Endpoint, input.StashBoxEndpoint)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
jobID := manager.GetInstance().StashBoxBatchStudioTag(ctx, b, input)
|
||||
return strconv.Itoa(jobID), nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) SubmitStashBoxSceneDraft(ctx context.Context, input StashBoxDraftSubmissionInput) (*string, error) {
|
||||
boxes := config.GetInstance().GetStashBoxes()
|
||||
|
||||
if input.StashBoxIndex < 0 || input.StashBoxIndex >= len(boxes) {
|
||||
return nil, fmt.Errorf("invalid stash_box_index %d", input.StashBoxIndex)
|
||||
b, err := resolveStashBox(input.StashBoxIndex, input.StashBoxEndpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := stashbox.NewClient(*boxes[input.StashBoxIndex], r.stashboxRepository())
|
||||
client := r.newStashBoxClient(*b)
|
||||
|
||||
id, err := strconv.Atoi(input.ID)
|
||||
if err != nil {
|
||||
@@ -68,7 +73,7 @@ func (r *mutationResolver) SubmitStashBoxSceneDraft(ctx context.Context, input S
|
||||
return fmt.Errorf("loading scene URLs: %w", err)
|
||||
}
|
||||
|
||||
res, err = client.SubmitSceneDraft(ctx, scene, boxes[input.StashBoxIndex].Endpoint, cover)
|
||||
res, err = client.SubmitSceneDraft(ctx, scene, cover)
|
||||
return err
|
||||
})
|
||||
|
||||
@@ -76,13 +81,12 @@ func (r *mutationResolver) SubmitStashBoxSceneDraft(ctx context.Context, input S
|
||||
}
|
||||
|
||||
func (r *mutationResolver) SubmitStashBoxPerformerDraft(ctx context.Context, input StashBoxDraftSubmissionInput) (*string, error) {
|
||||
boxes := config.GetInstance().GetStashBoxes()
|
||||
|
||||
if input.StashBoxIndex < 0 || input.StashBoxIndex >= len(boxes) {
|
||||
return nil, fmt.Errorf("invalid stash_box_index %d", input.StashBoxIndex)
|
||||
b, err := resolveStashBox(input.StashBoxIndex, input.StashBoxEndpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := stashbox.NewClient(*boxes[input.StashBoxIndex], r.stashboxRepository())
|
||||
client := r.newStashBoxClient(*b)
|
||||
|
||||
id, err := strconv.Atoi(input.ID)
|
||||
if err != nil {
|
||||
@@ -101,7 +105,7 @@ func (r *mutationResolver) SubmitStashBoxPerformerDraft(ctx context.Context, inp
|
||||
return fmt.Errorf("performer with id %d not found", id)
|
||||
}
|
||||
|
||||
res, err = client.SubmitPerformerDraft(ctx, performer, boxes[input.StashBoxIndex].Endpoint)
|
||||
res, err = client.SubmitPerformerDraft(ctx, performer)
|
||||
return err
|
||||
})
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/stashapp/stash/internal/manager"
|
||||
"github.com/stashapp/stash/internal/manager/config"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/scraper"
|
||||
@@ -190,18 +189,6 @@ func (r *queryResolver) ScrapeMovieURL(ctx context.Context, url string) (*models
|
||||
return marshalScrapedMovie(content)
|
||||
}
|
||||
|
||||
func (r *queryResolver) getStashBoxClient(index int) (*stashbox.Client, error) {
|
||||
boxes := config.GetInstance().GetStashBoxes()
|
||||
|
||||
if index < 0 || index >= len(boxes) {
|
||||
return nil, fmt.Errorf("%w: invalid stash_box_index %d", ErrInput, index)
|
||||
}
|
||||
|
||||
return stashbox.NewClient(*boxes[index], r.stashboxRepository()), nil
|
||||
}
|
||||
|
||||
// FIXME - in the following resolvers, we're processing the deprecated field and not processing the new endpoint input
|
||||
|
||||
func (r *queryResolver) ScrapeSingleScene(ctx context.Context, source scraper.Source, input ScrapeSingleSceneInput) ([]*scraper.ScrapedScene, error) {
|
||||
var ret []*scraper.ScrapedScene
|
||||
|
||||
@@ -245,12 +232,14 @@ func (r *queryResolver) ScrapeSingleScene(ctx context.Context, source scraper.So
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case source.StashBoxIndex != nil:
|
||||
client, err := r.getStashBoxClient(*source.StashBoxIndex)
|
||||
case source.StashBoxIndex != nil || source.StashBoxEndpoint != nil:
|
||||
b, err := resolveStashBox(source.StashBoxIndex, source.StashBoxEndpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := r.newStashBoxClient(*b)
|
||||
|
||||
switch {
|
||||
case input.SceneID != nil:
|
||||
ret, err = client.FindStashBoxSceneByFingerprints(ctx, sceneID)
|
||||
@@ -275,12 +264,14 @@ func (r *queryResolver) ScrapeSingleScene(ctx context.Context, source scraper.So
|
||||
func (r *queryResolver) ScrapeMultiScenes(ctx context.Context, source scraper.Source, input ScrapeMultiScenesInput) ([][]*scraper.ScrapedScene, error) {
|
||||
if source.ScraperID != nil {
|
||||
return nil, ErrNotImplemented
|
||||
} else if source.StashBoxIndex != nil {
|
||||
client, err := r.getStashBoxClient(*source.StashBoxIndex)
|
||||
} else if source.StashBoxIndex != nil || source.StashBoxEndpoint != nil {
|
||||
b, err := resolveStashBox(source.StashBoxIndex, source.StashBoxEndpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := r.newStashBoxClient(*b)
|
||||
|
||||
sceneIDs, err := stringslice.StringSliceToIntSlice(input.SceneIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -293,12 +284,14 @@ func (r *queryResolver) ScrapeMultiScenes(ctx context.Context, source scraper.So
|
||||
}
|
||||
|
||||
func (r *queryResolver) ScrapeSingleStudio(ctx context.Context, source scraper.Source, input ScrapeSingleStudioInput) ([]*models.ScrapedStudio, error) {
|
||||
if source.StashBoxIndex != nil {
|
||||
client, err := r.getStashBoxClient(*source.StashBoxIndex)
|
||||
if source.StashBoxIndex != nil || source.StashBoxEndpoint != nil {
|
||||
b, err := resolveStashBox(source.StashBoxIndex, source.StashBoxEndpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := r.newStashBoxClient(*b)
|
||||
|
||||
var ret []*models.ScrapedStudio
|
||||
out, err := client.FindStashBoxStudio(ctx, *input.Query)
|
||||
|
||||
@@ -346,13 +339,14 @@ func (r *queryResolver) ScrapeSinglePerformer(ctx context.Context, source scrape
|
||||
default:
|
||||
return nil, ErrNotImplemented
|
||||
}
|
||||
// FIXME - we're relying on a deprecated field and not processing the endpoint input
|
||||
case source.StashBoxIndex != nil:
|
||||
client, err := r.getStashBoxClient(*source.StashBoxIndex)
|
||||
case source.StashBoxIndex != nil || source.StashBoxEndpoint != nil:
|
||||
b, err := resolveStashBox(source.StashBoxIndex, source.StashBoxEndpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := r.newStashBoxClient(*b)
|
||||
|
||||
var res []*stashbox.StashBoxPerformerQueryResult
|
||||
switch {
|
||||
case input.PerformerID != nil:
|
||||
@@ -382,12 +376,14 @@ func (r *queryResolver) ScrapeSinglePerformer(ctx context.Context, source scrape
|
||||
func (r *queryResolver) ScrapeMultiPerformers(ctx context.Context, source scraper.Source, input ScrapeMultiPerformersInput) ([][]*models.ScrapedPerformer, error) {
|
||||
if source.ScraperID != nil {
|
||||
return nil, ErrNotImplemented
|
||||
} else if source.StashBoxIndex != nil {
|
||||
client, err := r.getStashBoxClient(*source.StashBoxIndex)
|
||||
} else if source.StashBoxIndex != nil || source.StashBoxEndpoint != nil {
|
||||
b, err := resolveStashBox(source.StashBoxIndex, source.StashBoxEndpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := r.newStashBoxClient(*b)
|
||||
|
||||
return client.FindStashBoxPerformersByPerformerNames(ctx, input.PerformerIds)
|
||||
}
|
||||
|
||||
@@ -397,7 +393,7 @@ func (r *queryResolver) ScrapeMultiPerformers(ctx context.Context, source scrape
|
||||
func (r *queryResolver) ScrapeSingleGallery(ctx context.Context, source scraper.Source, input ScrapeSingleGalleryInput) ([]*scraper.ScrapedGallery, error) {
|
||||
var ret []*scraper.ScrapedGallery
|
||||
|
||||
if source.StashBoxIndex != nil {
|
||||
if source.StashBoxIndex != nil || source.StashBoxEndpoint != nil {
|
||||
return nil, ErrNotSupported
|
||||
}
|
||||
|
||||
|
||||
45
internal/api/stash_box.go
Normal file
45
internal/api/stash_box.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/stashapp/stash/internal/manager/config"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/scraper/stashbox"
|
||||
)
|
||||
|
||||
func (r *Resolver) newStashBoxClient(box models.StashBox) *stashbox.Client {
|
||||
return stashbox.NewClient(box, r.stashboxRepository())
|
||||
}
|
||||
|
||||
func resolveStashBoxFn(indexField, endpointField string) func(index *int, endpoint *string) (*models.StashBox, error) {
|
||||
return func(index *int, endpoint *string) (*models.StashBox, error) {
|
||||
boxes := config.GetInstance().GetStashBoxes()
|
||||
|
||||
// prefer endpoint over index
|
||||
if endpoint != nil {
|
||||
for _, box := range boxes {
|
||||
if strings.EqualFold(*endpoint, box.Endpoint) {
|
||||
return box, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("stash box not found")
|
||||
}
|
||||
|
||||
if index != nil {
|
||||
if *index < 0 || *index >= len(boxes) {
|
||||
return nil, fmt.Errorf("invalid %s %d", indexField, index)
|
||||
}
|
||||
|
||||
return boxes[*index], nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s not provided", endpointField)
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
resolveStashBox = resolveStashBoxFn("stash_box_index", "stash_box_endpoint")
|
||||
resolveStashBoxBatchTagInput = resolveStashBoxFn("endpoint", "stash_box_endpoint")
|
||||
)
|
||||
@@ -366,8 +366,9 @@ func (s *Manager) MigrateHash(ctx context.Context) int {
|
||||
|
||||
// If neither ids nor names are set, tag all items
|
||||
type StashBoxBatchTagInput struct {
|
||||
// Stash endpoint to use for the tagging
|
||||
Endpoint int `json:"endpoint"`
|
||||
// Stash endpoint to use for the tagging - deprecated - use StashBoxEndpoint
|
||||
Endpoint *int `json:"endpoint"`
|
||||
StashBoxEndpoint *string `json:"stash_box_endpoint"`
|
||||
// Fields to exclude when executing the tagging
|
||||
ExcludeFields []string `json:"exclude_fields"`
|
||||
// Refresh items already tagged by StashBox if true. Only tag items with no StashBox tagging if false
|
||||
@@ -388,16 +389,10 @@ type StashBoxBatchTagInput struct {
|
||||
PerformerNames []string `json:"performer_names"`
|
||||
}
|
||||
|
||||
func (s *Manager) StashBoxBatchPerformerTag(ctx context.Context, input StashBoxBatchTagInput) int {
|
||||
func (s *Manager) StashBoxBatchPerformerTag(ctx context.Context, box *models.StashBox, input StashBoxBatchTagInput) int {
|
||||
j := job.MakeJobExec(func(ctx context.Context, progress *job.Progress) error {
|
||||
logger.Infof("Initiating stash-box batch performer tag")
|
||||
|
||||
boxes := config.GetInstance().GetStashBoxes()
|
||||
if input.Endpoint < 0 || input.Endpoint >= len(boxes) {
|
||||
return fmt.Errorf("invalid stash_box_index %d", input.Endpoint)
|
||||
}
|
||||
box := boxes[input.Endpoint]
|
||||
|
||||
var tasks []StashBoxBatchTagTask
|
||||
|
||||
// The gocritic linter wants to turn this ifElseChain into a switch.
|
||||
@@ -526,16 +521,10 @@ func (s *Manager) StashBoxBatchPerformerTag(ctx context.Context, input StashBoxB
|
||||
return s.JobManager.Add(ctx, "Batch stash-box performer tag...", j)
|
||||
}
|
||||
|
||||
func (s *Manager) StashBoxBatchStudioTag(ctx context.Context, input StashBoxBatchTagInput) int {
|
||||
func (s *Manager) StashBoxBatchStudioTag(ctx context.Context, box *models.StashBox, input StashBoxBatchTagInput) int {
|
||||
j := job.MakeJobExec(func(ctx context.Context, progress *job.Progress) error {
|
||||
logger.Infof("Initiating stash-box batch studio tag")
|
||||
|
||||
boxes := config.GetInstance().GetStashBoxes()
|
||||
if input.Endpoint < 0 || input.Endpoint >= len(boxes) {
|
||||
return fmt.Errorf("invalid stash_box_index %d", input.Endpoint)
|
||||
}
|
||||
box := boxes[input.Endpoint]
|
||||
|
||||
var tasks []StashBoxBatchTagTask
|
||||
|
||||
// The gocritic linter wants to turn this ifElseChain into a switch.
|
||||
|
||||
@@ -251,12 +251,14 @@ func (c Client) findStashBoxScenesByFingerprints(ctx context.Context, scenes [][
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (c Client) SubmitStashBoxFingerprints(ctx context.Context, sceneIDs []string, endpoint string) (bool, error) {
|
||||
func (c Client) SubmitStashBoxFingerprints(ctx context.Context, sceneIDs []string) (bool, error) {
|
||||
ids, err := stringslice.StringSliceToIntSlice(sceneIDs)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
endpoint := c.box.Endpoint
|
||||
|
||||
var fingerprints []graphql.FingerprintSubmission
|
||||
|
||||
r := c.repository
|
||||
@@ -945,12 +947,13 @@ func appendFingerprintUnique(v []*graphql.FingerprintInput, toAdd *graphql.Finge
|
||||
return append(v, toAdd)
|
||||
}
|
||||
|
||||
func (c Client) SubmitSceneDraft(ctx context.Context, scene *models.Scene, endpoint string, cover []byte) (*string, error) {
|
||||
func (c Client) SubmitSceneDraft(ctx context.Context, scene *models.Scene, cover []byte) (*string, error) {
|
||||
draft := graphql.SceneDraftInput{}
|
||||
var image io.Reader
|
||||
r := c.repository
|
||||
pqb := r.Performer
|
||||
sqb := r.Studio
|
||||
endpoint := c.box.Endpoint
|
||||
|
||||
if scene.Title != "" {
|
||||
draft.Title = &scene.Title
|
||||
@@ -1115,10 +1118,11 @@ func (c Client) SubmitSceneDraft(ctx context.Context, scene *models.Scene, endpo
|
||||
// return id, nil
|
||||
}
|
||||
|
||||
func (c Client) SubmitPerformerDraft(ctx context.Context, performer *models.Performer, endpoint string) (*string, error) {
|
||||
func (c Client) SubmitPerformerDraft(ctx context.Context, performer *models.Performer) (*string, error) {
|
||||
draft := graphql.PerformerDraftInput{}
|
||||
var image io.Reader
|
||||
pqb := c.repository.Performer
|
||||
endpoint := c.box.Endpoint
|
||||
|
||||
if err := performer.LoadAliases(ctx, pqb); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -52,17 +52,18 @@ export const SubmitStashBoxDraft: React.FC<IProps> = ({
|
||||
}, [show, type, boxes, entity]);
|
||||
|
||||
async function doSubmit() {
|
||||
if (type === "scene") {
|
||||
const r = await mutateSubmitStashBoxSceneDraft({
|
||||
if (!selectedBox) return;
|
||||
|
||||
const input = {
|
||||
id: entity.id,
|
||||
stash_box_index: selectedBoxIndex,
|
||||
});
|
||||
stash_box_endpoint: selectedBox.endpoint,
|
||||
};
|
||||
|
||||
if (type === "scene") {
|
||||
const r = await mutateSubmitStashBoxSceneDraft(input);
|
||||
return r.data?.submitStashBoxSceneDraft;
|
||||
} else if (type === "performer") {
|
||||
const r = await mutateSubmitStashBoxPerformerDraft({
|
||||
id: entity.id,
|
||||
stash_box_index: selectedBoxIndex,
|
||||
});
|
||||
const r = await mutateSubmitStashBoxPerformerDraft(input);
|
||||
return r.data?.submitStashBoxPerformerDraft;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ const PerformerStashBoxModal: React.FC<IProps> = ({
|
||||
const { data, loading } = GQL.useScrapeSinglePerformerQuery({
|
||||
variables: {
|
||||
source: {
|
||||
stash_box_index: instance.index,
|
||||
stash_box_endpoint: instance.endpoint,
|
||||
},
|
||||
input: {
|
||||
query,
|
||||
|
||||
@@ -419,7 +419,6 @@ export const SceneEditPanel: React.FC<IProps> = ({
|
||||
key={s.endpoint}
|
||||
onClick={() =>
|
||||
onScrapeQueryClicked({
|
||||
stash_box_index: index,
|
||||
stash_box_endpoint: s.endpoint,
|
||||
})
|
||||
}
|
||||
@@ -451,7 +450,7 @@ export const SceneEditPanel: React.FC<IProps> = ({
|
||||
function onSceneSelected(s: GQL.ScrapedSceneDataFragment) {
|
||||
if (!scraper) return;
|
||||
|
||||
if (scraper?.stash_box_index !== undefined) {
|
||||
if (scraper?.stash_box_endpoint !== undefined) {
|
||||
// must be stash-box - assume full scene
|
||||
setScrapedScene(s);
|
||||
} else {
|
||||
@@ -491,7 +490,6 @@ export const SceneEditPanel: React.FC<IProps> = ({
|
||||
key={s.endpoint}
|
||||
onClick={() =>
|
||||
onScrapeClicked({
|
||||
stash_box_index: index,
|
||||
stash_box_endpoint: s.endpoint,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ export const SCRAPER_PREFIX = "scraper:";
|
||||
|
||||
export interface ITaggerSource {
|
||||
id: string;
|
||||
stashboxEndpoint?: string;
|
||||
sourceInput: ScraperSourceInput;
|
||||
displayName: string;
|
||||
supportSceneQuery?: boolean;
|
||||
|
||||
@@ -146,10 +146,9 @@ export const TaggerContext: React.FC = ({ children }) => {
|
||||
const scrapers = Scrapers.data.listScrapers;
|
||||
|
||||
const stashboxSources: ITaggerSource[] = stashBoxes.map((s, i) => ({
|
||||
id: `${STASH_BOX_PREFIX}${i}`,
|
||||
stashboxEndpoint: s.endpoint,
|
||||
id: `${STASH_BOX_PREFIX}${s.endpoint}`,
|
||||
sourceInput: {
|
||||
stash_box_index: i,
|
||||
stash_box_endpoint: s.endpoint,
|
||||
},
|
||||
displayName: `stash-box: ${s.name || `#${i + 1}`}`,
|
||||
supportSceneFragment: true,
|
||||
@@ -192,14 +191,14 @@ export const TaggerContext: React.FC = ({ children }) => {
|
||||
}, [currentSource]);
|
||||
|
||||
function getPendingFingerprints() {
|
||||
const endpoint = currentSource?.stashboxEndpoint;
|
||||
const endpoint = currentSource?.sourceInput.stash_box_endpoint;
|
||||
if (!config || !endpoint) return [];
|
||||
|
||||
return config.fingerprintQueue[endpoint] ?? [];
|
||||
}
|
||||
|
||||
function clearSubmissionQueue() {
|
||||
const endpoint = currentSource?.stashboxEndpoint;
|
||||
const endpoint = currentSource?.sourceInput.stash_box_endpoint;
|
||||
if (!config || !endpoint) return;
|
||||
|
||||
setConfig({
|
||||
@@ -215,18 +214,16 @@ export const TaggerContext: React.FC = ({ children }) => {
|
||||
GQL.useSubmitStashBoxFingerprintsMutation();
|
||||
|
||||
async function submitFingerprints() {
|
||||
const endpoint = currentSource?.stashboxEndpoint;
|
||||
const stashBoxIndex =
|
||||
currentSource?.sourceInput.stash_box_index ?? undefined;
|
||||
const endpoint = currentSource?.sourceInput.stash_box_endpoint;
|
||||
|
||||
if (!config || !endpoint || stashBoxIndex === undefined) return;
|
||||
if (!config || !endpoint) return;
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
await submitFingerprintsMutation({
|
||||
variables: {
|
||||
input: {
|
||||
stash_box_index: stashBoxIndex,
|
||||
stash_box_endpoint: endpoint,
|
||||
scene_ids: config.fingerprintQueue[endpoint],
|
||||
},
|
||||
},
|
||||
@@ -241,7 +238,7 @@ export const TaggerContext: React.FC = ({ children }) => {
|
||||
}
|
||||
|
||||
function queueFingerprintSubmission(sceneId: string) {
|
||||
const endpoint = currentSource?.stashboxEndpoint;
|
||||
const endpoint = currentSource?.sourceInput.stash_box_endpoint;
|
||||
if (!config || !endpoint) return;
|
||||
|
||||
setConfig({
|
||||
@@ -276,7 +273,8 @@ export const TaggerContext: React.FC = ({ children }) => {
|
||||
);
|
||||
let newResult: ISceneQueryResult;
|
||||
// scenes are already resolved if they come from stash-box
|
||||
const resolved = currentSource.sourceInput.stash_box_index !== undefined;
|
||||
const resolved =
|
||||
currentSource.sourceInput.stash_box_endpoint !== undefined;
|
||||
|
||||
if (results.error) {
|
||||
newResult = { error: results.error.message };
|
||||
@@ -365,13 +363,16 @@ export const TaggerContext: React.FC = ({ children }) => {
|
||||
setLoading(true);
|
||||
setMultiError(undefined);
|
||||
|
||||
const stashBoxIndex =
|
||||
currentSource.sourceInput.stash_box_index ?? undefined;
|
||||
const stashBoxEndpoint =
|
||||
currentSource.sourceInput.stash_box_endpoint ?? undefined;
|
||||
|
||||
// if current source is stash-box, we can use the multi-scene
|
||||
// interface
|
||||
if (stashBoxIndex !== undefined) {
|
||||
const results = await stashBoxSceneBatchQuery(sceneIDs, stashBoxIndex);
|
||||
if (stashBoxEndpoint !== undefined) {
|
||||
const results = await stashBoxSceneBatchQuery(
|
||||
sceneIDs,
|
||||
stashBoxEndpoint
|
||||
);
|
||||
|
||||
if (results.error) {
|
||||
setMultiError(results.error.message);
|
||||
@@ -604,7 +605,11 @@ export const TaggerContext: React.FC = ({ children }) => {
|
||||
performer: GQL.ScrapedPerformer,
|
||||
performerID: string
|
||||
) {
|
||||
if (!performer.remote_site_id || !currentSource?.stashboxEndpoint) return;
|
||||
if (
|
||||
!performer.remote_site_id ||
|
||||
!currentSource?.sourceInput.stash_box_endpoint
|
||||
)
|
||||
return;
|
||||
|
||||
try {
|
||||
const queryResult = await queryFindPerformer(performerID);
|
||||
@@ -620,7 +625,7 @@ export const TaggerContext: React.FC = ({ children }) => {
|
||||
|
||||
stashIDs.push({
|
||||
stash_id: performer.remote_site_id,
|
||||
endpoint: currentSource?.stashboxEndpoint,
|
||||
endpoint: currentSource?.sourceInput.stash_box_endpoint,
|
||||
});
|
||||
|
||||
await updatePerformer({
|
||||
@@ -722,7 +727,7 @@ export const TaggerContext: React.FC = ({ children }) => {
|
||||
const studioID = result.data?.studioUpdate?.id;
|
||||
|
||||
const stashID = input.stash_ids?.find((e) => {
|
||||
return e.endpoint === currentSource?.stashboxEndpoint;
|
||||
return e.endpoint === currentSource?.sourceInput.stash_box_endpoint;
|
||||
})?.stash_id;
|
||||
|
||||
if (stashID) {
|
||||
@@ -757,7 +762,11 @@ export const TaggerContext: React.FC = ({ children }) => {
|
||||
}
|
||||
|
||||
async function linkStudio(studio: GQL.ScrapedStudio, studioID: string) {
|
||||
if (!studio.remote_site_id || !currentSource?.stashboxEndpoint) return;
|
||||
if (
|
||||
!studio.remote_site_id ||
|
||||
!currentSource?.sourceInput.stash_box_endpoint
|
||||
)
|
||||
return;
|
||||
|
||||
try {
|
||||
const queryResult = await queryFindStudio(studioID);
|
||||
@@ -773,7 +782,7 @@ export const TaggerContext: React.FC = ({ children }) => {
|
||||
|
||||
stashIDs.push({
|
||||
stash_id: studio.remote_site_id,
|
||||
endpoint: currentSource?.stashboxEndpoint,
|
||||
endpoint: currentSource?.sourceInput.stash_box_endpoint,
|
||||
});
|
||||
|
||||
await updateStudio({
|
||||
|
||||
@@ -238,7 +238,6 @@ interface IPerformerTaggerListProps {
|
||||
selectedEndpoint: { endpoint: string; index: number };
|
||||
isIdle: boolean;
|
||||
config: ITaggerConfig;
|
||||
stashBoxes?: GQL.StashBox[];
|
||||
onBatchAdd: (performerInput: string) => void;
|
||||
onBatchUpdate: (ids: string[] | undefined, refresh: boolean) => void;
|
||||
}
|
||||
@@ -248,7 +247,6 @@ const PerformerTaggerList: React.FC<IPerformerTaggerListProps> = ({
|
||||
selectedEndpoint,
|
||||
isIdle,
|
||||
config,
|
||||
stashBoxes,
|
||||
onBatchAdd,
|
||||
onBatchUpdate,
|
||||
}) => {
|
||||
@@ -277,7 +275,7 @@ const PerformerTaggerList: React.FC<IPerformerTaggerListProps> = ({
|
||||
>();
|
||||
|
||||
const doBoxSearch = (performerID: string, searchVal: string) => {
|
||||
stashBoxPerformerQuery(searchVal, selectedEndpoint.index)
|
||||
stashBoxPerformerQuery(searchVal, selectedEndpoint.endpoint)
|
||||
.then((queryData) => {
|
||||
const s = queryData.data?.scrapeSinglePerformer ?? [];
|
||||
setSearchResults({
|
||||
@@ -309,14 +307,14 @@ const PerformerTaggerList: React.FC<IPerformerTaggerListProps> = ({
|
||||
const doBoxUpdate = (
|
||||
performerID: string,
|
||||
stashID: string,
|
||||
endpointIndex: number
|
||||
endpoint: string
|
||||
) => {
|
||||
setLoadingUpdate(stashID);
|
||||
setError({
|
||||
...error,
|
||||
[performerID]: undefined,
|
||||
});
|
||||
stashBoxPerformerQuery(stashID, endpointIndex)
|
||||
stashBoxPerformerQuery(stashID, endpoint)
|
||||
.then((queryData) => {
|
||||
const data = queryData.data?.scrapeSinglePerformer ?? [];
|
||||
if (data.length > 0) {
|
||||
@@ -477,19 +475,18 @@ const PerformerTaggerList: React.FC<IPerformerTaggerListProps> = ({
|
||||
<div className="small">{stashID.stash_id}</div>
|
||||
);
|
||||
|
||||
const endpointIndex =
|
||||
stashBoxes?.findIndex((box) => box.endpoint === stashID.endpoint) ??
|
||||
-1;
|
||||
|
||||
subContent = (
|
||||
<div key={performer.id}>
|
||||
<InputGroup className="PerformerTagger-box-link">
|
||||
<InputGroup.Text>{link}</InputGroup.Text>
|
||||
<InputGroup.Append>
|
||||
{endpointIndex !== -1 && (
|
||||
<Button
|
||||
onClick={() =>
|
||||
doBoxUpdate(performer.id, stashID.stash_id, endpointIndex)
|
||||
doBoxUpdate(
|
||||
performer.id,
|
||||
stashID.stash_id,
|
||||
stashID.endpoint
|
||||
)
|
||||
}
|
||||
disabled={!!loadingUpdate}
|
||||
>
|
||||
@@ -499,7 +496,6 @@ const PerformerTaggerList: React.FC<IPerformerTaggerListProps> = ({
|
||||
<FormattedMessage id="actions.refresh" />
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
</InputGroup.Append>
|
||||
</InputGroup>
|
||||
{error[performer.id] && (
|
||||
@@ -787,7 +783,6 @@ export const PerformerTagger: React.FC<ITaggerProps> = ({ performers }) => {
|
||||
}}
|
||||
isIdle={batchJobID === undefined}
|
||||
config={config}
|
||||
stashBoxes={stashConfig?.general.stashBoxes}
|
||||
onBatchAdd={batchAdd}
|
||||
onBatchUpdate={batchUpdate}
|
||||
/>
|
||||
|
||||
@@ -327,8 +327,8 @@ const StashSearchResult: React.FC<IStashSearchResultProps> = ({
|
||||
}
|
||||
}, [isActive, loading, stashScene, index, resolveScene, scene]);
|
||||
|
||||
const stashBoxBaseURL = currentSource?.stashboxEndpoint
|
||||
? getStashboxBase(currentSource.stashboxEndpoint)
|
||||
const stashBoxBaseURL = currentSource?.sourceInput.stash_box_endpoint
|
||||
? getStashboxBase(currentSource.sourceInput.stash_box_endpoint)
|
||||
: undefined;
|
||||
const stashBoxURL = useMemo(() => {
|
||||
if (stashBoxBaseURL) {
|
||||
@@ -404,7 +404,7 @@ const StashSearchResult: React.FC<IStashSearchResultProps> = ({
|
||||
const includeStashID = !excludedFieldList.includes("stash_ids");
|
||||
if (
|
||||
includeStashID &&
|
||||
currentSource?.stashboxEndpoint &&
|
||||
currentSource?.sourceInput.stash_box_endpoint &&
|
||||
scene.remote_site_id
|
||||
) {
|
||||
sceneCreateInput.stash_ids = [
|
||||
@@ -415,9 +415,11 @@ const StashSearchResult: React.FC<IStashSearchResultProps> = ({
|
||||
stash_id: s.stash_id,
|
||||
};
|
||||
})
|
||||
.filter((s) => s.endpoint !== currentSource.stashboxEndpoint) ?? []),
|
||||
.filter(
|
||||
(s) => s.endpoint !== currentSource.sourceInput.stash_box_endpoint
|
||||
) ?? []),
|
||||
{
|
||||
endpoint: currentSource.stashboxEndpoint,
|
||||
endpoint: currentSource.sourceInput.stash_box_endpoint,
|
||||
stash_id: scene.remote_site_id,
|
||||
},
|
||||
];
|
||||
@@ -662,7 +664,9 @@ const StashSearchResult: React.FC<IStashSearchResultProps> = ({
|
||||
selectedID={studioID}
|
||||
setSelectedID={(id) => setStudioID(id)}
|
||||
onCreate={() => showStudioModal(scene.studio!)}
|
||||
endpoint={currentSource?.stashboxEndpoint}
|
||||
endpoint={
|
||||
currentSource?.sourceInput.stash_box_endpoint ?? undefined
|
||||
}
|
||||
onLink={async () => {
|
||||
await linkStudio(scene.studio!, studioID!);
|
||||
}}
|
||||
@@ -691,7 +695,9 @@ const StashSearchResult: React.FC<IStashSearchResultProps> = ({
|
||||
onLink={async () => {
|
||||
await linkPerformer(performer, performerIDs[performerIndex]!);
|
||||
}}
|
||||
endpoint={currentSource?.stashboxEndpoint}
|
||||
endpoint={
|
||||
currentSource?.sourceInput.stash_box_endpoint ?? undefined
|
||||
}
|
||||
key={`${performer.name ?? performer.remote_site_id ?? ""}`}
|
||||
/>
|
||||
))}
|
||||
|
||||
@@ -106,7 +106,7 @@ export const SceneTaggerModals: React.FC = ({ children }) => {
|
||||
setStudioCallback(() => callback);
|
||||
}
|
||||
|
||||
const endpoint = currentSource?.stashboxEndpoint;
|
||||
const endpoint = currentSource?.sourceInput.stash_box_endpoint ?? undefined;
|
||||
|
||||
return (
|
||||
<SceneTaggerModalsState.Provider
|
||||
|
||||
@@ -268,7 +268,6 @@ interface IStudioTaggerListProps {
|
||||
selectedEndpoint: { endpoint: string; index: number };
|
||||
isIdle: boolean;
|
||||
config: ITaggerConfig;
|
||||
stashBoxes?: GQL.StashBox[];
|
||||
onBatchAdd: (studioInput: string, createParent: boolean) => void;
|
||||
onBatchUpdate: (
|
||||
ids: string[] | undefined,
|
||||
@@ -282,7 +281,6 @@ const StudioTaggerList: React.FC<IStudioTaggerListProps> = ({
|
||||
selectedEndpoint,
|
||||
isIdle,
|
||||
config,
|
||||
stashBoxes,
|
||||
onBatchAdd,
|
||||
onBatchUpdate,
|
||||
}) => {
|
||||
@@ -315,7 +313,7 @@ const StudioTaggerList: React.FC<IStudioTaggerListProps> = ({
|
||||
>();
|
||||
|
||||
const doBoxSearch = (studioID: string, searchVal: string) => {
|
||||
stashBoxStudioQuery(searchVal, selectedEndpoint.index)
|
||||
stashBoxStudioQuery(searchVal, selectedEndpoint.endpoint)
|
||||
.then((queryData) => {
|
||||
const s = queryData.data?.scrapeSingleStudio ?? [];
|
||||
setSearchResults({
|
||||
@@ -344,17 +342,13 @@ const StudioTaggerList: React.FC<IStudioTaggerListProps> = ({
|
||||
setLoading(true);
|
||||
};
|
||||
|
||||
const doBoxUpdate = (
|
||||
studioID: string,
|
||||
stashID: string,
|
||||
endpointIndex: number
|
||||
) => {
|
||||
const doBoxUpdate = (studioID: string, stashID: string, endpoint: string) => {
|
||||
setLoadingUpdate(stashID);
|
||||
setError({
|
||||
...error,
|
||||
[studioID]: undefined,
|
||||
});
|
||||
stashBoxStudioQuery(stashID, endpointIndex)
|
||||
stashBoxStudioQuery(stashID, endpoint)
|
||||
.then((queryData) => {
|
||||
const data = queryData.data?.scrapeSingleStudio ?? [];
|
||||
if (data.length > 0) {
|
||||
@@ -535,19 +529,14 @@ const StudioTaggerList: React.FC<IStudioTaggerListProps> = ({
|
||||
<div className="small">{stashID.stash_id}</div>
|
||||
);
|
||||
|
||||
const endpointIndex =
|
||||
stashBoxes?.findIndex((box) => box.endpoint === stashID.endpoint) ??
|
||||
-1;
|
||||
|
||||
subContent = (
|
||||
<div key={studio.id}>
|
||||
<InputGroup className="StudioTagger-box-link">
|
||||
<InputGroup.Text>{link}</InputGroup.Text>
|
||||
<InputGroup.Append>
|
||||
{endpointIndex !== -1 && (
|
||||
<Button
|
||||
onClick={() =>
|
||||
doBoxUpdate(studio.id, stashID.stash_id, endpointIndex)
|
||||
doBoxUpdate(studio.id, stashID.stash_id, stashID.endpoint)
|
||||
}
|
||||
disabled={!!loadingUpdate}
|
||||
>
|
||||
@@ -557,7 +546,6 @@ const StudioTaggerList: React.FC<IStudioTaggerListProps> = ({
|
||||
<FormattedMessage id="actions.refresh" />
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
</InputGroup.Append>
|
||||
</InputGroup>
|
||||
{error[studio.id] && (
|
||||
@@ -849,7 +837,6 @@ export const StudioTagger: React.FC<ITaggerProps> = ({ studios }) => {
|
||||
}}
|
||||
isIdle={batchJobID === undefined}
|
||||
config={config}
|
||||
stashBoxes={stashConfig?.general.stashBoxes}
|
||||
onBatchAdd={batchAdd}
|
||||
onBatchUpdate={batchUpdate}
|
||||
/>
|
||||
|
||||
@@ -2054,19 +2054,21 @@ export const queryScrapeSceneQueryFragment = (
|
||||
|
||||
export const stashBoxSceneBatchQuery = (
|
||||
sceneIds: string[],
|
||||
stashBoxIndex: number
|
||||
stashBoxEndpoint: string
|
||||
) =>
|
||||
client.query<GQL.ScrapeMultiScenesQuery>({
|
||||
client.query<GQL.ScrapeMultiScenesQuery, GQL.ScrapeMultiScenesQueryVariables>(
|
||||
{
|
||||
query: GQL.ScrapeMultiScenesDocument,
|
||||
variables: {
|
||||
source: {
|
||||
stash_box_index: stashBoxIndex,
|
||||
stash_box_endpoint: stashBoxEndpoint,
|
||||
},
|
||||
input: {
|
||||
scene_ids: sceneIds,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
export const useListPerformerScrapers = () =>
|
||||
GQL.useListPerformerScrapersQuery();
|
||||
@@ -2110,13 +2112,16 @@ export const queryScrapePerformerURL = (url: string) =>
|
||||
|
||||
export const stashBoxPerformerQuery = (
|
||||
searchVal: string,
|
||||
stashBoxIndex: number
|
||||
stashBoxEndpoint: string
|
||||
) =>
|
||||
client.query<GQL.ScrapeSinglePerformerQuery>({
|
||||
client.query<
|
||||
GQL.ScrapeSinglePerformerQuery,
|
||||
GQL.ScrapeSinglePerformerQueryVariables
|
||||
>({
|
||||
query: GQL.ScrapeSinglePerformerDocument,
|
||||
variables: {
|
||||
source: {
|
||||
stash_box_index: stashBoxIndex,
|
||||
stash_box_endpoint: stashBoxEndpoint,
|
||||
},
|
||||
input: {
|
||||
query: searchVal,
|
||||
@@ -2127,13 +2132,16 @@ export const stashBoxPerformerQuery = (
|
||||
|
||||
export const stashBoxStudioQuery = (
|
||||
query: string | null,
|
||||
stashBoxIndex: number
|
||||
stashBoxEndpoint: string
|
||||
) =>
|
||||
client.query<GQL.ScrapeSingleStudioQuery>({
|
||||
client.query<
|
||||
GQL.ScrapeSingleStudioQuery,
|
||||
GQL.ScrapeSingleStudioQueryVariables
|
||||
>({
|
||||
query: GQL.ScrapeSingleStudioDocument,
|
||||
variables: {
|
||||
source: {
|
||||
stash_box_index: stashBoxIndex,
|
||||
stash_box_endpoint: stashBoxEndpoint,
|
||||
},
|
||||
input: {
|
||||
query: query,
|
||||
|
||||
Reference in New Issue
Block a user