resource

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: GPL-3.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package resource turns MDD references into opaque, tamper-proof URL tokens and serves the bytes behind them.

Index

Constants

This section is empty.

Variables

View Source
var ErrBadToken = errors.New("invalid resource token")

ErrBadToken means the token was malformed, truncated, or not produced by this process.

View Source
var ErrNoSpeexDecoder = errors.New("speex decoder not available")

ErrNoSpeexDecoder means an Ogg-Speex asset was requested but no decoder is installed. The service degrades to reporting the asset as unavailable rather than substituting synthesized speech.

Functions

This section is empty.

Types

type Ref

type Ref struct {
	// DictionaryID scopes the reference. A token minted for one dictionary can
	// never address another.
	DictionaryID string `json:"d"`
	// ResourceRef is the MDD-internal key, e.g. "sound://synthetic/uk/example.mp3" in tests.
	// It is an index key, never a filesystem path.
	ResourceRef string `json:"r"`
}

Ref is the payload a token carries.

type Tokenizer

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

Tokenizer mints and verifies resource tokens.

Tokens are AES-GCM sealed with a key generated fresh at every start, so they are opaque to the client, cannot be forged, and cannot be rewritten to point at a different dictionary or resource. Because a token decodes to a dictionary ID plus an MDD index key — and resolution only ever consults that dictionary's in-memory resource index — path traversal, symlink escape and arbitrary local file reads are structurally impossible rather than filtered.

func NewTokenizer

func NewTokenizer() (*Tokenizer, error)

NewTokenizer creates a tokenizer with a random per-process key.

func (*Tokenizer) Mint

func (t *Tokenizer) Mint(ref Ref) (string, error)

Mint seals a reference into a token that is safe in URLs and Markdown.

func (*Tokenizer) Open

func (t *Tokenizer) Open(token string) (Ref, error)

Open verifies and decodes a token.

type Transcoder

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

Transcoder converts Ogg-Speex pronunciation assets to WAV, which macOS and Bob can play, and caches the result on disk so each asset is decoded once.

func NewTranscoder

func NewTranscoder(cacheDir string) *Transcoder

NewTranscoder creates a transcoder writing into cacheDir/audio.

func (*Transcoder) DecoderName

func (t *Transcoder) DecoderName() string

DecoderName returns the decoder binary in use, or "" when none is installed.

func (*Transcoder) SpeexAvailable

func (t *Transcoder) SpeexAvailable() bool

SpeexAvailable reports whether Speex assets can be served.

func (*Transcoder) SpeexToWAV

func (t *Transcoder) SpeexToWAV(data []byte) ([]byte, error)

SpeexToWAV decodes Ogg-Speex bytes to WAV, using the disk cache when warm.

Jump to

Keyboard shortcuts

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