images

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package images is the gateway-side presign service for user image uploads: its own blobstore.Storage (its own bucket) and its own /v1/images route, built on pkg/blobstore.

Flow (see the project plan): the client asks for an upload slot and gets a presigned PUT URL plus a presigned GET URL; it uploads the bytes, then sends the GET URL inside its chat message. The credential-free sprite downloads via the GET URL and inlines the image into the agent — the gateway never sees the bytes.

Index

Constants

View Source
const DefaultPresignTTL = 30 * time.Minute

DefaultPresignTTL is how long image presigned URLs stay valid when Config.PresignTTL is zero. Longer than sync's 5m default because the GET URL is minted at upload time and must outlive the user composing and sending the message.

Variables

View Source
var AllowedMimes = map[string]bool{
	"image/png":  true,
	"image/jpeg": true,
	"image/webp": true,
	"image/gif":  true,
}

AllowedMimes is the closed set of accepted image content types — the formats Claude and OpenCode both take as vision input. A closed set (not a prefix check) stops the presign endpoint from minting upload slots for arbitrary content.

Functions

func KeyForImage

func KeyForImage(userID, imageID string) (string, error)

KeyForImage builds the storage key for a user's uploaded image:

<userID>/images/<imageID>

Images live in a dedicated bucket (separate from sync), so the prefix is tenant-scoping/defense-in-depth rather than collision avoidance. userID MUST come from authenticated token claims; imageID is a server-minted ULID. Both are validated for path safety.

Types

type Config

type Config struct {
	// Storage is the object store images live in — its own dedicated
	// bucket. Required.
	Storage blobstore.Storage

	// PresignTTL overrides DefaultPresignTTL when non-zero.
	PresignTTL time.Duration
}

Config wires a Server.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server mints presigned image upload/download URLs.

func NewServer

func NewServer(cfg Config) (*Server, error)

NewServer constructs a Server. Storage is required — fail fast at startup rather than 500 per request.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the image routes. Mount under the gateway's authenticated surface — the handler reads the caller from the auth.Principal the outer middleware injects.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL