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 ¶
- func StaticFS() fs.FS
- type Crumb
- type FilePage
- type GonePage
- type IndexEntry
- type IndexPage
- type Meta
- type PasswordPage
- type Renderer
- func (r *Renderer) File(w http.ResponseWriter, status int, data FilePage) error
- func (r *Renderer) Gone(w http.ResponseWriter, status int, data GonePage) error
- func (r *Renderer) Index(w http.ResponseWriter, status int, data IndexPage) error
- func (r *Renderer) Password(w http.ResponseWriter, status int, data PasswordPage) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
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 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 ¶
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 ¶
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) Password ¶
func (r *Renderer) Password(w http.ResponseWriter, status int, data PasswordPage) error
Password renders the unlock form.