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

Embed default icons #3577

Merged
merged 4 commits into from
Apr 17, 2023
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
11 changes: 10 additions & 1 deletion internal/api/routes_studio.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package api
import (
"context"
"errors"
"io"
"net/http"
"strconv"

"github.com/go-chi/chi"
"github.com/stashapp/stash/internal/static"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/studio"
Expand Down Expand Up @@ -55,7 +57,14 @@ func (rs studioRoutes) Image(w http.ResponseWriter, r *http.Request) {
}

if len(image) == 0 {
image, _ = utils.ProcessBase64Image(models.DefaultStudioImage)
const defaultStudioImage = "studio/studio.svg"

// fall back to static image
f, _ := static.Studio.Open(defaultStudioImage)
defer f.Close()
stat, _ := f.Stat()
http.ServeContent(w, r, "studio.svg", stat.ModTime(), f.(io.ReadSeeker))
return
}

if err := utils.ServeImage(image, w, r); err != nil {
Expand Down
11 changes: 10 additions & 1 deletion internal/api/routes_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package api
import (
"context"
"errors"
"io"
"net/http"
"strconv"

"github.com/go-chi/chi"
"github.com/stashapp/stash/internal/static"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/tag"
Expand Down Expand Up @@ -55,7 +57,14 @@ func (rs tagRoutes) Image(w http.ResponseWriter, r *http.Request) {
}

if len(image) == 0 {
image = models.DefaultTagImage
const defaultTagImage = "tag/tag.svg"

// fall back to static image
f, _ := static.Tag.Open(defaultTagImage)
defer f.Close()
stat, _ := f.Stat()
http.ServeContent(w, r, "tag.svg", stat.ModTime(), f.(io.ReadSeeker))
return
}

if err := utils.ServeImage(image, w, r); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions internal/static/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ var Scene embed.FS

//go:embed image
var Image embed.FS

//go:embed tag
var Tag embed.FS

//go:embed studio
var Studio embed.FS
7 changes: 7 additions & 0 deletions internal/static/studio/studio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions internal/static/tag/tag.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions pkg/models/model_studio.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ type StudioPartial struct {
IgnoreAutoTag *bool `db:"ignore_auto_tag" json:"ignore_auto_tag"`
}

var DefaultStudioImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4wgVBQsJl1CMZAAAASJJREFUeNrt3N0JwyAYhlEj3cj9R3Cm5rbkqtAP+qrnGaCYHPwJpLlaa++mmLpbAERAgAgIEAEBIiBABERAgAgIEAEBIiBABERAgAgIEAHZuVflj40x4i94zhk9vqsVvEq6AsQqMP1EjORx20OACAgQRRx7T+zzcFBxcjNDfoB4ntQqTm5Awo7MlqywZxcgYQ+RlqywJ3ozJAQCSBiEJSsQA0gYBpDAgAARECACAkRAgAgIEAERECACAmSjUv6eAOSB8m8YIGGzBUjYbAESBgMkbBkDEjZbgITBAClcxiqQvEoatreYIWEBASIgJ4Gkf11ntXH3nS9uxfGWfJ5J9hAgAgJEQAQEiIAAERAgAgJEQAQEiIAAERAgAgJEQAQEiL7qBuc6RKLHxr0CAAAAAElFTkSuQmCC"

func NewStudio(name string) *Studio {
currentTime := time.Now()
return &Studio{
Expand Down
129 changes: 0 additions & 129 deletions pkg/models/model_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,132 +58,3 @@ func (t *TagPaths) Append(o interface{}) {
func (t *TagPaths) New() interface{} {
return &TagPath{}
}

// Original Tag image from: https://fontawesome.com/icons/tag?style=solid
// Modified to change color and rotate
// Licensed under CC Attribution 4.0: https://fontawesome.com/license
var DefaultTagImage = []byte(`<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="200"
height="200"
id="svg2"
version="1.1"
inkscape:version="0.48.4 r9939"
sodipodi:docname="tag.svg">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#000000"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="1"
inkscape:pageshadow="2"
inkscape:zoom="1"
inkscape:cx="181.77771"
inkscape:cy="279.72376"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:window-width="1920"
inkscape:window-height="1017"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-157.84358,-524.69522)">
<path
id="path2987"
d="m 229.94314,669.26549 -36.08466,-36.08466 c -4.68653,-4.68653 -4.68653,-12.28468 0,-16.97121 l 36.08466,-36.08467 a 12.000453,12.000453 0 0 1 8.4856,-3.5148 l 74.91443,0 c 6.62761,0 12.00041,5.3728 12.00041,12.00041 l 0,72.16933 c 0,6.62761 -5.3728,12.00041 -12.00041,12.00041 l -74.91443,0 a 12.000453,12.000453 0 0 1 -8.4856,-3.51481 z m -13.45639,-53.05587 c -4.68653,4.68653 -4.68653,12.28468 0,16.97121 4.68652,4.68652 12.28467,4.68652 16.9712,0 4.68653,-4.68653 4.68653,-12.28468 0,-16.97121 -4.68653,-4.68652 -12.28468,-4.68652 -16.9712,0 z"
inkscape:connector-curvature="0"
style="fill:#ffffff;fill-opacity:1" />
</g>
</svg>`)

// var DefaultTagImage = []byte(`<svg
// xmlns:dc="http://purl.org/dc/elements/1.1/"
// xmlns:cc="http://creativecommons.org/ns#"
// xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
// xmlns:svg="http://www.w3.org/2000/svg"
// xmlns="http://www.w3.org/2000/svg"
// xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
// xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
// width="600"
// height="600"
// id="svg2"
// version="1.1"
// inkscape:version="0.48.4 r9939"
// sodipodi:docname="New document 1">
// <defs
// id="defs4" />
// <sodipodi:namedview
// id="base"
// pagecolor="#000000"
// bordercolor="#666666"
// borderopacity="1.0"
// inkscape:pageopacity="1"
// inkscape:pageshadow="2"
// inkscape:zoom="0.82173542"
// inkscape:cx="181.77771"
// inkscape:cy="159.72376"
// inkscape:document-units="px"
// inkscape:current-layer="layer1"
// showgrid="false"
// fit-margin-top="0"
// fit-margin-left="0"
// fit-margin-right="0"
// fit-margin-bottom="0"
// inkscape:window-width="1920"
// inkscape:window-height="1017"
// inkscape:window-x="-8"
// inkscape:window-y="-8"
// inkscape:window-maximized="1" />
// <metadata
// id="metadata7">
// <rdf:RDF>
// <cc:Work
// rdf:about="">
// <dc:format>image/svg+xml</dc:format>
// <dc:type
// rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
// <dc:title></dc:title>
// </cc:Work>
// </rdf:RDF>
// </metadata>
// <g
// inkscape:label="Layer 1"
// inkscape:groupmode="layer"
// id="layer1"
// transform="translate(-157.84358,-124.69522)">
// <path
// id="path2987"
// d="M 346.24605,602.96957 201.91282,458.63635 c -18.7454,-18.7454 -18.7454,-49.13685 0,-67.88225 L 346.24605,246.42087 a 48,48 0 0 1 33.94111,-14.05869 l 299.64641,0 c 26.50943,0 47.99982,21.49039 47.99982,47.99982 l 0,288.66645 c 0,26.50943 -21.49039,47.99982 -47.99983,47.99982 l -299.64639,0 a 48,48 0 0 1 -33.94112,-14.0587 z M 292.42249,390.7541 c -18.7454,18.7454 -18.7454,49.13685 0,67.88225 18.7454,18.7454 49.13685,18.7454 67.88225,0 18.7454,-18.7454 18.7454,-49.13685 0,-67.88225 -18.7454,-18.7454 -49.13685,-18.7454 -67.88225,0 z"
// inkscape:connector-curvature="0"
// style="fill:#ffffff;fill-opacity:1" />
// </g>
// </svg>`)
2 changes: 1 addition & 1 deletion pkg/sqlite/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1726,5 +1726,5 @@ func linkTagsParent(ctx context.Context, qb models.TagReaderWriter) error {
}

func addTagImage(ctx context.Context, qb models.TagWriter, tagIndex int) error {
return qb.UpdateImage(ctx, tagIDs[tagIndex], models.DefaultTagImage)
return qb.UpdateImage(ctx, tagIDs[tagIndex], []byte("image"))
}