Skip to content

Commit

Permalink
Fix scraped movie to create input translation (#3969)
Browse files Browse the repository at this point in the history
  • Loading branch information
WithoutPants authored Jul 31, 2023
1 parent a354f9b commit 170f45c
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>,
Expand Down Expand Up @@ -324,7 +324,7 @@ export const GalleryScrapeDialog: React.FC<IGalleryScrapeDialogProps> = (
}

async function createNewPerformer(toCreate: GQL.ScrapedPerformer) {
const input = makePerformerCreateInput(toCreate);
const input = scrapedPerformerToCreateInput(toCreate);

try {
const result = await createPerformer({
Expand Down
23 changes: 4 additions & 19 deletions ui/v2.5/src/components/Scenes/SceneDetails/SceneScrapeDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -464,7 +464,7 @@ export const SceneScrapeDialog: React.FC<ISceneScrapeDialogProps> = ({
}

async function createNewPerformer(toCreate: GQL.ScrapedPerformer) {
const input = makePerformerCreateInput(toCreate);
const input = scrapedPerformerToCreateInput(toCreate);

try {
const result = await createPerformer({
Expand Down Expand Up @@ -503,23 +503,8 @@ export const SceneScrapeDialog: React.FC<ISceneScrapeDialogProps> = ({
}

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 },
});
Expand Down
38 changes: 0 additions & 38 deletions ui/v2.5/src/core/StashService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;
};
30 changes: 30 additions & 0 deletions ui/v2.5/src/core/movies.ts
Original file line number Diff line number Diff line change
@@ -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;
};
40 changes: 40 additions & 0 deletions ui/v2.5/src/core/performers.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -79,3 +82,40 @@ export function sortPerformers<T extends IPerformerFragment>(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;
};

0 comments on commit 170f45c

Please sign in to comment.