mirror of
https://github.com/navidrome/navidrome.git
synced 2026-04-03 06:41:01 +00:00
If resize fails, send the artwork as is. Closes #1102
This commit is contained in:
parent
8e640bb858
commit
847a0432ea
@ -125,19 +125,24 @@ func (a *artwork) extractMediaFileImage(ctx context.Context, artID model.Artwork
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *artwork) resizedFromOriginal(ctx context.Context, artID model.ArtworkID, size int) (io.ReadCloser, string, error) {
|
func (a *artwork) resizedFromOriginal(ctx context.Context, artID model.ArtworkID, size int) (io.ReadCloser, string, error) {
|
||||||
r, path, err := a.get(ctx, artID, 0)
|
// first get original image
|
||||||
if err != nil || r == nil {
|
original, path, err := a.get(ctx, artID, 0)
|
||||||
|
if err != nil || original == nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
defer r.Close()
|
defer original.Close()
|
||||||
|
|
||||||
|
// Keep a copy of the original data. In case we can't resize it, send it as is
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
r := io.TeeReader(original, buf)
|
||||||
|
|
||||||
usePng := strings.ToLower(filepath.Ext(path)) == ".png"
|
usePng := strings.ToLower(filepath.Ext(path)) == ".png"
|
||||||
r, err = resizeImage(r, size, usePng)
|
resized, err := resizeImage(r, size, usePng)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn(ctx, "Could not resize image. Using placeholder", "artID", artID, "size", size, err)
|
log.Warn(ctx, "Could not resize image. Sending it as-is", "artID", artID, "size", size, err)
|
||||||
r, path := fromPlaceholder()()
|
return io.NopCloser(buf), path, nil
|
||||||
return r, path, nil
|
|
||||||
}
|
}
|
||||||
return r, fmt.Sprintf("%s@%d", path, size), nil
|
return resized, fmt.Sprintf("%s@%d", path, size), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type fromFunc func() (io.ReadCloser, string)
|
type fromFunc func() (io.ReadCloser, string)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user