share

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModeLive     = "live"
	ModeSnapshot = "snapshot"
)
View Source
const (
	DefaultAdminAddr  = "127.0.0.1:39125"
	DefaultPublicPort = 39124
)
View Source
const DefaultTokenBytes = 8

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

func CleanupSnapshot

func CleanupSnapshot(snapshotRoot string) error

func CodeLanguageForName

func CodeLanguageForName(name string) string

func CreateSnapshot

func CreateSnapshot(paths StatePaths, shareID string, sourcePath string, isDir bool) (string, error)

func EnsurePrivateFile

func EnsurePrivateFile(path string) error

func ExternalShareBaseURL

func ExternalShareBaseURL(publicPort int) (string, error)

func GenerateShareID

func GenerateShareID() (string, error)

func LoadOrCreateSecret

func LoadOrCreateSecret(path string) ([]byte, error)

func LocalTailscaleIPv4

func LocalTailscaleIPv4() (string, error)

func LocalTailscaleMagicDNS

func LocalTailscaleMagicDNS() (string, error)

func RenderDirectoryPage

func RenderDirectoryPage(title string, entries []DirEntry, breadcrumbs []Breadcrumb) (string, error)

func RenderMarkdownDocument

func RenderMarkdownDocument(source []byte) (string, map[string]any, error)

func RenderMarkdownPreviewPage

func RenderMarkdownPreviewPage(
	title string,
	rendered string,
	rawURL string,
	breadcrumbs []Breadcrumb,
	meta map[string]any,
) (string, error)

func RenderPreviewPage

func RenderPreviewPage(baseName string, kind PreviewKind, rawURL string, breadcrumbs []Breadcrumb) string

func ResolveScopedPath

func ResolveScopedPath(root string, rel string) (string, error)
func RewriteMarkdownLinks(rendered string, currentRel string, resolver markdownLinkResolver) (string, error)

func RewriteServePreviewImageSources

func RewriteServePreviewImageSources(rendered string, externalBase string) (string, error)

func ShareToken

func ShareToken(secret []byte, shareID string, tokenBytes int) string

func ValidateMode

func ValidateMode(mode string) string

func ValidateShareToken

func ValidateShareToken(secret []byte, shareID string, token string, tokenBytes int) bool

Types

type Breadcrumb struct {
	Name string
	URL  string
}

Breadcrumb represents a single segment in the navigation path.

type Client

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

func NewClient

func NewClient(adminAddr string) *Client

func (*Client) CreateShare

func (c *Client) CreateShare(req CreateShareRequest) (ShareResponse, error)

func (*Client) GetShare

func (c *Client) GetShare(id string) (ShareResponse, error)

func (*Client) Health

func (c *Client) Health() error

func (*Client) ListShares

func (c *Client) ListShares() ([]ShareResponse, error)

func (*Client) RenewShare

func (c *Client) RenewShare(id string, expiresIn time.Duration) (ShareResponse, error)

func (*Client) RevokeShare

func (c *Client) RevokeShare(id string) error

type CreateShareRequest

type CreateShareRequest struct {
	Path             string `json:"path"`
	Mode             string `json:"mode"`
	ExpiresInSeconds int64  `json:"expires_in_seconds"`
}

type Daemon

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

func NewDaemon

func NewDaemon(cfg DaemonConfig) (*Daemon, error)

func (*Daemon) Close

func (d *Daemon) Close() error

func (*Daemon) ExternalBaseURL

func (d *Daemon) ExternalBaseURL() string

func (*Daemon) PublicBaseURL

func (d *Daemon) PublicBaseURL() string

func (*Daemon) Run

func (d *Daemon) Run(ctx context.Context) error

type DaemonConfig

type DaemonConfig struct {
	Paths       StatePaths
	AdminAddr   string
	PublicPort  int
	TokenBytes  int
	ExternalURL string
}

type DirEntry

type DirEntry struct {
	Name       string
	IsDir      bool
	Size       int64
	ModTime    time.Time
	PreviewURL string
	RawURL     string
	CanCopy    bool
}

type MarkdownDirectoryShareAnalysis

type MarkdownDirectoryShareAnalysis struct {
	NeedsDirectoryShare bool
	HasEscapingTargets  bool
}

func AnalyzeMarkdownForDirectoryShare

func AnalyzeMarkdownForDirectoryShare(source []byte) (MarkdownDirectoryShareAnalysis, error)

type MarkdownPreviewField

type MarkdownPreviewField struct {
	Label string
	Value string
}

type MarkdownPreviewTag

type MarkdownPreviewTag struct {
	Label string
}

type PreviewKind

type PreviewKind string
const (
	PreviewCode     PreviewKind = "code"
	PreviewDiff     PreviewKind = "diff"
	PreviewMarkdown PreviewKind = "markdown"
	PreviewHTML     PreviewKind = "html"
	PreviewCSV      PreviewKind = "csv"
	PreviewPDF      PreviewKind = "pdf"
	PreviewImage    PreviewKind = "image"
	PreviewAudio    PreviewKind = "audio"
	PreviewVideo    PreviewKind = "video"
	PreviewBinary   PreviewKind = "binary"
)

func ClassifyPreviewKind

func ClassifyPreviewKind(name string) PreviewKind

type RenewShareRequest

type RenewShareRequest struct {
	ExpiresInSeconds int64 `json:"expires_in_seconds"`
}

type Share

type Share struct {
	ID           string
	SourcePath   string
	IsDir        bool
	Mode         string
	SnapshotRoot string
	CreatedAt    time.Time
	ExpiresAt    time.Time
	RevokedAt    *time.Time
	LastServedAt *time.Time
}

func (Share) IsActive

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

func (Share) ToResponse

func (s Share) ToResponse(baseURL string, token string) ShareResponse

type ShareResponse

type ShareResponse struct {
	ID        string    `json:"id"`
	Path      string    `json:"path"`
	IsDir     bool      `json:"is_dir"`
	Mode      string    `json:"mode"`
	URL       string    `json:"url"`
	CreatedAt time.Time `json:"created_at"`
	ExpiresAt time.Time `json:"expires_at"`
	Revoked   bool      `json:"revoked"`
}

type StatePaths

type StatePaths struct {
	BaseDir      string
	DBPath       string
	SecretPath   string
	SnapshotsDir string
	LogsDir      string
}

func DefaultStatePaths

func DefaultStatePaths() (StatePaths, error)

func (StatePaths) Ensure

func (p StatePaths) Ensure() error

type Store

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

func OpenStore

func OpenStore(dbPath string) (*Store, error)

func (*Store) Close

func (s *Store) Close() error

func (*Store) CreateShare

func (s *Store) CreateShare(share Share) error

func (*Store) ExpiredShares

func (s *Store) ExpiredShares(now time.Time) ([]Share, error)

func (*Store) GetShare

func (s *Store) GetShare(id string) (Share, error)

func (*Store) ListShares

func (s *Store) ListShares(activeOnly bool) ([]Share, error)

func (*Store) RenewShare

func (s *Store) RenewShare(id string, expiresAt time.Time) error

func (*Store) RevokeShare

func (s *Store) RevokeShare(id string) error

func (*Store) RevokeSharesByPath

func (s *Store) RevokeSharesByPath(absPath string) (int64, error)

func (*Store) TouchLastServed

func (s *Store) TouchLastServed(id string, ts time.Time) error

Jump to

Keyboard shortcuts

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