Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merge studio stash ids when saving in studio tagger #4572

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading