diff --git a/ui/v2.5/src/components/Galleries/GalleryDetails/GalleryScrapeDialog.tsx b/ui/v2.5/src/components/Galleries/GalleryDetails/GalleryScrapeDialog.tsx index 55eb9607f19..520f5bf4746 100644 --- a/ui/v2.5/src/components/Galleries/GalleryDetails/GalleryScrapeDialog.tsx +++ b/ui/v2.5/src/components/Galleries/GalleryDetails/GalleryScrapeDialog.tsx @@ -18,9 +18,9 @@ import { useStudioCreate, usePerformerCreate, useTagCreate, - makePerformerCreateInput, } from "src/core/StashService"; import { useToast } from "src/hooks/Toast"; +import { scrapedPerformerToCreateInput } from "src/core/performers"; function renderScrapedStudio( result: ScrapeResult, @@ -324,7 +324,7 @@ export const GalleryScrapeDialog: React.FC = ( } async function createNewPerformer(toCreate: GQL.ScrapedPerformer) { - const input = makePerformerCreateInput(toCreate); + const input = scrapedPerformerToCreateInput(toCreate); try { const result = await createPerformer({ diff --git a/ui/v2.5/src/components/Scenes/SceneDetails/SceneScrapeDialog.tsx b/ui/v2.5/src/components/Scenes/SceneDetails/SceneScrapeDialog.tsx index d9b014787b5..a75d7eac3e0 100644 --- a/ui/v2.5/src/components/Scenes/SceneDetails/SceneScrapeDialog.tsx +++ b/ui/v2.5/src/components/Scenes/SceneDetails/SceneScrapeDialog.tsx @@ -22,12 +22,12 @@ import { usePerformerCreate, useMovieCreate, useTagCreate, - makePerformerCreateInput, } from "src/core/StashService"; import { useToast } from "src/hooks/Toast"; -import DurationUtils from "src/utils/duration"; import { useIntl } from "react-intl"; import { uniq } from "lodash-es"; +import { scrapedPerformerToCreateInput } from "src/core/performers"; +import { scrapedMovieToCreateInput } from "src/core/movies"; interface IScrapedStudioRow { title: string; @@ -464,7 +464,7 @@ export const SceneScrapeDialog: React.FC = ({ } async function createNewPerformer(toCreate: GQL.ScrapedPerformer) { - const input = makePerformerCreateInput(toCreate); + const input = scrapedPerformerToCreateInput(toCreate); try { const result = await createPerformer({ @@ -503,23 +503,8 @@ export const SceneScrapeDialog: React.FC = ({ } async function createNewMovie(toCreate: GQL.ScrapedMovie) { - let movieInput: GQL.MovieCreateInput = { name: "" }; + const movieInput = scrapedMovieToCreateInput(toCreate); try { - movieInput = Object.assign(movieInput, toCreate); - - // #788 - convert duration and rating to the correct type - movieInput.duration = DurationUtils.stringToSeconds( - toCreate.duration ?? undefined - ); - if (!movieInput.duration) { - movieInput.duration = undefined; - } - - movieInput.rating = parseInt(toCreate.rating ?? "0", 10); - if (!movieInput.rating || Number.isNaN(movieInput.rating)) { - movieInput.rating = undefined; - } - const result = await createMovie({ variables: { input: movieInput }, }); diff --git a/ui/v2.5/src/core/StashService.ts b/ui/v2.5/src/core/StashService.ts index 77c574e940d..7850c0ae086 100644 --- a/ui/v2.5/src/core/StashService.ts +++ b/ui/v2.5/src/core/StashService.ts @@ -5,9 +5,6 @@ import { getQueryDefinition, StoreObject, } from "@apollo/client/utilities"; -import { stringToGender } from "src/utils/gender"; -import { stringToCircumcised } from "src/utils/circumcised"; -import { filterData } from "../utils/data"; import { ListFilterModel } from "../models/list-filter/filter"; import * as GQL from "./generated-graphql"; @@ -2205,38 +2202,3 @@ export const queryParseSceneFilenames = ( variables: { filter, config }, fetchPolicy: "network-only", }); - -export const makePerformerCreateInput = (toCreate: GQL.ScrapedPerformer) => { - const input: GQL.PerformerCreateInput = { - name: toCreate.name ?? "", - url: toCreate.url, - gender: stringToGender(toCreate.gender), - birthdate: toCreate.birthdate, - ethnicity: toCreate.ethnicity, - country: toCreate.country, - eye_color: toCreate.eye_color, - height_cm: toCreate.height ? Number(toCreate.height) : undefined, - measurements: toCreate.measurements, - fake_tits: toCreate.fake_tits, - career_length: toCreate.career_length, - tattoos: toCreate.tattoos, - piercings: toCreate.piercings, - aliases: toCreate.aliases, - twitter: toCreate.twitter, - instagram: toCreate.instagram, - tag_ids: filterData((toCreate.tags ?? []).map((t) => t.stored_id)), - image: - (toCreate.images ?? []).length > 0 - ? (toCreate.images ?? [])[0] - : undefined, - details: toCreate.details, - death_date: toCreate.death_date, - hair_color: toCreate.hair_color, - weight: toCreate.weight ? Number(toCreate.weight) : undefined, - penis_length: toCreate.penis_length - ? Number(toCreate.penis_length) - : undefined, - circumcised: stringToCircumcised(toCreate.circumcised), - }; - return input; -}; diff --git a/ui/v2.5/src/core/movies.ts b/ui/v2.5/src/core/movies.ts new file mode 100644 index 00000000000..c369b4497bc --- /dev/null +++ b/ui/v2.5/src/core/movies.ts @@ -0,0 +1,30 @@ +import * as GQL from "src/core/generated-graphql"; +import DurationUtils from "src/utils/duration"; + +export const scrapedMovieToCreateInput = (toCreate: GQL.ScrapedMovie) => { + const input: GQL.MovieCreateInput = { + name: toCreate.name ?? "", + url: toCreate.url, + aliases: toCreate.aliases, + front_image: toCreate.front_image, + back_image: toCreate.back_image, + synopsis: toCreate.synopsis, + date: toCreate.date, + // #788 - convert duration and rating to the correct type + duration: toCreate.duration + ? DurationUtils.stringToSeconds(toCreate.duration) + : undefined, + studio_id: toCreate.studio?.stored_id, + rating: parseInt(toCreate.rating ?? "0", 10), + }; + + if (!input.duration) { + input.duration = undefined; + } + + if (!input.rating || Number.isNaN(input.rating)) { + input.rating = undefined; + } + + return input; +}; diff --git a/ui/v2.5/src/core/performers.ts b/ui/v2.5/src/core/performers.ts index 597a0be5492..c69d93c5661 100644 --- a/ui/v2.5/src/core/performers.ts +++ b/ui/v2.5/src/core/performers.ts @@ -1,6 +1,9 @@ import { PerformersCriterion } from "src/models/list-filter/criteria/performers"; import * as GQL from "src/core/generated-graphql"; import { ListFilterModel } from "src/models/list-filter/filter"; +import { stringToGender } from "src/utils/gender"; +import { filterData } from "src/utils/data"; +import { stringToCircumcised } from "src/utils/circumcised"; export const usePerformerFilterHook = ( performer: GQL.PerformerDataFragment @@ -79,3 +82,40 @@ export function sortPerformers(performers: T[]) { return ret; } + +export const scrapedPerformerToCreateInput = ( + toCreate: GQL.ScrapedPerformer +) => { + const input: GQL.PerformerCreateInput = { + name: toCreate.name ?? "", + url: toCreate.url, + gender: stringToGender(toCreate.gender), + birthdate: toCreate.birthdate, + ethnicity: toCreate.ethnicity, + country: toCreate.country, + eye_color: toCreate.eye_color, + height_cm: toCreate.height ? Number(toCreate.height) : undefined, + measurements: toCreate.measurements, + fake_tits: toCreate.fake_tits, + career_length: toCreate.career_length, + tattoos: toCreate.tattoos, + piercings: toCreate.piercings, + aliases: toCreate.aliases, + twitter: toCreate.twitter, + instagram: toCreate.instagram, + tag_ids: filterData((toCreate.tags ?? []).map((t) => t.stored_id)), + image: + (toCreate.images ?? []).length > 0 + ? (toCreate.images ?? [])[0] + : undefined, + details: toCreate.details, + death_date: toCreate.death_date, + hair_color: toCreate.hair_color, + weight: toCreate.weight ? Number(toCreate.weight) : undefined, + penis_length: toCreate.penis_length + ? Number(toCreate.penis_length) + : undefined, + circumcised: stringToCircumcised(toCreate.circumcised), + }; + return input; +};