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, three functions of internal/magic, the image processor's lists of supported formats, IsEmpty and Count of the allowlist, ssrfSafeDialer, CacheStale, ErrCacheMiss, ErrNegativeCache, ImageResponse.LastModified and VariantStorage.Load 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. ParseImageURL, MIMEToImageFormat, ContentStorage.Store and CleanExpired stay, as pixa calls them. Model: opus-5-5
This commit is contained in:
@@ -14,12 +14,6 @@ import (
|
||||
"sneak.berlin/go/pixa/internal/imagerequest"
|
||||
)
|
||||
|
||||
// Cache errors.
|
||||
var (
|
||||
ErrCacheMiss = errors.New("cache miss")
|
||||
ErrNegativeCache = errors.New("negative cache hit")
|
||||
)
|
||||
|
||||
// maxPendingAccessTimes is how many access times of variants served from
|
||||
// the cache, and how many of cached sources a miss used, may each wait to be
|
||||
// written, at about 80 bytes each. An access time handed over while that
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
// Package imgcache provides interfaces and types for the image caching proxy.
|
||||
// Package imgcache provides types for the image caching proxy.
|
||||
package imgcache
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"sneak.berlin/go/pixa/internal/imagerequest"
|
||||
)
|
||||
import "io"
|
||||
|
||||
// ImageResponse represents a processed image ready to serve
|
||||
type ImageResponse struct {
|
||||
@@ -19,9 +13,7 @@ type ImageResponse struct {
|
||||
ContentType string
|
||||
// ETag is the entity tag for caching
|
||||
ETag string
|
||||
// LastModified is when the content was last modified
|
||||
LastModified time.Time
|
||||
// CacheStatus indicates HIT, MISS, or STALE
|
||||
// CacheStatus indicates HIT or MISS
|
||||
CacheStatus CacheStatus
|
||||
// FetchedBytes is the number of bytes fetched from upstream (0 if cache hit)
|
||||
FetchedBytes int64
|
||||
@@ -32,16 +24,6 @@ type CacheStatus string
|
||||
|
||||
// Cache status values for response headers.
|
||||
const (
|
||||
CacheHit CacheStatus = "HIT"
|
||||
CacheMiss CacheStatus = "MISS"
|
||||
CacheStale CacheStatus = "STALE"
|
||||
CacheHit CacheStatus = "HIT"
|
||||
CacheMiss CacheStatus = "MISS"
|
||||
)
|
||||
|
||||
// ImageCache is the main interface for the image caching proxy
|
||||
type ImageCache interface {
|
||||
// Get retrieves a processed image, fetching and processing if necessary
|
||||
Get(ctx context.Context, req *imagerequest.Request) (*ImageResponse, error)
|
||||
|
||||
// Warm pre-fetches and caches an image without returning it
|
||||
Warm(ctx context.Context, req *imagerequest.Request) error
|
||||
}
|
||||
|
||||
@@ -24,8 +24,7 @@ import (
|
||||
"sneak.berlin/go/pixa/internal/signature"
|
||||
)
|
||||
|
||||
// Service implements the ImageCache interface, orchestrating cache,
|
||||
// fetcher, and processor.
|
||||
// Service orchestrates the cache, fetcher, and processor.
|
||||
type Service struct {
|
||||
cache *Cache
|
||||
fetcher httpfetcher.Fetcher
|
||||
@@ -189,13 +188,6 @@ func (s *Service) Get(
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// Warm pre-fetches and caches an image without returning it.
|
||||
func (s *Service) Warm(ctx context.Context, req *imagerequest.Request) error {
|
||||
_, err := s.Get(ctx, req)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// WaitForProcessing waits until no image is being processed, or until ctx
|
||||
// ends, and returns how many images were still being processed then.
|
||||
func (s *Service) WaitForProcessing(ctx context.Context) int {
|
||||
@@ -229,30 +221,6 @@ func (s *Service) ValidateRequest(req *imagerequest.Request) error {
|
||||
return s.signer.Verify(req)
|
||||
}
|
||||
|
||||
// GenerateSignedURL generates a signed URL for the given request. The URL
|
||||
// carries q and fit next to sig and exp, so the image route verifies it for
|
||||
// the quality and fit it was signed with. An unset quality or fit is first
|
||||
// set to 85 or cover, the values the route uses when a URL has no q or fit.
|
||||
func (s *Service) GenerateSignedURL(
|
||||
baseURL string,
|
||||
req *imagerequest.Request,
|
||||
ttl time.Duration,
|
||||
) (string, error) {
|
||||
if req.Transform.Quality == 0 {
|
||||
req.Transform.Quality = 85
|
||||
}
|
||||
|
||||
if req.Transform.FitMode == "" {
|
||||
req.Transform.FitMode = imagerequest.FitCover
|
||||
}
|
||||
|
||||
// Sets the request's Expires and Signature
|
||||
path, sig, exp := s.signer.GenerateSignedURL(req, ttl)
|
||||
|
||||
return fmt.Sprintf("%s%s?sig=%s&exp=%d&q=%d&fit=%s",
|
||||
baseURL, path, sig, exp, req.Transform.Quality, req.Transform.FitMode), nil
|
||||
}
|
||||
|
||||
// errPanicked is returned when processing a variant panicked.
|
||||
var errPanicked = errors.New("panic while processing image")
|
||||
|
||||
|
||||
@@ -251,22 +251,6 @@ func (s *VariantStorage) Store(
|
||||
return int64(len(data)), nil
|
||||
}
|
||||
|
||||
// Load returns a reader for the content at the given key.
|
||||
func (s *VariantStorage) Load(key imagerequest.VariantKey) (io.ReadCloser, error) {
|
||||
path := s.keyToPath(key)
|
||||
|
||||
f, err := os.Open(path) //nolint:gosec // path derived from cache key
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("failed to open content: %w", err)
|
||||
}
|
||||
|
||||
return f, nil
|
||||
}
|
||||
|
||||
// LoadWithContentType opens the content at the given key and returns a
|
||||
// reader, the file size and the content type, which is read from the
|
||||
// file's first bytes. A missing file is ErrNotFound. A file whose first
|
||||
|
||||
Reference in New Issue
Block a user