mirror of
https://github.com/stashapp/stash.git
synced 2025-12-16 20:07:05 +03:00
Feature: Manual StashId Search - Tags (#6374)
This commit is contained in:
@@ -18,6 +18,7 @@ type StashBoxGraphQLClient interface {
|
||||
FindSceneByID(ctx context.Context, id string, interceptors ...clientv2.RequestInterceptor) (*FindSceneByID, error)
|
||||
FindStudio(ctx context.Context, id *string, name *string, interceptors ...clientv2.RequestInterceptor) (*FindStudio, error)
|
||||
FindTag(ctx context.Context, id *string, name *string, interceptors ...clientv2.RequestInterceptor) (*FindTag, error)
|
||||
QueryTags(ctx context.Context, input TagQueryInput, interceptors ...clientv2.RequestInterceptor) (*QueryTags, error)
|
||||
SubmitFingerprint(ctx context.Context, input FingerprintSubmission, interceptors ...clientv2.RequestInterceptor) (*SubmitFingerprint, error)
|
||||
Me(ctx context.Context, interceptors ...clientv2.RequestInterceptor) (*Me, error)
|
||||
SubmitSceneDraft(ctx context.Context, input SceneDraftInput, interceptors ...clientv2.RequestInterceptor) (*SubmitSceneDraft, error)
|
||||
@@ -643,6 +644,24 @@ func (t *FindStudio_FindStudio_StudioFragment_Parent) GetName() string {
|
||||
return t.Name
|
||||
}
|
||||
|
||||
type QueryTags_QueryTags struct {
|
||||
Count int "json:\"count\" graphql:\"count\""
|
||||
Tags []*TagFragment "json:\"tags\" graphql:\"tags\""
|
||||
}
|
||||
|
||||
func (t *QueryTags_QueryTags) GetCount() int {
|
||||
if t == nil {
|
||||
t = &QueryTags_QueryTags{}
|
||||
}
|
||||
return t.Count
|
||||
}
|
||||
func (t *QueryTags_QueryTags) GetTags() []*TagFragment {
|
||||
if t == nil {
|
||||
t = &QueryTags_QueryTags{}
|
||||
}
|
||||
return t.Tags
|
||||
}
|
||||
|
||||
type Me_Me struct {
|
||||
Name string "json:\"name\" graphql:\"name\""
|
||||
}
|
||||
@@ -775,6 +794,17 @@ func (t *FindTag) GetFindTag() *TagFragment {
|
||||
return t.FindTag
|
||||
}
|
||||
|
||||
type QueryTags struct {
|
||||
QueryTags QueryTags_QueryTags "json:\"queryTags\" graphql:\"queryTags\""
|
||||
}
|
||||
|
||||
func (t *QueryTags) GetQueryTags() *QueryTags_QueryTags {
|
||||
if t == nil {
|
||||
t = &QueryTags{}
|
||||
}
|
||||
return &t.QueryTags
|
||||
}
|
||||
|
||||
type SubmitFingerprint struct {
|
||||
SubmitFingerprint bool "json:\"submitFingerprint\" graphql:\"submitFingerprint\""
|
||||
}
|
||||
@@ -1736,6 +1766,37 @@ func (c *Client) FindTag(ctx context.Context, id *string, name *string, intercep
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
const QueryTagsDocument = `query QueryTags ($input: TagQueryInput!) {
|
||||
queryTags(input: $input) {
|
||||
count
|
||||
tags {
|
||||
... TagFragment
|
||||
}
|
||||
}
|
||||
}
|
||||
fragment TagFragment on Tag {
|
||||
name
|
||||
id
|
||||
}
|
||||
`
|
||||
|
||||
func (c *Client) QueryTags(ctx context.Context, input TagQueryInput, interceptors ...clientv2.RequestInterceptor) (*QueryTags, error) {
|
||||
vars := map[string]any{
|
||||
"input": input,
|
||||
}
|
||||
|
||||
var res QueryTags
|
||||
if err := c.Client.Post(ctx, "QueryTags", QueryTagsDocument, &res, vars, interceptors...); err != nil {
|
||||
if c.Client.ParseDataWhenErrors {
|
||||
return &res, err
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
const SubmitFingerprintDocument = `mutation SubmitFingerprint ($input: FingerprintSubmission!) {
|
||||
submitFingerprint(input: $input)
|
||||
}
|
||||
@@ -1838,6 +1899,7 @@ var DocumentOperationNames = map[string]string{
|
||||
FindSceneByIDDocument: "FindSceneByID",
|
||||
FindStudioDocument: "FindStudio",
|
||||
FindTagDocument: "FindTag",
|
||||
QueryTagsDocument: "QueryTags",
|
||||
SubmitFingerprintDocument: "SubmitFingerprint",
|
||||
MeDocument: "Me",
|
||||
SubmitSceneDraftDocument: "SubmitSceneDraft",
|
||||
|
||||
67
pkg/stashbox/tag.go
Normal file
67
pkg/stashbox/tag.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package stashbox
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/stashbox/graphql"
|
||||
)
|
||||
|
||||
// QueryTag searches for tags by name or ID.
|
||||
// If query is a valid UUID, it searches by ID (returns single result).
|
||||
// Otherwise, it searches by name (returns multiple results).
|
||||
func (c Client) QueryTag(ctx context.Context, query string) ([]*models.ScrapedTag, error) {
|
||||
_, err := uuid.Parse(query)
|
||||
if err == nil {
|
||||
// Query is a UUID, use findTag for exact match
|
||||
return c.findTagByID(ctx, query)
|
||||
}
|
||||
// Otherwise search by name
|
||||
return c.queryTagsByName(ctx, query)
|
||||
}
|
||||
|
||||
func (c Client) findTagByID(ctx context.Context, id string) ([]*models.ScrapedTag, error) {
|
||||
tag, err := c.client.FindTag(ctx, &id, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if tag.FindTag == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return []*models.ScrapedTag{{
|
||||
Name: tag.FindTag.Name,
|
||||
RemoteSiteID: &tag.FindTag.ID,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
func (c Client) queryTagsByName(ctx context.Context, name string) ([]*models.ScrapedTag, error) {
|
||||
input := graphql.TagQueryInput{
|
||||
Name: &name,
|
||||
Page: 1,
|
||||
PerPage: 25,
|
||||
Direction: graphql.SortDirectionEnumAsc,
|
||||
Sort: graphql.TagSortEnumName,
|
||||
}
|
||||
|
||||
result, err := c.client.QueryTags(ctx, input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if result.QueryTags.Tags == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var ret []*models.ScrapedTag
|
||||
for _, t := range result.QueryTags.Tags {
|
||||
ret = append(ret, &models.ScrapedTag{
|
||||
Name: t.Name,
|
||||
RemoteSiteID: &t.ID,
|
||||
})
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
Reference in New Issue
Block a user