pad

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 21 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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

View Source
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.

View Source
var ErrNoRevisions = errors.New("pad has no revisions")

ErrNoRevisions is returned when a pad row exists but no revision is stored for it.

View Source
var ErrPadGone = errors.New("pad no longer exists")

ErrPadGone is returned by Refresh when the pad was deleted, for instance by another instance.

View Source
var ErrRevisionAlreadySaved = errors.New("saved revision already exists")

ErrRevisionAlreadySaved is returned for a revision that is saved already.

Functions

func CleanText

func CleanText(context string) *string

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

func IsLegacyPadId(padID string) bool

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

func IsValidPadId(padID string) bool

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 NewPad

func NewPad(id string, db db.DataStore, hook *hooks.Hook) Pad

func (*Pad) AddSavedRevision added in v0.0.4

func (p *Pad) AddSavedRevision(author string) error

func (*Pad) AddSavedRevisionAt added in v0.7.0

func (p *Pad) AddSavedRevisionAt(rev int, author string, label *string) error

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 (p *Pad) AppendChatMessage(authorId *string, timestamp int64, text string) (*int, error)

func (*Pad) AppendRevision

func (p *Pad) AppendRevision(cs string, authorId *string) (*int, error)

func (*Pad) Check added in v0.0.2

func (p *Pad) Check() error

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 (p *Pad) GetAllAuthors() []string

func (*Pad) GetAllChatters added in v0.0.4

func (p *Pad) GetAllChatters() (*[]string, error)

func (*Pad) GetChatMessages added in v0.0.2

func (p *Pad) GetChatMessages(start int, end int) (*[]db2.ChatMessageDBWithDisplayName, error)

func (*Pad) GetInternalRevisionAText

func (p *Pad) GetInternalRevisionAText(targetRev int) *apool.AText

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) GetRevisionAuthor

func (p *Pad) GetRevisionAuthor(revNum int) (*string, error)

func (*Pad) GetRevisionChangeset added in v0.0.2

func (p *Pad) GetRevisionChangeset(revNum int) (*string, error)

func (*Pad) GetRevisionDate

func (p *Pad) GetRevisionDate(rev int) (*int64, error)

func (*Pad) GetRevisions added in v0.0.2

func (p *Pad) GetRevisions(start int, end int) (*[]db2.PadSingleRevision, error)

func (*Pad) Init

func (p *Pad) Init(text *string, author *string, authorManager *author.Manager) error

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

func (p *Pad) PadSettingsJSON() string

PadSettingsJSON is the stored pad-wide settings JSON ("" for defaults), as exported in .etherpad files.

func (*Pad) Refresh added in v0.7.0

func (p *Pad) Refresh() error

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) Remove

func (p *Pad) Remove() error

func (*Pad) RemoveAllChats

func (p *Pad) RemoveAllChats() error

func (*Pad) RemoveAllSavedRevisions

func (p *Pad) RemoveAllSavedRevisions() error

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

func (p *Pad) RestoreRevision(rev int, authorId *string) (*int, error)

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) Save added in v0.0.2

func (p *Pad) Save() error

func (*Pad) SetPadSettings added in v0.7.0

func (p *Pad) SetPadSettings(change map[string]any, d PadSettingsDefaults) (map[string]any, error)

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

func (p *Pad) SetPublicStatus(public bool) error

SetPublicStatus changes the public status of a group pad.

func (*Pad) SetText

func (p *Pad) SetText(newText string, authorId *string) error

func (*Pad) SpliceText

func (p *Pad) SpliceText(start int, ndel int, ins string, authorId *string) error

func (*Pad) Text

func (p *Pad) Text() string

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.

Jump to

Keyboard shortcuts

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