viewer

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package viewer renders the HTML a visitor sees and serves the viewer's own static assets. Templates and CSS are embedded in the binary so a vrok share has no runtime dependency on the filesystem it was started from.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StaticFS

func StaticFS() fs.FS

StaticFS returns the embedded static assets rooted at the directory that holds them, ready to hand to http.FileServer.

Types

type Crumb

type Crumb struct {
	Name string
	URL  string
}

Crumb is one breadcrumb link.

type FilePage

type FilePage struct {
	Meta
	Name        string
	Icon        string
	SizeText    string
	DownloadURL string
	Breadcrumbs []Crumb
	// SHA256 is the file's fingerprint as hex, once it has been worked out.
	SHA256 string
	// ChecksumPending is true while the fingerprint is still being worked
	// out in the background.
	ChecksumPending bool
	// Preview is a trusted fragment produced by internal/preview.
	Preview template.HTML
}

FilePage presents a single file with its rendered preview.

type GonePage

type GonePage struct {
	Meta
	Icon    string
	Heading string
	Message string
}

GonePage presents a terminal state: not found, expired or used up.

type IndexEntry

type IndexEntry struct {
	Name        string
	URL         string
	DownloadURL string
	Icon        string
	SizeText    string
	Modified    string
	IsDir       bool
}

IndexEntry is one row of a listing.

type IndexPage

type IndexPage struct {
	Meta
	Heading     string
	Current     string
	Breadcrumbs []Crumb
	Entries     []IndexEntry
	// Total is how many entries the directory actually holds, and Truncated
	// reports that Entries is only the first part of it. A visitor is told
	// rather than left to assume the folder is smaller than it is.
	Total     int
	Truncated bool
	// ArchiveURL downloads everything listed, and everything under it, as
	// one zip. Empty when there is nothing to download.
	ArchiveURL string
}

IndexPage presents a directory or a multi-file share.

type Meta

type Meta struct {
	// Title is the browser tab title.
	Title string
	// StaticBase is the URL prefix the stylesheet is served from.
	StaticBase string
	// HomeURL points at the root of this share.
	HomeURL string
	// Expires is a pre-formatted countdown, or empty when there is no TTL.
	Expires string
	// Downloads is a pre-formatted allowance, or empty when unlimited.
	Downloads string
}

Meta is the chrome shared by every page. Each page struct embeds it, which is what lets layout.html render the header without knowing the page type.

type PasswordPage

type PasswordPage struct {
	Meta
	ActionURL string
	Error     string
}

PasswordPage presents the unlock form.

type Renderer

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

Renderer renders the viewer pages. It is safe for concurrent use: templates are parsed once at construction and never mutated afterwards.

func New

func New() (*Renderer, error)

New parses the embedded templates and returns a Renderer. It fails only if the embedded assets are corrupt, which means a broken build rather than a runtime condition.

func (*Renderer) File

func (r *Renderer) File(w http.ResponseWriter, status int, data FilePage) error

File renders the single-file page.

func (*Renderer) Gone

func (r *Renderer) Gone(w http.ResponseWriter, status int, data GonePage) error

Gone renders a terminal state page.

func (*Renderer) Index

func (r *Renderer) Index(w http.ResponseWriter, status int, data IndexPage) error

Index renders a directory or multi-file listing.

func (*Renderer) Password

func (r *Renderer) Password(w http.ResponseWriter, status int, data PasswordPage) error

Password renders the unlock form.

Jump to

Keyboard shortcuts

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