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
- Variables
- func PlausibleToken(s string) bool
- type Share
- type Store
- func (s *Store) Close() error
- func (s *Store) Create(path string, ttl time.Duration) (Share, error)
- func (s *Store) ForPath(path string) (Share, bool)
- func (s *Store) Get(token string) (Share, bool)
- func (s *Store) Len() int
- func (s *Store) List() []Share
- func (s *Store) RecordView(token string)
- func (s *Store) Rename(from, to string) bool
- func (s *Store) Revoke(token string) (Share, bool)
- func (s *Store) RevokePath(path string) (Share, bool)
- func (s *Store) RevokePrefix(dir string) []Share
Constants ¶
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 ¶
var ErrInvalidTTL = errors.New("share lifetime must be between 1 hour and 365 days")
ErrInvalidTTL is returned for a lifetime outside [MinTTL, MaxTTL].
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 ¶
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 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 ¶
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) Create ¶
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) Get ¶
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) RecordView ¶
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 ¶
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) RevokePath ¶
RevokePath kills the link of one note.
func (*Store) RevokePrefix ¶
RevokePrefix kills the links of every note inside a folder, for when the folder itself is deleted. Returns what it dropped.