Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scene Drafts can now get multiple links #824

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions frontend/src/graphql/queries/Draft.gql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#import "../fragments/PerformerFragment.gql"
#import "../fragments/TagFragment.gql"
#import "../fragments/StudioFragment.gql"
#import "../fragments/URLFragment.gql"
query Draft($id: ID!) {
findDraft(id: $id) {
id
Expand Down Expand Up @@ -39,9 +38,7 @@ query Draft($id: ID!) {
details
director
date
url {
...URLFragment
}
urls
studio {
... on Studio {
...StudioFragment
Expand Down
29 changes: 5 additions & 24 deletions frontend/src/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ export type SceneDraft = {
studio?: Maybe<SceneDraftStudio>;
tags?: Maybe<Array<SceneDraftTag>>;
title?: Maybe<Scalars["String"]>;
url?: Maybe<Url>;
urls?: Maybe<Array<Scalars["String"]>>;
};

export type SceneDraftInput = {
Expand All @@ -1371,7 +1371,9 @@ export type SceneDraftInput = {
studio?: InputMaybe<DraftEntityInput>;
tags?: InputMaybe<Array<DraftEntityInput>>;
title?: InputMaybe<Scalars["String"]>;
/** @deprecated Use urls field instead. */
url?: InputMaybe<Scalars["String"]>;
urls?: InputMaybe<Array<Scalars["String"]>>;
};

export type SceneDraftPerformer = DraftEntity | Performer;
Expand Down Expand Up @@ -13953,16 +13955,7 @@ export type DraftQuery = {
details?: string | null;
director?: string | null;
date?: string | null;
url?: {
__typename: "URL";
url: string;
site: {
__typename: "Site";
id: string;
name: string;
icon: string;
};
} | null;
urls?: Array<string> | null;
studio?:
| {
__typename: "DraftEntity";
Expand Down Expand Up @@ -39404,19 +39397,7 @@ export const DraftDocument = {
},
{
kind: "Field",
name: { kind: "Name", value: "url" },
selectionSet: {
kind: "SelectionSet",
selections: [
{
kind: "FragmentSpread",
name: {
kind: "Name",
value: "URLFragment",
},
},
],
},
name: { kind: "Name", value: "urls" },
},
{
kind: "Field",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/pages/drafts/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
>["performers"][number];

type URL = { url: string; site: { id: string } };
const joinURLs = <T extends URL>(

Check warning on line 25 in frontend/src/pages/drafts/parse.ts

View workflow job for this annotation

GitHub Actions / build

'joinURLs' is assigned a value but never used
newURL: T | undefined | null,
existingURLs: T[] | undefined
) =>
Expand Down Expand Up @@ -68,7 +68,7 @@
date: draft.date,
title: draft.title,
details: draft.details,
urls: joinURLs(draft.url, existingScene?.urls),
urls: existingScene?.urls,
studio: draft.studio?.__typename === "Studio" ? draft.studio : null,
director: draft.director,
code: draft.code,
Expand Down Expand Up @@ -105,6 +105,7 @@
[]
)
.join(", "),
Urls: (draft?.urls ?? []).join(", "),
Tags: (draft.tags ?? [])
.reduce<string[]>(
(res, t) => (t.__typename === "DraftEntity" ? [...res, t.name] : res),
Expand Down
5 changes: 3 additions & 2 deletions graphql/schema/types/scene.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ type SceneDraft {
code: String
details: String
director: String
url: URL
urls: [String!]
date: String
studio: SceneDraftStudio
performers: [SceneDraftPerformer!]!
Expand All @@ -243,7 +243,8 @@ input SceneDraftInput {
code: String
details: String
director: String
url: String
url: String @deprecated(reason: "Use urls field instead.")
urls: [String!]
date: String
studio: DraftEntityInput
performers: [DraftEntityInput!]!
Expand Down
50 changes: 0 additions & 50 deletions pkg/api/resolver_model_scene_draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ package api

import (
"context"
"regexp"

"github.com/gofrs/uuid"
"github.com/stashapp/stash-box/pkg/models"
"github.com/stashapp/stash-box/pkg/utils"
)

type sceneDraftResolver struct{ *Resolver }
Expand Down Expand Up @@ -108,50 +105,3 @@ func (r *sceneDraftResolver) Studio(ctx context.Context, obj *models.SceneDraft)
}
return nil, nil
}

func (r *sceneDraftResolver) URL(ctx context.Context, obj *models.SceneDraft) (*models.URL, error) {
if obj.URL == nil {
return nil, nil
}

fac := r.getRepoFactory(ctx)
qb := fac.Site()
sites, _, err := qb.Query()
if err != nil {
return nil, nil
}
var studioSiteID *uuid.UUID
var siteID *uuid.UUID
for _, site := range sites {
// Skip any sites not valid for scenes
if !utils.Includes(site.ValidTypes, models.ValidSiteTypeEnumScene.String()) {
continue
}

if site.Name == "Studio" {
studioSiteID = &site.ID
continue
}

if site.Regex.Valid {
re, err := regexp.Compile(site.Regex.String)
if err == nil && re.MatchString(*obj.URL) {
siteID = &site.ID
break
}
}
}

if siteID == nil && studioSiteID != nil {
siteID = studioSiteID
}

if siteID != nil {
url := models.URL{
URL: *obj.URL,
SiteID: *siteID,
}
return &url, nil
}
return nil, nil
}
7 changes: 6 additions & 1 deletion pkg/api/resolver_mutation_draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (r *mutationResolver) SubmitSceneDraft(ctx context.Context, input models.Sc
Code: input.Code,
Details: input.Details,
Director: input.Director,
URL: input.URL,
URLs: input.Urls,
Date: input.Date,
Studio: translateDraftEntity(input.Studio),
Performers: translateDraftEntitySlice(input.Performers),
Expand Down Expand Up @@ -56,6 +56,11 @@ func (r *mutationResolver) SubmitSceneDraft(ctx context.Context, input models.Sc
data.Tags = tags
}

// Temporary code, while we depreciate the URL parameter.
if input.URL != nil {
data.URLs = []string{*input.URL}
}

if err := newDraft.SetData(data); err != nil {
return err
}
Expand Down
92 changes: 26 additions & 66 deletions pkg/models/generated_exec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/models/generated_models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/models/model_draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type SceneDraft struct {
Code *string `json:"code,omitempty"`
Details *string `json:"details,omitempty"`
Director *string `json:"director,omitempty"`
URL *string `json:"url,omitempty"`
URLs []string `json:"urls,omitempty"`
Date *string `json:"date,omitempty"`
Studio *DraftEntity `json:"studio,omitempty"`
Performers []DraftEntity `json:"performers,omitempty"`
Expand Down
Loading