note

package
v0.0.0-...-a7c217f Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: AGPL-3.0 Imports: 37 Imported by: 6

Documentation

Overview

Package note is the glue between the prosemirror models, the VFS, redis, the hub for realtime, etc.

Index

Constants

View Source
const MaxImageWeight = 100 * 1024 * 1024

MaxImageWeight is the maximal weight (in bytes) for an image.

View Source
const MaxMarkdownSize = 2 * 1024 * 1024

MaxMarkdownSize is the maximal size of a markdown that can be parsed.

View Source
const MaxWidth = 768

MaxWidth is the maximal width of an image for a note. If larger, the image will be resized.

Variables

View Source
var (
	// ErrInvalidSchema is used when the schema cannot be read by prosemirror.
	ErrInvalidSchema = errors.New("Invalid schema for prosemirror")
	// ErrInvalidFile is used when a file doesn't have the metadata to be used
	// as a note.
	ErrInvalidFile = errors.New("Invalid file, not a note")
	// ErrNoSteps is used when steps are expected, but there are none.
	ErrNoSteps = errors.New("No steps")
	// ErrInvalidSteps is used when prosemirror can't instantiate the steps.
	ErrInvalidSteps = errors.New("Invalid steps")
	// ErrCannotApply is used when trying to apply some steps, but it fails
	// because of a conflict. The client can try to rebase the steps.
	ErrCannotApply = errors.New("Cannot apply the steps")
	// ErrTooOld is used when the steps just after the given revision are no
	// longer available.
	ErrTooOld = errors.New("The revision is too old")
	// ErrMissingSessionID is used when a telepointer has no identifier.
	ErrMissingSessionID = errors.New("The session id is missing")
)

Functions

func ApplySteps

func ApplySteps(inst *instance.Instance, file *vfs.FileDoc, lastVersion string, steps []Step) (*vfs.FileDoc, error)

ApplySteps takes a note and some steps, and tries to apply them. It is an all or nothing change: if there is one error, the note won't be changed.

func CopyFile

func CopyFile(inst *instance.Instance, olddoc, newdoc *vfs.FileDoc) error

CopyFile is an overloaded version of Fs.CopyFile that take care of also copying the images in the note.

func Create

func Create(inst *instance.Instance, doc *Document) (*vfs.FileDoc, error)

Create the file in the VFS for this note.

func DefaultSchemaSpecs

func DefaultSchemaSpecs() map[string]interface{}

DefaultSchemaSpecs returns the prosemirror schema used when importing files.

func FlushPendings

func FlushPendings(inst *instance.Instance) error

FlushPendings is used to persist all the notes before an export.

func GetFile

func GetFile(inst *instance.Instance, file *vfs.FileDoc) (*vfs.FileDoc, error)

GetFile takes a file from the VFS as a note and returns its last version. It is useful when some changes have not yet been persisted to the VFS.

func GetText

func GetText(inst *instance.Instance, file *vfs.FileDoc) (string, error)

func ImportFile

func ImportFile(inst *instance.Instance, newdoc, olddoc *vfs.FileDoc, body io.ReadCloser) error

func ImportImages

func ImportImages(inst *instance.Instance, olddoc *vfs.FileDoc) error

func List

func List(inst *instance.Instance, bookmark string) ([]*vfs.FileDoc, string, error)

List returns a list of notes sorted by descending updated_at. It uses pagination via a mango bookmark.

func PublishThumbnail

func PublishThumbnail(inst *instance.Instance, event Event)

PublishThumbnail sends information about a resized image.

func PutTelepointer

func PutTelepointer(inst *instance.Instance, t Event) error

PutTelepointer sends the position of a pointer in the realtime hub.

func SetupTrigger

func SetupTrigger(inst *instance.Instance, fileID string) error

func Update

func Update(inst *instance.Instance, fileID string) error

Update is used to persist changes on a note to its file in the VFS.

func UpdateMetadataFromCache

func UpdateMetadataFromCache(inst *instance.Instance, docs []*vfs.FileDoc)

UpdateMetadataFromCache update the metadata for a file/note with the information in cache.

func UpdateSchema

func UpdateSchema(inst *instance.Instance, file *vfs.FileDoc, schema map[string]interface{}) (*vfs.FileDoc, error)

UpdateSchema updates the schema of a note, and invalidates the previous steps.

func UpdateTitle

func UpdateTitle(inst *instance.Instance, file *vfs.FileDoc, title, sessionID string) (*vfs.FileDoc, error)

UpdateTitle changes the title of a note and renames the associated file.

Types

type DebounceMessage

type DebounceMessage struct {
	NoteID string `json:"note_id"`
}

DebounceMessage is used by the trigger for saving the note to the VFS with a debounce.

type Document

type Document struct {
	DocID      string                 `json:"_id"`
	DocRev     string                 `json:"_rev,omitempty"`
	CreatedBy  string                 `json:"-"`
	DirID      string                 `json:"dir_id,omitempty"` // Only used at creation
	Title      string                 `json:"title"`
	Version    int64                  `json:"version"`
	SchemaSpec map[string]interface{} `json:"schema"`
	RawContent map[string]interface{} `json:"content"`
	// contains filtered or unexported fields
}

Document is the note document in memory. It is persisted to the VFS as a file, but with a debounce: the intermediate states are saved in Redis.

func (*Document) Clone

func (d *Document) Clone() couchdb.Doc

Clone implements couchdb.Doc

func (*Document) Content

func (d *Document) Content() (*model.Node, error)

