mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Fix performer scraping (#1314)
This commit is contained in:
@@ -146,7 +146,7 @@ export const PerformerEditPanel: React.FC<IPerformerDetails> = ({
|
|||||||
const formik = useFormik({
|
const formik = useFormik({
|
||||||
initialValues,
|
initialValues,
|
||||||
validationSchema: schema,
|
validationSchema: schema,
|
||||||
onSubmit: (values) => onSave(getPerformerInput(values)),
|
onSubmit: (values) => onSave(values),
|
||||||
});
|
});
|
||||||
|
|
||||||
function translateScrapedGender(scrapedGender?: string) {
|
function translateScrapedGender(scrapedGender?: string) {
|
||||||
@@ -158,7 +158,7 @@ export const PerformerEditPanel: React.FC<IPerformerDetails> = ({
|
|||||||
|
|
||||||
// try to translate from enum values first
|
// try to translate from enum values first
|
||||||
const upperGender = scrapedGender?.toUpperCase();
|
const upperGender = scrapedGender?.toUpperCase();
|
||||||
const asEnum = genderToString(upperGender as GQL.GenderEnum);
|
const asEnum = genderToString(upperGender);
|
||||||
if (asEnum) {
|
if (asEnum) {
|
||||||
retEnum = stringToGender(asEnum);
|
retEnum = stringToGender(asEnum);
|
||||||
} else {
|
} else {
|
||||||
@@ -214,9 +214,14 @@ export const PerformerEditPanel: React.FC<IPerformerDetails> = ({
|
|||||||
variables: tagInput,
|
variables: tagInput,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!result.data?.tagCreate) {
|
||||||
|
Toast.error(new Error("Failed to create tag"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// add the new tag to the new tags value
|
// add the new tag to the new tags value
|
||||||
const newTagIds = formik.values.tag_ids.concat([
|
const newTagIds = formik.values.tag_ids.concat([
|
||||||
result.data!.tagCreate!.id,
|
result.data.tagCreate.id,
|
||||||
]);
|
]);
|
||||||
formik.setFieldValue("tag_ids", newTagIds);
|
formik.setFieldValue("tag_ids", newTagIds);
|
||||||
|
|
||||||
@@ -298,7 +303,7 @@ export const PerformerEditPanel: React.FC<IPerformerDetails> = ({
|
|||||||
if (state.tags) {
|
if (state.tags) {
|
||||||
// map tags to their ids and filter out those not found
|
// map tags to their ids and filter out those not found
|
||||||
const newTagIds = state.tags.map((t) => t.stored_id).filter((t) => t);
|
const newTagIds = state.tags.map((t) => t.stored_id).filter((t) => t);
|
||||||
formik.setFieldValue("tag_ids", newTagIds as string[]);
|
formik.setFieldValue("tag_ids", newTagIds);
|
||||||
|
|
||||||
setNewTags(state.tags.filter((t) => !t.stored_id));
|
setNewTags(state.tags.filter((t) => !t.stored_id));
|
||||||
}
|
}
|
||||||
@@ -309,9 +314,9 @@ export const PerformerEditPanel: React.FC<IPerformerDetails> = ({
|
|||||||
// otherwise follow existing behaviour
|
// otherwise follow existing behaviour
|
||||||
if (
|
if (
|
||||||
(!isNew || formik.values.image === undefined) &&
|
(!isNew || formik.values.image === undefined) &&
|
||||||
(state as GQL.ScrapedPerformerDataFragment).image !== undefined
|
state.image !== undefined
|
||||||
) {
|
) {
|
||||||
const imageStr = (state as GQL.ScrapedPerformerDataFragment).image;
|
const imageStr = state.image;
|
||||||
formik.setFieldValue("image", imageStr ?? undefined);
|
formik.setFieldValue("image", imageStr ?? undefined);
|
||||||
}
|
}
|
||||||
if (state.details) {
|
if (state.details) {
|
||||||
@@ -332,29 +337,30 @@ export const PerformerEditPanel: React.FC<IPerformerDetails> = ({
|
|||||||
formik.setFieldValue("image", imageData);
|
formik.setFieldValue("image", imageData);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onSave(
|
async function onSave(performerInput: InputValues) {
|
||||||
performerInput:
|
|
||||||
| Partial<GQL.PerformerCreateInput>
|
|
||||||
| Partial<GQL.PerformerUpdateInput>
|
|
||||||
) {
|
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
if (!isNew) {
|
if (!isNew) {
|
||||||
|
const input = getUpdateValues(performerInput);
|
||||||
|
|
||||||
await updatePerformer({
|
await updatePerformer({
|
||||||
variables: {
|
variables: {
|
||||||
input: {
|
input: {
|
||||||
...performerInput,
|
...input,
|
||||||
stash_ids: performerInput?.stash_ids?.map((s) => ({
|
stash_ids: performerInput?.stash_ids?.map((s) => ({
|
||||||
endpoint: s.endpoint,
|
endpoint: s.endpoint,
|
||||||
stash_id: s.stash_id,
|
stash_id: s.stash_id,
|
||||||
})),
|
})),
|
||||||
} as GQL.PerformerUpdateInput,
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
history.push(`/performers/${performer.id}`);
|
history.push(`/performers/${performer.id}`);
|
||||||
} else {
|
} else {
|
||||||
|
const input = getCreateValues(performerInput);
|
||||||
const result = await createPerformer({
|
const result = await createPerformer({
|
||||||
variables: { input: performerInput as GQL.PerformerCreateInput },
|
variables: {
|
||||||
|
input,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
if (result.data?.performerCreate) {
|
if (result.data?.performerCreate) {
|
||||||
history.push(`/performers/${result.data.performerCreate.id}`);
|
history.push(`/performers/${result.data.performerCreate.id}`);
|
||||||
@@ -370,7 +376,7 @@ export const PerformerEditPanel: React.FC<IPerformerDetails> = ({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isVisible) {
|
if (isVisible) {
|
||||||
Mousetrap.bind("s s", () => {
|
Mousetrap.bind("s s", () => {
|
||||||
onSave?.(getPerformerInput(formik.values));
|
onSave?.(formik.values);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isNew) {
|
if (!isNew) {
|
||||||
@@ -413,19 +419,21 @@ export const PerformerEditPanel: React.FC<IPerformerDetails> = ({
|
|||||||
|
|
||||||
if (isLoading) return <LoadingIndicator />;
|
if (isLoading) return <LoadingIndicator />;
|
||||||
|
|
||||||
function getPerformerInput(values: InputValues) {
|
function getUpdateValues(values: InputValues): GQL.PerformerUpdateInput {
|
||||||
const performerInput: Partial<
|
return {
|
||||||
GQL.PerformerCreateInput | GQL.PerformerUpdateInput
|
...values,
|
||||||
> = {
|
gender: stringToGender(values.gender),
|
||||||
|
weight: Number(values.weight),
|
||||||
|
id: performer.id ?? "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCreateValues(values: InputValues): GQL.PerformerCreateInput {
|
||||||
|
return {
|
||||||
...values,
|
...values,
|
||||||
gender: stringToGender(values.gender),
|
gender: stringToGender(values.gender),
|
||||||
weight: Number(values.weight),
|
weight: Number(values.weight),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!isNew) {
|
|
||||||
(performerInput as GQL.PerformerUpdateInput).id = performer.id!;
|
|
||||||
}
|
|
||||||
return performerInput;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onImageChangeHandler(event: React.FormEvent<HTMLInputElement>) {
|
function onImageChangeHandler(event: React.FormEvent<HTMLInputElement>) {
|
||||||
|
|||||||
@@ -16,9 +16,10 @@ import {
|
|||||||
usePerformerCreate,
|
usePerformerCreate,
|
||||||
useMovieCreate,
|
useMovieCreate,
|
||||||
useTagCreate,
|
useTagCreate,
|
||||||
|
stringToGender,
|
||||||
} from "src/core/StashService";
|
} from "src/core/StashService";
|
||||||
import { useToast } from "src/hooks";
|
import { useToast } from "src/hooks";
|
||||||
import { DurationUtils } from "src/utils";
|
import { DurationUtils, filterData } from "src/utils";
|
||||||
|
|
||||||
function renderScrapedStudio(
|
function renderScrapedStudio(
|
||||||
result: ScrapeResult<string>,
|
result: ScrapeResult<string>,
|
||||||
@@ -360,11 +361,37 @@ export const SceneScrapeDialog: React.FC<ISceneScrapeDialogProps> = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function createNewPerformer(toCreate: GQL.ScrapedScenePerformer) {
|
async function createNewPerformer(toCreate: GQL.ScrapedScenePerformer) {
|
||||||
let performerInput: GQL.PerformerCreateInput = { name: "" };
|
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: toCreate.height,
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
performerInput = Object.assign(performerInput, toCreate);
|
|
||||||
const result = await createPerformer({
|
const result = await createPerformer({
|
||||||
variables: { input: performerInput },
|
variables: { input },
|
||||||
});
|
});
|
||||||
|
|
||||||
// add the new performer to the new performers value
|
// add the new performer to the new performers value
|
||||||
|
|||||||
@@ -933,7 +933,7 @@ export const stringGenderMap = new Map<string, GQL.GenderEnum>([
|
|||||||
["Non-Binary", GQL.GenderEnum.NonBinary],
|
["Non-Binary", GQL.GenderEnum.NonBinary],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export const genderToString = (value?: GQL.GenderEnum) => {
|
export const genderToString = (value?: GQL.GenderEnum | string) => {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -947,7 +947,10 @@ export const genderToString = (value?: GQL.GenderEnum) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const stringToGender = (value?: string, caseInsensitive?: boolean) => {
|
export const stringToGender = (
|
||||||
|
value?: string | null,
|
||||||
|
caseInsensitive?: boolean
|
||||||
|
) => {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
2
ui/v2.5/src/utils/data.ts
Normal file
2
ui/v2.5/src/utils/data.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
export const filterData = <T>(data?: (T | null | undefined)[] | null) =>
|
||||||
|
data ? (data.filter((item) => item) as T[]) : [];
|
||||||
@@ -11,3 +11,4 @@ export { default as flattenMessages } from "./flattenMessages";
|
|||||||
export { default as getISOCountry } from "./country";
|
export { default as getISOCountry } from "./country";
|
||||||
export { default as useFocus } from "./focus";
|
export { default as useFocus } from "./focus";
|
||||||
export { default as downloadFile } from "./download";
|
export { default as downloadFile } from "./download";
|
||||||
|
export * from "./data";
|
||||||
|
|||||||
Reference in New Issue
Block a user