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

Add SVG studio image support, and studio image caching #418

Merged
merged 3 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 18 additions & 0 deletions pkg/api/routes_studio.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package api

import (
"context"
"crypto/md5"
"fmt"
"github.com/go-chi/chi"
"github.com/stashapp/stash/pkg/models"
"net/http"
"strconv"
"strings"
)

type studioRoutes struct{}
Expand All @@ -23,6 +26,21 @@ func (rs studioRoutes) Routes() chi.Router {

func (rs studioRoutes) Image(w http.ResponseWriter, r *http.Request) {
studio := r.Context().Value(studioKey).(*models.Studio)
etag := fmt.Sprintf("%x", md5.Sum(studio.Image))
if match := r.Header.Get("If-None-Match"); match != "" {
if strings.Contains(match, etag) {
w.WriteHeader(http.StatusNotModified)
return
}
}

contentType := http.DetectContentType(studio.Image)
if contentType == "text/xml; charset=utf-8" {
bnkai marked this conversation as resolved.
Show resolved Hide resolved
contentType = "image/svg+xml"
}

w.Header().Set("Content-Type", contentType)
w.Header().Add("Etag", etag)
_, _ = w.Write(studio.Image)
}

Expand Down
2 changes: 2 additions & 0 deletions ui/v2.5/src/components/Shared/DetailsEditNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface IProps {
onAutoTag?: () => void;
onImageChange: (event: React.FormEvent<HTMLInputElement>) => void;
onBackImageChange?: (event: React.FormEvent<HTMLInputElement>) => void;
acceptSVG?: boolean;
}

export const DetailsEditNavbar: React.FC<IProps> = (props: IProps) => {
Expand Down Expand Up @@ -113,6 +114,7 @@ export const DetailsEditNavbar: React.FC<IProps> = (props: IProps) => {
isEditing={props.isEditing}
text={props.onBackImageChange ? "Front image..." : undefined}
onImageChange={props.onImageChange}
acceptSVG={props.acceptSVG ?? false}
/>
{renderBackImageInput()}
{renderAutoTagButton()}
Expand Down
6 changes: 4 additions & 2 deletions ui/v2.5/src/components/Shared/ImageInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ interface IImageInput {
isEditing: boolean;
text?: string;
onImageChange: (event: React.FormEvent<HTMLInputElement>) => void;
acceptSVG?: boolean;
}

export const ImageInput: React.FC<IImageInput> = ({
isEditing,
text,
onImageChange
onImageChange,
acceptSVG = false
}) => {
if (!isEditing) return <div />;

Expand All @@ -20,7 +22,7 @@ export const ImageInput: React.FC<IImageInput> = ({
<Form.Control
type="file"
onChange={onImageChange}
accept=".jpg,.jpeg,.png"
accept={`.jpg,.jpeg,.png${acceptSVG ? ',.svg' : ''}`}
/>
</Form.Label>
);
Expand Down
1 change: 1 addition & 0 deletions ui/v2.5/src/components/Studios/StudioDetails/Studio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export const Studio: React.FC = () => {
onImageChange={onImageChangeHandler}
onAutoTag={onAutoTag}
onDelete={onDelete}
acceptSVG
/>
</div>
{!isNew && (
Expand Down