Content returns the prosemirror content for this note.

func (*Document) DocType

func (d *Document) DocType() string

DocType returns the document type

func (*Document) GetDirID

func (d *Document) GetDirID(inst *instance.Instance) (string, error)

GetDirID returns the ID of the directory where the note will be created.

func (*Document) ID

func (d *Document) ID() string

ID returns the document qualified identifier

func (*Document) Markdown

func (d *Document) Markdown(images []*Image) ([]byte, error)

Markdown returns a markdown serialization of the content.

func (*Document) Metadata

func (d *Document) Metadata() map[string]interface{}

Metadata returns the file metadata for this note.

func (*Document) Rev

func (d *Document) Rev() string

Rev returns the document revision

func (*Document) Schema

func (d *Document) Schema() (*model.Schema, error)

Schema returns the prosemirror schema for this note

func (*Document) SetContent

func (d *Document) SetContent(content *model.Node)

SetContent updates the content of this note, and clears the cache.

func (*Document) SetID

func (d *Document) SetID(id string)

SetID changes the document qualified identifier

func (*Document) SetRev

func (d *Document) SetRev(rev string)

SetRev changes the document revision

func (*Document) Text

func (d *Document) Text() (string, error)

type Event

type Event map[string]interface{}

Event is a realtime event for a note (like the update of the position of a pointer).

func (Event) Clone

func (e Event) Clone() couchdb.Doc

Clone implements couchdb.Doc

func (Event) DocType

func (e Event) DocType() string

DocType returns the document type

func (Event) ID

func (e Event) ID() string

ID returns the event qualified identifier

func (Event) Included

func (e Event) Included() []jsonapi.Object

Included is part of the jsonapi.Object interface

func (e Event) Links() *jsonapi.LinksList

Links is part of the jsonapi.Object interface

func (Event) Relationships

func (e Event) Relationships() jsonapi.RelationshipMap

Relationships is part of the jsonapi.Object interface

func (Event) Rev

func (e Event) Rev() string

Rev returns the event revision

func (Event) SetID

func (e Event) SetID(id string)

SetID changes the event qualified identifier

func (Event) SetRev

func (e Event) SetRev(rev string)

SetRev changes the event revision

type Image

type Image struct {
	DocID    string                `json:"_id,omitempty"`
	DocRev   string                `json:"_rev,omitempty"`
	Name     string                `json:"name"`
	Mime     string                `json:"mime"`
	Width    int                   `json:"width,omitempty"`
	Height   int                   `json:"height,omitempty"`
	ToResize bool                  `json:"willBeResized,omitempty"`
	ToRemove bool                  `json:"willBeRemoved,omitempty"`
	Metadata metadata.CozyMetadata `json:"cozyMetadata,omitempty"`
	// contains filtered or unexported fields
}

Image is a file that will be persisted inside the note archive.

func CopyImageToAnotherNote

func CopyImageToAnotherNote(inst *instance.Instance, imageID string, dstDoc *vfs.FileDoc) (*Image, error)

CopyImageToAnotherNote makes a copy of an image from one note to be used in another note.

func GetImages

func GetImages(inst *instance.Instance, fileID string) ([]*Image, error)

GetImages returns the images for the given note.

func (*Image) Clone

func (img *Image) Clone() couchdb.Doc

Clone implements couchdb.Doc

func (*Image) DocType

func (img *Image) DocType() string

DocType returns the image type

func (*Image) ID

func (img *Image) ID() string

ID returns the image qualified identifier

func (*Image) Rev

func (img *Image) Rev() string

Rev returns the image revision

func (*Image) SetID

func (img *Image) SetID(id string)

SetID changes the image qualified identifier

func (*Image) SetRev

func (img *Image) SetRev(rev string)

SetRev changes the image revision

type ImageUpload

type ImageUpload struct {
	Image *Image
	// contains filtered or unexported fields
}

ImageUpload is used while an image is uploaded to the stack.

func NewImageUpload

func NewImageUpload(inst *instance.Instance, note *vfs.FileDoc, name, mime string) (*ImageUpload, error)

NewImageUpload can be used to manage uploading a new image for a note.

func (*ImageUpload) Close

func (u *ImageUpload) Close() error

Close is called to finalize an upload.

func (*ImageUpload) Write

func (u *ImageUpload) Write(p []byte) (int, error)

Write implements the io.Writer interface (used by io.Copy).

type Step

type Step map[string]interface{}

Step is a patch to apply on a note.

func GetSteps

func GetSteps(inst *instance.Instance, fileID string, version int64) ([]Step, error)

GetSteps returns the steps for the given note, starting from the version.

func (Step) Clone

func (s Step) Clone() couchdb.Doc

Clone implements couchdb.Doc

func (Step) DocType

func (s Step) DocType() string

DocType returns the document type

func (Step) ID

func (s Step) ID() string

ID returns the step qualified identifier

func (Step) Included

func (s Step) Included() []jsonapi.Object

Included is part of the jsonapi.Object interface

func (s Step) Links() *jsonapi.LinksList

Links is part of the jsonapi.Object interface

func (Step) Relationships

func (s Step) Relationships() jsonapi.RelationshipMap

Relationships is part of the jsonapi.Object interface

func (Step) Rev

func (s Step) Rev() string

Rev returns the step revision

func (Step) SetID

func (s Step) SetID(id string)

SetID changes the step qualified identifier

func (Step) SetRev

func (s Step) SetRev(rev string)

SetRev changes the step revision

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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