api

package
v1.3.8 Latest Latest
Warning

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

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

Documentation

Overview

Package api owns the orchestrator: it takes a resolved Provider, a Request, and orchestration-only parameters (output folder, filename rules, total count), fans out provider calls in parallel while respecting MaxBatchN, writes each image to disk, and returns a per-image result summary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GenerationOutput

type GenerationOutput struct {
	Results      []GenerationResult
	OutputFolder string
	Elapsed      time.Duration

	// MetadataSkipped is true when Metadata was requested but a saved image wasn't PNG, so nothing was embedded.
	MetadataSkipped bool
}

GenerationOutput wraps the full run.

func RunGeneration

func RunGeneration(ctx context.Context, provider providers.Provider, request providers.Request, params Params) GenerationOutput

RunGeneration dispatches NumImages through the given Provider, batching at Info().Capabilities.MaxBatchN. Each batch runs in its own goroutine; each successful image is saved to disk using ResolveFilename's precedence rules. ctx cancels in-flight HTTP (Ctrl+C via fang).

type GenerationResult

type GenerationResult struct {
	Index     int
	ImageData []byte
	Filename  string
	Error     error
	Duration  time.Duration // wall time of the provider call that produced this image
	// contains filtered or unexported fields
}

GenerationResult is the outcome of a single image request/save.

type Params

type Params struct {
	OutputFolder     string
	OutputFilename   string // -f
	NumImages        int    // total, across all batches
	PreserveFilename bool   // -r
	RefInputPath     string // original -i path, used by -r

	// MaxParallel caps in-flight provider calls within this run. 0
	// (default) means unlimited — every batch fires immediately, the
	// pre-existing behaviour. Ignored when Sem is non-nil.
	MaxParallel int

	// Sem, when non-nil, is a shared concurrency semaphore — the batch
	// runner creates one and passes the same channel into every entry's
	// orchestrator call so a single --max-parallel cap covers both the
	// per-entry and per-image axes. Single-shot leaves this nil and the
	// orchestrator builds a private sem from MaxParallel.
	Sem chan struct{}

	// Progress, when non-nil, receives each result in completion order and is closed when the run finishes.
	// Sends are synchronous: it MUST be buffered to >= NumImages or drained concurrently, else RunGeneration blocks.
	Progress chan<- GenerationResult

	// Metadata, when non-empty, is embedded into PNG output (--embed-metadata); a no-op for other formats.
	Metadata []images.TextTag
}

Params holds orchestration-only settings — things no provider needs to know.

Jump to

Keyboard shortcuts

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