Skip to content

Commit

Permalink
Merge studio stash ids (stashapp#4572)
Browse files Browse the repository at this point in the history
  • Loading branch information
WithoutPants authored and halkeye committed Sep 1, 2024
1 parent cc4e327 commit 38d53b4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ui/v2.5/src/components/Tagger/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { useToast } from "src/hooks/Toast";
import { ConfigurationContext } from "src/hooks/Config";
import { ITaggerSource, SCRAPER_PREFIX, STASH_BOX_PREFIX } from "./constants";
import { errorToString } from "src/utils";
import { mergeStudioStashIDs } from "./utils";

export interface ITaggerContextState {
config: ITaggerConfig;
Expand Down Expand Up @@ -708,6 +709,11 @@ export const TaggerContext: React.FC = ({ children }) => {

async function updateExistingStudio(input: GQL.StudioUpdateInput) {
try {
const inputCopy = { ...input };
inputCopy.stash_ids = await mergeStudioStashIDs(
input.id,
input.stash_ids ?? []
);
const result = await updateStudio({
variables: {
input: input,
Expand Down
12 changes: 12 additions & 0 deletions ui/v2.5/src/components/Tagger/studios/StashSearchResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { faTags } from "@fortawesome/free-solid-svg-icons";
import { useStudioCreate } from "src/core/StashService";
import { useIntl } from "react-intl";
import { apolloError } from "src/utils";
import { mergeStudioStashIDs } from "../utils";

interface IStashSearchResultProps {
studio: GQL.SlimStudioDataFragment;
Expand Down Expand Up @@ -69,6 +70,12 @@ const StashSearchResult: React.FC<IStashSearchResultProps> = ({
...parentInput,
id: input.parent_id,
};

parentUpdateData.stash_ids = await mergeStudioStashIDs(
input.parent_id,
parentInput.stash_ids ?? []
);

await updateStudio(parentUpdateData);
} else {
const parentRes = await createStudio({
Expand All @@ -87,6 +94,11 @@ const StashSearchResult: React.FC<IStashSearchResultProps> = ({
id: studio.id,
};

updateData.stash_ids = await mergeStudioStashIDs(
studio.id,
input.stash_ids ?? []
);

const res = await updateStudio(updateData);

if (!res?.data?.studioUpdate)
Expand Down
9 changes: 9 additions & 0 deletions ui/v2.5/src/components/Tagger/studios/StudioTagger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { useUpdateStudio } from "../queries";
import { apolloError } from "src/utils";
import { faStar, faTags } from "@fortawesome/free-solid-svg-icons";
import { ExternalLink } from "src/components/Shared/ExternalLink";
import { mergeStudioStashIDs } from "../utils";

type JobFragment = Pick<
GQL.Job,
Expand Down Expand Up @@ -426,6 +427,10 @@ const StudioTaggerList: React.FC<IStudioTaggerListProps> = ({
...parentInput,
id: input.parent_id,
};
parentUpdateData.stash_ids = await mergeStudioStashIDs(
input.parent_id,
parentInput.stash_ids ?? []
);
await updateStudio(parentUpdateData);
} else {
const parentRes = await createStudio({
Expand All @@ -442,6 +447,10 @@ const StudioTaggerList: React.FC<IStudioTaggerListProps> = ({
...input,
id: studioID,
};
updateData.stash_ids = await mergeStudioStashIDs(
studioID,
input.stash_ids ?? []
);

const res = await updateStudio(updateData);
if (!res.data?.studioUpdate)
Expand Down
14 changes: 14 additions & 0 deletions ui/v2.5/src/components/Tagger/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as GQL from "src/core/generated-graphql";
import { ParseMode } from "./constants";
import { queryFindStudio } from "src/core/StashService";
import { mergeStashIDs } from "src/utils/stashbox";

const months = [
"jan",
Expand Down Expand Up @@ -142,3 +144,15 @@ export const parsePath = (filePath: string) => {

return { paths, file, ext };
};

export async function mergeStudioStashIDs(
id: string,
newStashIDs: GQL.StashIdInput[]
) {
const existing = await queryFindStudio(id);
if (existing?.data?.findStudio?.stash_ids) {
return mergeStashIDs(existing.data.findStudio.stash_ids, newStashIDs);
}

return newStashIDs;
}

0 comments on commit 38d53b4

Please sign in to comment.