Remove the code nothing in production calls (closes #312)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
Service.Warm, the ImageCache interface, both GenerateSignedURL methods, signature.ParseParams, imagerequest.ParseImagePath, four symbols of internal/magic, the image processor's lists of supported formats, IsEmpty and Count of the allowlist, ssrfSafeDialer, CacheStale, ErrCacheMiss, ErrNegativeCache, ImageResponse.LastModified and the Load methods of ContentStorage and VariantStorage had no caller outside tests. They are gone, with the tests that tested only them. The handlers tests sign their image URLs with generateSignedURL, a test helper that builds the URL as the removed generator did. The SSRF dialer tests call dialSSRFSafe with no operator blocklist, which is all ssrfSafeDialer did. The tests of ParseImagePath and ContentStorage.Load call ParseImageURL and LoadWithSize instead. MIMEToImageFormat, ContentStorage.Store and CleanExpired stay, as pixa calls them. Model: opus-5-5
This commit was merged in pull request #329.
This commit is contained in:
+6
-71
@@ -5,7 +5,6 @@ package magic
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -36,22 +35,17 @@ type ImageFormat string
|
||||
|
||||
// Supported image output formats.
|
||||
const (
|
||||
FormatOriginal ImageFormat = "orig"
|
||||
FormatJPEG ImageFormat = "jpeg"
|
||||
FormatPNG ImageFormat = "png"
|
||||
FormatWebP ImageFormat = "webp"
|
||||
FormatAVIF ImageFormat = "avif"
|
||||
FormatJXL ImageFormat = "jxl"
|
||||
FormatGIF ImageFormat = "gif"
|
||||
FormatJPEG ImageFormat = "jpeg"
|
||||
FormatPNG ImageFormat = "png"
|
||||
FormatWebP ImageFormat = "webp"
|
||||
FormatAVIF ImageFormat = "avif"
|
||||
FormatJXL ImageFormat = "jxl"
|
||||
FormatGIF ImageFormat = "gif"
|
||||
)
|
||||
|
||||
// MinMagicBytes is the minimum number of bytes needed to detect format.
|
||||
const MinMagicBytes = 12
|
||||
|
||||
// mimeOctetStream is the fallback MIME type for formats without a
|
||||
// specific MIME type.
|
||||
const mimeOctetStream = "application/octet-stream"
|
||||
|
||||
// Magic byte signatures for supported formats.
|
||||
// These are effectively constants but Go doesn't support const slices.
|
||||
//
|
||||
@@ -190,42 +184,6 @@ func normalizeMIMEType(mimeType string) string {
|
||||
return strings.TrimSpace(strings.ToLower(mimeType))
|
||||
}
|
||||
|
||||
// IsSupportedMIMEType checks if a MIME type is supported for input.
|
||||
func IsSupportedMIMEType(mimeType string) bool {
|
||||
normalized := normalizeMIMEType(mimeType)
|
||||
switch MIMEType(normalized) {
|
||||
case MIMETypeJPEG, MIMETypePNG, MIMETypeWebP, MIMETypeGIF, MIMETypeAVIF,
|
||||
MIMETypeJXL, MIMETypeSVG:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// PeekAndValidate reads the minimum bytes needed for format detection,
|
||||
// validates against the declared type, and returns a reader that includes
|
||||
// those bytes for subsequent reading.
|
||||
func PeekAndValidate(r io.Reader, declaredType string) (io.Reader, error) {
|
||||
// Read minimum bytes for detection
|
||||
buf := make([]byte, MinMagicBytes)
|
||||
|
||||
n, err := io.ReadFull(r, buf)
|
||||
if err != nil && !errors.Is(err, io.ErrUnexpectedEOF) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
buf = buf[:n]
|
||||
|
||||
// Validate magic bytes
|
||||
err = ValidateMagicBytes(buf, declaredType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Return a reader that includes the peeked bytes
|
||||
return io.MultiReader(bytes.NewReader(buf), r), nil
|
||||
}
|
||||
|
||||
// MIMEToImageFormat converts a MIME type to an ImageFormat.
|
||||
func MIMEToImageFormat(mimeType string) (ImageFormat, bool) {
|
||||
normalized := normalizeMIMEType(mimeType)
|
||||
@@ -249,26 +207,3 @@ func MIMEToImageFormat(mimeType string) (ImageFormat, bool) {
|
||||
return "", false
|
||||
}
|
||||
}
|
||||
|
||||
// ImageFormatToMIME converts an ImageFormat to a MIME type string.
|
||||
func ImageFormatToMIME(format ImageFormat) string {
|
||||
switch format {
|
||||
case FormatJPEG:
|
||||
return string(MIMETypeJPEG)
|
||||
case FormatPNG:
|
||||
return string(MIMETypePNG)
|
||||
case FormatWebP:
|
||||
return string(MIMETypeWebP)
|
||||
case FormatGIF:
|
||||
return string(MIMETypeGIF)
|
||||
case FormatAVIF:
|
||||
return string(MIMETypeAVIF)
|
||||
case FormatJXL:
|
||||
return string(MIMETypeJXL)
|
||||
case FormatOriginal:
|
||||
// Original format passes content through unchanged.
|
||||
return mimeOctetStream
|
||||
default:
|
||||
return mimeOctetStream
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user