Fix scraped movie to create input translation (#3969)

This commit is contained in:
WithoutPants
2023-07-31 19:21:44 +10:00
committed by GitHub
parent a354f9b36b
commit 170f45c445
5 changed files with 76 additions and 59 deletions

View File

@@ -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>,
@@ -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({

View File

@@ -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<ISceneScrapeDialogProps> = ({
}
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<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 },
});

View File

@@ -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;
};

View File

@@ -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;
};

View File

@@ -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<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;
};