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 ¶
This section is empty.
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.
type Options ¶
type Options struct {
// File is the shared file; attachments go to Dir beside it.
File string
// 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)
OnError func(error)
}