share

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 11 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 share implements public, read-only links to individual notes.

A share is a capability, not a copy: a random token bound to a vault path. Whoever holds the link reads the *current* note, so an edit shows up immediately and a revoke takes effect immediately — the same "one URL, live content" model the workspace already has for its own deep links.

State lives in a single JSON file inside the vault, at `.vellum/shares.json`. That location is deliberate:

  • It survives a restart. vellum's OAuth tokens are in memory and die with the process by design; a link handed to somebody else must not.
  • It travels with the vault, which is backed up by copying a directory. No database, no second thing to restore.
  • It is unreachable from a note path. The vault refuses writes into dot-directories and the index skips them, so an agent holding an MCP token cannot publish a note by writing to this file or by setting some `share:` key in frontmatter — sharing only ever happens through the explicit calls in this package.

Index

Constants

View Source
const (
	// StateDir is the vault-relative directory holding vellum's own state.
	StateDir = ".vellum"

	// MinTTL and MaxTTL bound a caller-supplied lifetime. A zero TTL means
	// "until revoked" and is always allowed.
	MinTTL = time.Hour
	MaxTTL = 365 * 24 * time.Hour
)

Variables

View Source
var ErrInvalidTTL = errors.New("share lifetime must be between 1 hour and 365 days")

ErrInvalidTTL is returned for a lifetime outside [MinTTL, MaxTTL].

View Source
var TokenLen = base64.RawURLEncoding.EncodedLen(tokenBytes)

TokenLen is the length of a minted token, used to reject obvious garbage before it reaches the store.

Functions

func PlausibleToken

func PlausibleToken(s string) bool

PlausibleToken reports whether s could be a token vellum minted. It exists so the public endpoint can drop probe traffic early; a true result says nothing about the token existing.

Types

type Share

type Share struct {
	Token      string     `json:"token"`
	Path       string     `json:"path"`
	CreatedAt  time.Time  `json:"createdAt"`
	ExpiresAt  *time.Time `json:"expiresAt,omitempty"`
	Views      int        `json:"views"`
	LastViewAt *time.Time `json:"lastViewAt,omitempty"`
}

Share is one public link.

func (Share) Expired

func (s Share) Expired(now time.Time) bool

Expired reports whether the share has passed its expiry.

type Store

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

Store is the set of live shares, persisted to `.vellum/shares.json`. Safe for concurrent use.

func Open

func Open(vaultRoot string) (*Store, error)

Open loads (or starts) the share store for a vault root. It creates the `.vellum` directory, so call it only when sharing is enabled — an installation with sharing off should not grow a state directory.

func (*Store) Close

func (s *Store) Close() error

Close flushes pending view counts and stops the background writer.

func (*Store) Create

func (s *Store) Create(path string, ttl time.Duration) (Share, error)

Create mints the link for path, or refreshes the one it already has. Re-sharing a note keeps its existing token — the URL somebody was given stays valid — and only moves the expiry. A ttl of 0 means "until revoked".

func (*Store) ForPath

func (s *Store) ForPath(path string) (Share, bool)

ForPath returns the live share of a note, if it has one.

func (*Store) Get

func (s *Store) Get(token string) (Share, bool)

Get resolves a token. An expired share reports false, exactly like an unknown one — the caller must not be able to tell them apart.

func (*Store) Len

func (s *Store) Len() int

Len is the number of live shares.

func (*Store) List

func (s *Store) List() []Share

List returns every live share, newest first.

func (*Store) RecordView

func (s *Store) RecordView(token string)

RecordView counts a hit on a link. Cheap on purpose: the counter is kept in memory and written back by the flush loop.

func (*Store) Rename

func (s *Store) Rename(from, to string) bool

Rename follows a note to its new path, so moving or renaming a shared note does not break the link — the same promise move_note makes for backlinks. A share already sitting on the destination is replaced.

func (*Store) Revoke

func (s *Store) Revoke(token string) (Share, bool)

Revoke kills one link by token.

func (*Store) RevokePath

func (s *Store) RevokePath(path string) (Share, bool)

RevokePath kills the link of one note.

func (*Store) RevokePrefix

func (s *Store) RevokePrefix(dir string) []Share

RevokePrefix kills the links of every note inside a folder, for when the folder itself is deleted. Returns what it dropped.

Jump to

Keyboard shortcuts

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