content

package
v0.1.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 18 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 content owns the public directory scanner, manifest and safe file access. Public content is untrusted input and is read through os.Root.

Index

Constants

View Source
const (
	CacheTTL             = 30 * time.Second
	FirstScanWait        = 3 * time.Second
	MaxManifestPage      = 64 << 10
	MaxManifestLimit     = 200
	DefaultManifestLimit = 100
)

Variables

View Source
var ErrScanInProgress = errors.New("content: initial scan in progress")

Functions

func EnsureLayout

func EnsureLayout(dataDir string) error

Types

type Entry

type Entry struct {
	Path           string `json:"path"`
	Size           int64  `json:"size"`
	ModifiedUnixMS int64  `json:"modified_unix_ms"`
	SHA256         string `json:"sha256"`
}

type Limits

type Limits struct {
	MaxFileBytes    int64
	MaxPostsBytes   int64
	MaxProfileBytes int64
}

type Manifest

type Manifest struct {
	Version           int     `json:"version"`
	PeerID            string  `json:"peer_id"`
	GeneratedAtUnixMS int64   `json:"generated_at_unix_ms"`
	Entries           []Entry `json:"entries"`
	Total             int     `json:"total"`
}

type Skip

type Skip struct {
	Path   string `json:"path"`
	Reason string `json:"reason"`
}

type Snapshot

type Snapshot struct {
	PeerID      string
	GeneratedAt time.Time
	Entries     []Entry
	Total       int
	Warnings    []string
	Skipped     []Skip
	// FriendsSyncedAt is the mtime of friends.json, i.e. when its contents last
	// changed. WriteFriends skips unchanged writes, so this is not the last time
	// friends were synced.
	FriendsSyncedAt time.Time
}

func (*Snapshot) Page

func (snap *Snapshot) Page(offset, limit int) Manifest

Page returns a deterministic, size-bounded manifest page. The total is the full manifest count, not the page count.

type Store

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

func New

func New(dataDir, peerID string, limits Limits) (*Store, error)

func (*Store) Close

func (s *Store) Close() error

func (*Store) File

func (s *Store) File(rel string) (*os.File, fs.FileInfo, error)

func (*Store) Invalidate

func (s *Store) Invalidate()

func (*Store) Refresh

func (s *Store) Refresh(ctx context.Context) (*Snapshot, error)

Refresh forces a new scan and waits for it. /published uses this so a user never sees a cached list after adding a file.

func (*Store) Snapshot

func (s *Store) Snapshot(ctx context.Context) (*Snapshot, error)

Snapshot returns the cached manifest inside the TTL. After the TTL it waits for one singleflight scan, bounded by FirstScanWait and ctx. If the bound is reached it serves the previous snapshot rather than an arbitrarily old one.

func (*Store) Warnings

func (s *Store) Warnings() []string

func (*Store) WriteFriends

func (s *Store) WriteFriends(data []byte) (bool, error)

WriteFriends atomically replaces friends.json only when bytes differ. It is the only writer for the generated file.

Jump to

Keyboard shortcuts

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