Documentation
¶
Index ¶
- Constants
- Variables
- func CleanText(context string) *string
- func IsLegacyPadId(padID string) bool
- func IsValidPadId(padID string) bool
- func NormalizePadSettings(raw map[string]any, d PadSettingsDefaults) map[string]any
- type Pad
- func (p *Pad) AddSavedRevision(author string) error
- func (p *Pad) AddSavedRevisionAt(rev int, author string, label *string) error
- func (p *Pad) AppendChatMessage(authorId *string, timestamp int64, text string) (*int, error)
- func (p *Pad) AppendRevision(cs string, authorId *string) (*int, error)
- func (p *Pad) Check() error
- func (p *Pad) GetAllAuthors() []string
- func (p *Pad) GetAllChatters() (*[]string, error)
- func (p *Pad) GetChatMessages(start int, end int) (*[]db2.ChatMessageDBWithDisplayName, error)
- func (p *Pad) GetInternalRevisionAText(targetRev int) *apool.AText
- func (p *Pad) GetPadSettings(d PadSettingsDefaults) map[string]any
- func (p *Pad) GetRevision(revNumber int) (*db2.PadSingleRevision, error)
- func (p *Pad) GetRevisionAuthor(revNum int) (*string, error)
- func (p *Pad) GetRevisionChangeset(revNum int) (*string, error)
- func (p *Pad) GetRevisionDate(rev int) (*int64, error)
- func (p *Pad) GetRevisions(start int, end int) (*[]db2.PadSingleRevision, error)
- func (p *Pad) Init(text *string, author *string, authorManager *author.Manager) error
- func (p *Pad) MatchesVersion(v *dbstore.PadVersion) bool
- func (p *Pad) PadSettingsJSON() string
- func (p *Pad) Refresh() error
- func (p *Pad) Remove() error
- func (p *Pad) RemoveAllChats() error
- func (p *Pad) RemoveAllSavedRevisions() error
- func (p *Pad) ReplaceContent(target apool.AText, srcPool *apool.APool, authorId *string) (*int, error)
- func (p *Pad) RestoreRevision(rev int, authorId *string) (*int, error)
- func (p *Pad) RevisionDeltas(from, to int) ([]dbstore.RevisionDelta, error)
- func (p *Pad) Save() error
- func (p *Pad) SetPadSettings(change map[string]any, d PadSettingsDefaults) (map[string]any, error)
- func (p *Pad) SetPublicStatus(public bool) error
- func (p *Pad) SetText(newText string, authorId *string) error
- func (p *Pad) SpliceText(start int, ndel int, ins string, authorId *string) error
- func (p *Pad) Text() string
- type PadSettingsDefaults
Constants ¶
const SystemAuthorId = "a.etherpad-system"
SystemAuthorId is the stable author id used to attribute inserts coming from internal callers (HTTP API SetText/AppendText with no authorId, plugins, server-side import flows). Without ANY author attribute, AText.Text and AText.Attribs drift out of sync — clients then fail setDocAText reconciliation in ace2_inner.ts when loading the pad. Using a fixed system author keeps the AText well-formed without requiring every plugin to allocate its own author up-front. Upstream #7773.
Variables ¶
var ErrInsertWithoutAuthor = errors.New("insert op without an author attribute")
ErrInsertWithoutAuthor is returned by AppendRevision for a changeset with an insert that carries no author attribute.
var ErrNoRevisions = errors.New("pad has no revisions")
ErrNoRevisions is returned when a pad row exists but no revision is stored for it.
var ErrPadGone = errors.New("pad no longer exists")
ErrPadGone is returned by Refresh when the pad was deleted, for instance by another instance.
var ErrRevisionAlreadySaved = errors.New("saved revision already exists")
ErrRevisionAlreadySaved is returned for a revision that is saved already.
Functions ¶
func CleanText ¶
CleanText normalises line endings and expands tabs. Everything else is kept as it is, non-breaking spaces (U+00A0) included.
func IsLegacyPadId ¶ added in v0.7.0
IsLegacyPadId reports whether padID was a valid pad id before ":" was refused. A pad with such an id can still be opened, edited and checked; it just cannot be created any more.
func IsValidPadId ¶ added in v0.0.2
IsValidPadId reports whether padID may name a new pad.
- "." and ".." match the pattern but are refused: a browser normalises "/p/." to "/p/" and "/p/.." to "/", so such a pad could never be opened or exported.
- ":" is refused like in etherpad-lite (GHSA-wg58-mhwv-35pq), where it is the key delimiter of the database. etherpad-go keys pads by column, so the attack does not apply here, but the rule keeps pad ids portable between the two servers. Pads that already carry a ":" stay usable, see IsLegacyPadId.
func NormalizePadSettings ¶ added in v0.7.0
func NormalizePadSettings(raw map[string]any, d PadSettingsDefaults) map[string]any
NormalizePadSettings returns the complete, valid pad settings for raw, filling in defaults. It is etherpad-lite's Pad.normalizePadSettings.
Types ¶
type Pad ¶
type Pad struct {
Id string
ChatHead int
Head int
PublicStatus bool
DocumentType string
SavedRevisions []revision.SavedRevision
Pool apool.APool
AText apool.AText
ReadonlyId *string
UpdatedAt *time.Time
CreatedAt time.Time
// contains filtered or unexported fields
}
func (*Pad) AddSavedRevision ¶ added in v0.0.4
func (*Pad) AddSavedRevisionAt ¶ added in v0.7.0
AddSavedRevisionAt saves revision rev (at most head) with a label; without one it is "Revision <rev>".
func (*Pad) AppendChatMessage ¶ added in v0.0.2
func (*Pad) AppendRevision ¶
func (*Pad) Check ¶ added in v0.0.2
Check verifies the pad's stored data. Errors name the pad, and the revision or chat message at fault ("(pad foo revision 3)"), so an operator reading the log knows where to look.
func (*Pad) GetAllAuthors ¶
func (*Pad) GetAllChatters ¶ added in v0.0.4
func (*Pad) GetChatMessages ¶ added in v0.0.2
func (*Pad) GetInternalRevisionAText ¶
func (*Pad) GetPadSettings ¶ added in v0.7.0
func (p *Pad) GetPadSettings(d PadSettingsDefaults) map[string]any
GetPadSettings returns the pad's normalised pad-wide settings.
func (*Pad) GetRevision ¶
func (p *Pad) GetRevision(revNumber int) (*db2.PadSingleRevision, error)
func (*Pad) GetRevisionChangeset ¶ added in v0.0.2
func (*Pad) GetRevisions ¶ added in v0.0.2
func (*Pad) MatchesVersion ¶ added in v0.7.0
func (p *Pad) MatchesVersion(v *dbstore.PadVersion) bool
MatchesVersion reports whether the pad reflects the stored version v: same head, no newer chat message and the same metadata.
func (*Pad) PadSettingsJSON ¶ added in v0.7.0
PadSettingsJSON is the stored pad-wide settings JSON ("" for defaults), as exported in .etherpad files.
func (*Pad) Refresh ¶ added in v0.7.0
Refresh brings the pad up to the state stored in the database. Callers hold the pad's write lock. On error the pad is unchanged.
func (*Pad) RemoveAllChats ¶
func (*Pad) RemoveAllSavedRevisions ¶
func (*Pad) ReplaceContent ¶ added in v0.7.0
func (p *Pad) ReplaceContent(target apool.AText, srcPool *apool.APool, authorId *string) (*int, error)
ReplaceContent appends one revision that makes the pad's content target, whose attribute numbers refer to srcPool (the pad's own or another pad's pool): text, formatting and authorship. Runs without an author go to authorId, or to the system author.
func (*Pad) RestoreRevision ¶ added in v0.7.0
RestoreRevision appends a revision that makes the pad's content what it was at rev: text, formatting and authorship. Runs without an author (text stored before every insert had to carry one) are attributed to authorId, or to the system author when no author is given.
func (*Pad) RevisionDeltas ¶ added in v0.7.0
func (p *Pad) RevisionDeltas(from, to int) ([]dbstore.RevisionDelta, error)
RevisionDeltas returns the stored changesets of revisions from..to.
func (*Pad) SetPadSettings ¶ added in v0.7.0
SetPadSettings merges change into the current settings (the view object key by key), normalises and stores the result. The caller holds the pad's write lock. The pad in memory changes only after the store succeeded.
func (*Pad) SetPublicStatus ¶ added in v0.7.0
SetPublicStatus changes the public status of a group pad.
func (*Pad) SpliceText ¶
type PadSettingsDefaults ¶ added in v0.7.0
type PadSettingsDefaults struct {
ShowChat bool
ShowLineNumbers bool
FadeInactiveAuthorColors bool
EnablePluginPadOptions bool
// Warn receives a message for every dropped plugin key; may be nil.
Warn func(msg string)
}
PadSettingsDefaults are the server settings the normalisation falls back to.
func DefaultsFromSettings ¶ added in v0.7.0
func DefaultsFromSettings(s *settings.Settings) PadSettingsDefaults
DefaultsFromSettings builds PadSettingsDefaults from the server settings.