transport

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangeEvent

type ChangeEvent struct {
	DocID string
	Path  string
	Type  string // "modified", "created", "deleted"
}

ChangeEvent represents a document modification on the device

type CloudTransport

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

CloudTransport implements document access via sync v3

func NewCloudTransport

func NewCloudTransport() *CloudTransport

func (*CloudTransport) Close

func (t *CloudTransport) Close() error

func (*CloudTransport) Connect

func (t *CloudTransport) Connect() error

func (*CloudTransport) DeleteDocument

func (t *CloudTransport) DeleteDocument(docID string) error

DeleteDocument removes a doc from the root index. Note: this is a hard delete (removes from root entirely). The CLI's `rm` command may want to do a soft delete by moving to trash via SetMetadata instead — that's a caller decision.

func (*CloudTransport) GetMetadata

func (t *CloudTransport) GetMetadata(docID string) (*model.Metadata, error)

GetMetadata downloads and parses a doc's .metadata blob

func (*CloudTransport) ListDocuments

func (t *CloudTransport) ListDocuments() ([]model.Document, error)

ListDocuments fetches docs — caches metadata so repeat calls are free. First call fetches root + per-doc index/metadata blobs (each cached on disk by content hash, so subsequent runs only re-fetch the mutable root).

func (*CloudTransport) Name

func (t *CloudTransport) Name() string

func (*CloudTransport) ReadFile

func (t *CloudTransport) ReadFile(docID, path string) (io.ReadCloser, error)

ReadFile downloads a file from the cloud blob tree

func (*CloudTransport) SetMetadata

func (t *CloudTransport) SetMetadata(docID string, m *model.Metadata) error

SetMetadata uploads .metadata blob and updates the doc + root indexes

func (*CloudTransport) SyncDoc

func (t *CloudTransport) SyncDoc(docID string) error

SyncDoc builds the doc index, uploads it, and updates the root index. Retries once on 412 (generation race) by re-fetching root and rebuilding.

func (*CloudTransport) WriteFile

func (t *CloudTransport) WriteFile(docID, path string, r io.Reader) error

WriteFile uploads a blob to cloud and tracks it for the doc index

type SSHOption

type SSHOption func(*SSHTransport)

SSHOption configures the SSH transport

func WithHost

func WithHost(host string) SSHOption

WithHost sets the SSH host (default: 10.11.99.1)

func WithKeyPath

func WithKeyPath(path string) SSHOption

WithKeyPath sets SSH key path

func WithPassword

func WithPassword(pw string) SSHOption

WithPassword sets password auth

type SSHTransport

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

SSHTransport implements DeviceTransport via SSH/SFTP

func NewSSHTransport

func NewSSHTransport(opts ...SSHOption) *SSHTransport

NewSSHTransport creates a new SSH transport

func (*SSHTransport) Close

func (t *SSHTransport) Close() error

Close tears down connections

func (*SSHTransport) Connect

func (t *SSHTransport) Connect() error

Connect establishes SSH + SFTP connections

func (*SSHTransport) DeleteDocument

func (t *SSHTransport) DeleteDocument(docID string) error

DeleteDocument removes all files for a document

func (*SSHTransport) GetMetadata

func (t *SSHTransport) GetMetadata(docID string) (*model.Metadata, error)

GetMetadata reads a document's .metadata JSON

func (*SSHTransport) ListDocuments

func (t *SSHTransport) ListDocuments() ([]model.Document, error)

ListDocuments reads all metadata in a single SSH command (~1s vs 10s+ for individual SFTP reads)

func (*SSHTransport) Name

func (t *SSHTransport) Name() string

func (*SSHTransport) ReadFile

func (t *SSHTransport) ReadFile(docID, relPath string) (io.ReadCloser, error)

ReadFile reads a file relative to a document's UUID space relPath examples:

"content"     -> {xochitl}/{uuid}.content (top-level doc file)
"pdf"         -> {xochitl}/{uuid}.pdf
"abc123.rm"   -> {xochitl}/{uuid}/abc123.rm (page file inside UUID dir)
"abc/def.json"-> {xochitl}/{uuid}/abc/def.json

func (*SSHTransport) RestartUI

func (t *SSHTransport) RestartUI() error

RestartUI restarts the xochitl service

func (*SSHTransport) RunCommand

func (t *SSHTransport) RunCommand(cmd string) (string, error)

RunCommand executes a command over SSH and returns stdout

func (*SSHTransport) RunCommandBytes

func (t *SSHTransport) RunCommandBytes(cmd string) ([]byte, error)

RunCommandBytes executes a command and returns raw stdout bytes

func (*SSHTransport) Screenshot

func (t *SSHTransport) Screenshot() (image.Image, error)

Screenshot captures the device screen via /proc/PID/mem

func (*SSHTransport) SetMetadata

func (t *SSHTransport) SetMetadata(docID string, m *model.Metadata) error

SetMetadata writes a document's .metadata JSON

func (*SSHTransport) WatchChanges

func (t *SSHTransport) WatchChanges(ctx context.Context) (<-chan ChangeEvent, error)

WatchChanges polls for file changes and emits events

func (*SSHTransport) WriteFile

func (t *SSHTransport) WriteFile(docID, relPath string, r io.Reader) error

WriteFile writes a file into a document's space top-level doc files (content, pdf, epub) → {uuid}.{relPath} page/subdir files (contain / or .rm) → {uuid}/{relPath}

func (*SSHTransport) WriteRawFile

func (t *SSHTransport) WriteRawFile(remotePath string, data []byte) error

WriteRawFile writes arbitrary bytes to an absolute path on the device

type Transport

type Transport interface {
	Connect() error
	Close() error
	Name() string

	// documents
	ListDocuments() ([]model.Document, error)
	ReadFile(docID, path string) (io.ReadCloser, error)
	WriteFile(docID, path string, r io.Reader) error
	DeleteDocument(docID string) error

	// metadata
	GetMetadata(docID string) (*model.Metadata, error)
	SetMetadata(docID string, m *model.Metadata) error
}

Transport is the single interface for device communication

func AutoDetect

func AutoDetect(opts ...SSHOption) (Transport, error)

AutoDetect tries SSH first, falls back to cloud

type Watchable

type Watchable interface {
	WatchChanges(ctx context.Context) (<-chan ChangeEvent, error)
}

Watchable is implemented by transports that support live change detection

Jump to

Keyboard shortcuts

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