Skip to content

@lastshotlabs/slingshot-image

npm install @lastshotlabs/slingshot-image

Create the slingshot-image plugin.

Registers a GET /_snapshot/image handler on the Hono app that resizes, converts, and caches image responses. Backed by sharp when installed; falls back to serving originals with a warning when sharp is absent.

SSRF protection: The url query parameter is validated against config.allowedOrigins before any network fetch is attempted. Relative URLs (starting with /) are always allowed and resolved against localhost. Absolute URLs are only allowed when their hostname is in allowedOrigins.

Factory pattern (Rule 3): Each call to createImagePlugin() creates a fresh, isolated cache instance. No shared mutable state between plugin instances or app instances.

function createImagePlugin(rawConfig?: ImagePluginConfig): SlingshotPlugin

Source: packages/slingshot-image/src/plugin.ts

Creates an in-memory LRU image cache adapter.

Uses a Map (insertion-order) as the backing store. When maxEntries is reached, the oldest-inserted key is evicted on the next set() call.

This is the default cache used by createImagePlugin() when no custom adapter is provided.

function createMemoryImageCache(opts?: MemoryImageCacheOptions): ImageCacheAdapter

Source: packages/slingshot-image/src/cache.ts

Error thrown when image transform parameters violate configured limits.

Source: packages/slingshot-image/src/types.ts

Cache adapter interface for image responses.

Implement this to plug in custom storage (Redis, file system, etc.). The default implementation uses an in-memory LRU map.

Source: packages/slingshot-image/src/types.ts

A cached image entry stored by the cache adapter.

Source: packages/slingshot-image/src/types.ts

Configuration for createImagePlugin().

Source: packages/slingshot-image/src/types.ts

Options controlling how an image is transformed.

Source: packages/slingshot-image/src/types.ts

The result of a successful image transformation.

Source: packages/slingshot-image/src/types.ts

Supported output image formats for the image optimization handler.

Source: packages/slingshot-image/src/types.ts