Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Don't set image.title to file basename in graphql #5658

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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: 0 additions & 6 deletions gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ models:
model: github.com/stashapp/stash/internal/api.BoolMap
PluginConfigMap:
model: github.com/stashapp/stash/internal/api.PluginConfigMap
# define to force resolvers
Image:
model: github.com/stashapp/stash/pkg/models.Image
fields:
title:
resolver: true
VideoFile:
fields:
# override float fields - #1572
Expand Down
5 changes: 0 additions & 5 deletions internal/api/resolver_model_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ func (r *imageResolver) getFiles(ctx context.Context, obj *models.Image) ([]mode
return files, firstError(errs)
}

func (r *imageResolver) Title(ctx context.Context, obj *models.Image) (*string, error) {
ret := obj.GetTitle()
return &ret, nil
}

func (r *imageResolver) VisualFiles(ctx context.Context, obj *models.Image) ([]VisualFile, error) {
files, err := r.getFiles(ctx, obj)
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions ui/v2.5/graphql/data/image-slim.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ fragment SlimImageData on Image {
organized
o_counter

files {
...ImageFileData
}

paths {
thumbnail
preview
Expand Down
4 changes: 0 additions & 4 deletions ui/v2.5/graphql/data/image.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ fragment ImageData on Image {
created_at
updated_at

files {
...ImageFileData
}

paths {
thumbnail
preview
Expand Down
4 changes: 2 additions & 2 deletions ui/v2.5/src/components/Images/ImageCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
faSearch,
faTag,
} from "@fortawesome/free-solid-svg-icons";
import { objectTitle } from "src/core/files";
import { imageTitle } from "src/core/files";
import { TruncatedText } from "../Shared/TruncatedText";
import ScreenUtils from "src/utils/screen";
import { StudioOverlay } from "../Shared/GridCard/StudioOverlay";
Expand Down Expand Up @@ -197,7 +197,7 @@ export const ImageCard: React.FC<IImageCardProps> = (
className={`image-card zoom-${props.zoomIndex}`}
url={`/images/${props.image.id}`}
width={cardWidth}
title={objectTitle(props.image)}
title={imageTitle(props.image)}
linkClassName="image-card-link"
image={
<>
Expand Down
8 changes: 4 additions & 4 deletions ui/v2.5/src/components/Images/ImageDetails/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { ImageEditPanel } from "./ImageEditPanel";
import { ImageDetailPanel } from "./ImageDetailPanel";
import { DeleteImagesDialog } from "../DeleteImagesDialog";
import { faEllipsisV } from "@fortawesome/free-solid-svg-icons";
import { objectPath, objectTitle } from "src/core/files";
import { imagePath, imageTitle } from "src/core/files";
import { isVideo } from "src/utils/visualFile";
import { useScrollToTopOnMount } from "src/hooks/scrollToTop";
import { useRatingKeybinds } from "src/hooks/keybinds";
Expand Down Expand Up @@ -79,7 +79,7 @@ const ImagePage: React.FC<IProps> = ({ image }) => {
}

await mutateMetadataScan({
paths: [objectPath(image)],
paths: [imagePath(image)],
rescan: true,
});

Expand Down Expand Up @@ -274,11 +274,11 @@ const ImagePage: React.FC<IProps> = ({ image }) => {
});

const file = useMemo(
() => (image.files.length > 0 ? image.files[0] : undefined),
() => (image.visual_files.length > 0 ? image.visual_files[0] : undefined),
[image]
);

const title = objectTitle(image);
const title = imageTitle(image);
const ImageView =
image.visual_files.length > 0 && isVideo(image.visual_files[0])
? "video"
Expand Down
25 changes: 25 additions & 0 deletions ui/v2.5/src/core/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,28 @@ export function objectPath(s: IObjectWithFiles) {
}
return "";
}

interface IObjectWithVisualFiles {
visual_files?: IFile[];
}

export interface IObjectWithTitleVisualFiles extends IObjectWithVisualFiles {
title?: GQL.Maybe<string>;
}

export function imageTitle(s: Partial<IObjectWithTitleVisualFiles>) {
if (s.title) {
return s.title;
}
if (s.visual_files && s.visual_files.length > 0) {
return TextUtils.fileNameFromPath(s.visual_files[0].path);
}
return "";
}

export function imagePath(s: IObjectWithVisualFiles) {
if (s.visual_files && s.visual_files.length > 0) {
return s.visual_files[0].path;
}
return "";
}