Documentation
¶
Overview ¶
Package attach saves images pasted into the shared document next to the host's file, and uploads them again for peers who could not fetch them.
Image bytes travel through the server's blob store, encrypted; the room only carries small attachment messages. The host is the one peer that writes to disk, and it trusts nothing a peer claims: it checks every image against its content hash, and picks the file type from the bytes themselves.
Index ¶
Constants ¶
const ( // Dir is where attachments go, beside the shared file. Links in the // document point into it. Dir = "assets" // MaxBytes caps one attachment. MaxBytes = 10 << 20 // MaxTotalBytes and MaxCount cap what one session writes to disk, like // the server caps what a room stores. MaxTotalBytes = 100 << 20 MaxCount = 500 )
const ( ReasonTooLarge = "too_large" ReasonType = "type" ReasonQuota = "quota" ReasonInvalid = "invalid" )
Reasons sent in Rejected messages.
Variables ¶
var ErrLinkedOut = errors.New("it links out of the shared file's folder")
ErrLinkedOut means Dir is a link out of the shared file's directory, which images are never saved through.
var ErrNotInRoom = errors.New("the room no longer has the image, or it does not match its name")
ErrNotInRoom means the room no longer holds an image the document refers to.
Functions ¶
This section is empty.
Types ¶
type Attachments ¶
type Attachments struct {
// contains filtered or unexported fields
}
Attachments handles the attachment messages of one session, one at a time in the background, so the room's read loop never waits on the network or the disk.
func New ¶
func New(opts Options) *Attachments
func (*Attachments) AllowLocalChanges ¶
func (a *Attachments) AllowLocalChanges(base, next string)
AllowLocalChanges authorizes only references introduced by the local edit. References already persisted from peer edits do not gain permission merely because the host edits another part of the file.
func (*Attachments) AllowLocalDocument ¶
func (a *Attachments) AllowLocalDocument(document string)
AllowLocalDocument authorizes references in a file read from the host's disk. Callers must not pass the peer-editable live document here.
func (*Attachments) Close ¶
func (a *Attachments) Close()
Close stops handling messages, abandoning any in flight.
func (*Attachments) Handle ¶
func (a *Attachments) Handle(m protocol.Attachment)
Handle queues an attachment message from the room. It never blocks.
func (*Attachments) Restore ¶ added in v0.2.0
Restore saves the images that document refers to and that are not beside the file yet, fetched from the room. It is for a kept room, whose host was away while guests pasted them. It returns how many it wrote and one error for each image it could not save, which the caller reports: a missing image must not stop the text from being written.
type Options ¶
type Options struct {
// File is the shared file; attachments go to Dir beside it.
File string
// Root is File's directory, opened when the session started. Attachments
// are read and written only through it, so swapping the directory or Dir
// for a link later cannot send them elsewhere. Without it, New opens
// File's directory, and Close closes it.
Root *os.Root
// InitialDocument is the host's local file before peers can edit the room.
InitialDocument string
// Server is the base URL of the pedit server, and Room the room id.
Server string
Room string
// Header is sent with every request to the server, such as the Cloudflare
// Access token. It must not hold the host token.
Header http.Header
HTTPClient *http.Client
Keys *protocol.BlobKeys
// Send sends an attachment message to the room.
Send func(protocol.Attachment) error
// OnSaved is called with the path, relative to File, of each image
// written to disk.
OnSaved func(path string)
// OnSaveError is called when an image could not be written beside the
// file, and the room is told it was not saved. It defaults to OnError.
OnSaveError func(error)
OnError func(error)
}