filesystem

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package filesystem contains shared manifest and route helpers for file browser plugins backed by different remote filesystem protocols.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectMIME added in v0.1.1

func DetectMIME(p string, buf []byte) string

DetectMIME resolves a preview MIME, preferring the extension type and sniffing leading bytes when it's unknown. Never returns "" (unknown → octet-stream).

func FilesTab

func FilesTab(prefix string, opts ...FilesOption) plugin.Panel

func IsText added in v0.1.1

func IsText(mimeType string, buf []byte) bool

IsText reports whether a preview buffer should be served as editable text.

func MimeFor added in v0.1.1

func MimeFor(p string) string

MimeFor returns the MIME type for a path by file extension, or "" if unknown.

func Routes

func Routes(prefix, protocol string) []plugin.Route

func SniffStream added in v0.1.1

func SniffStream(r io.ReadCloser) (string, io.ReadCloser)

SniffStream is the streaming counterpart to DetectMIME: it peeks a stream's leading bytes for the MIME and returns a reader that replays them so the body streams whole. Never returns "".

func Streams added in v0.1.1

func Streams(_ string) []plugin.Stream

Types

type Chmodder

type Chmodder interface {
	Chmod(ctx context.Context, p string, mode fs.FileMode) error
}

Chmodder changes a path's permission bits.

type Client

type Client interface {
	Home(ctx context.Context) (string, error)
	ReadDir(ctx context.Context, p string) ([]os.FileInfo, error)
	Stat(ctx context.Context, p string) (os.FileInfo, error)
	Open(ctx context.Context, p string) (io.ReadCloser, error)
	Write(ctx context.Context, p string, r io.Reader) error
	Mkdir(ctx context.Context, p string) error
	Rename(ctx context.Context, from, to string) error
	Remove(ctx context.Context, p string, isDir bool) error
}

type Copier

type Copier interface {
	Copy(ctx context.Context, src, dst string) error
}

Copier duplicates a path within the backend.

type DirPager added in v0.1.1

type DirPager interface {
	ReadDirPage(ctx context.Context, p string, cursor string, limit int) ([]os.FileInfo, string, error)
}

DirPager is an optional Client capability for backends whose listings are natively cursor-paged and potentially unbounded (object stores). Implementing it makes the browser fetch one bounded page at a time instead of draining a directory through ReadDir. The returned cursor is opaque and empty when the listing is exhausted; entries are ordered within a page only.

type ErrorMapper

type ErrorMapper interface {
	MapError(error) error
}

type FileContent

type FileContent struct {
	Path      string `json:"path"`
	MIME      string `json:"mime,omitempty"`
	Encoding  string `json:"encoding,omitempty"`
	Content   string `json:"content,omitempty"`
	Size      int64  `json:"size,omitempty"`
	Truncated bool   `json:"truncated,omitempty"`
}

type FileEntry

type FileEntry struct {
	Name    string    `json:"name"`
	Path    string    `json:"path"`
	IsDir   bool      `json:"isDir"`
	Size    int64     `json:"size,omitempty"`
	MIME    string    `json:"mime,omitempty"`
	ModTime time.Time `json:"modTime,omitzero"`
	Mode    string    `json:"mode,omitempty"`
	Symlink string    `json:"symlink,omitempty"`
}

type FilePage

type FilePage struct {
	Items      []FileEntry `json:"items"`
	NextCursor string      `json:"nextCursor"`
	Total      *int        `json:"total,omitempty"`
	Path       string      `json:"path"`
	Truncated  bool        `json:"truncated,omitempty"`
}

FilePage is one slice of a directory listing. Total is omitted for backends paged by DirPager, where the directory size is unknown without draining it; Truncated then tells the browser more entries remain behind NextCursor.

type FilesOption

type FilesOption func(*plugin.FileBrowserConfig)

FilesOption opts a FilesTab into optional filesystem operations a backend supports.

func WithArchive

func WithArchive(prefix string) FilesOption

func WithChmod

func WithChmod(prefix string) FilesOption

func WithCopy

func WithCopy(prefix string) FilesOption

func WithMove

func WithMove(prefix string) FilesOption

type RangeOpener

type RangeOpener interface {
	OpenRange(ctx context.Context, p string, offset, length int64) (io.ReadCloser, error)
}

RangeOpener is an optional Client capability for backends that read from an offset but cannot seek. length <= 0 means to EOF.

type Seekable

type Seekable interface {
	OpenSeeker(ctx context.Context, p string) (io.ReadSeekCloser, error)
}

Seekable is an optional Client capability: a seekable handle enables full HTTP Range support for downloads/previews.

type Session

type Session interface {
	Filesystem() (Client, error)
}

Jump to

Keyboard shortcuts

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