bookmarks

package
v0.0.0-...-60192f8 Latest Latest
Warning

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

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

Documentation

Overview

Package bookmarks provides storage and tooling for bookmarks and collections management.

Index

Constants

View Source
const (
	// CollectionTable is the collection table name in database.
	CollectionTable = "bookmark_collection"
)
View Source
const (
	// TableName is the bookmark table name in database.
	TableName = "bookmark"
)

Variables

View Source
var (
	// Bookmarks is the bookmark query manager.
	Bookmarks = BookmarkManager{}

	// ErrBookmarkNotFound is returned when a bookmark record was not found.
	ErrBookmarkNotFound = errors.New("not found")
)
View Source
var (
	// Collections is the collection query manager.
	Collections = CollectionManager{}

	// ErrCollectionNotFound is returned when a collection record was not found.
	ErrCollectionNotFound = errors.New("not found")
)
View Source
var StateNames = map[BookmarkState]string{
	StateLoaded:  "loaded",
	StateError:   "error",
	StateLoading: "loading",
}

StateNames returns a string with the state name.

Functions

func DecryptID

func DecryptID(value string) (time.Time, uint64, error)

DecryptID deciphers a base64 encrypted value into a timestamp and a unsigned integer.

func EncryptID

func EncryptID(id uint64, expires time.Time) (string, error)

EncryptID returns an 128bit base64 encrypted ID and timestamp.

func GetContentScripts

func GetContentScripts(logger *log.Logger) []*contentscripts.Program

GetContentScripts returns the compiled content scripts, either from the cache or by browsing the configured folders.

func GetURLfilename

func GetURLfilename(uri string, contentType string) string

GetURLfilename returns a filename from a URL and MIME type. The filename is a short UUID based on the URL and its extension is based on the MIME type.

func LoadContentScripts

func LoadContentScripts()

LoadContentScripts loads the content scripts when Readeck is not configured in dev mode. In dev mode, scripts are reloaded on each extraction.

func NewArchive

func NewArchive(_ context.Context, ex *extract.Extractor) (*archiver.Archiver, error)

NewArchive runs the archiver and returns a BookmarkArchive instance.

func ResourceDirName

func ResourceDirName() string

ResourceDirName returns the resource folder name in an archive.

func StoragePath

func StoragePath() string

StoragePath returns the storage base directory for bookmark files.

Types

type AnnotationQueryResult

type AnnotationQueryResult struct {
	Bookmark Bookmark         `db:"b"`
	ID       string           `db:"annotation_id"`
	Text     string           `db:"annotation_text"`
	Created  types.TimeString `db:"annotation_created"`
}

AnnotationQueryResult hold the content of an annotation.

type Bookmark

type Bookmark struct {
	ID            int                 `db:"id" goqu:"skipinsert,skipupdate"`
	UID           string              `db:"uid"`
	UserID        *int                `db:"user_id"`
	Created       time.Time           `db:"created" goqu:"skipupdate"`
	Updated       time.Time           `db:"updated"`
	State         BookmarkState       `db:"state"`
	URL           string              `db:"url"`
	InitialURL    string              `db:"initial_url"`
	Title         string              `db:"title"`
	Domain        string              `db:"domain"`
	Site          string              `db:"site"`
	SiteName      string              `db:"site_name"`
	Published     *time.Time          `db:"published"`
	Authors       types.Strings       `db:"authors"`
	Lang          string              `db:"lang"`
	TextDirection string              `db:"dir"`
	DocumentType  string              `db:"type"`
	Description   string              `db:"description"`
	Text          string              `db:"text"`
	WordCount     int                 `db:"word_count"`
	Duration      int                 `db:"duration"`
	Embed         string              `db:"embed"`
	FilePath      string              `db:"file_path"`
	Files         BookmarkFiles       `db:"files"`
	Errors        types.Strings       `db:"errors"`
	Labels        types.Strings       `db:"labels"`
	IsArchived    bool                `db:"is_archived"`
	IsMarked      bool                `db:"is_marked"`
	Annotations   BookmarkAnnotations `db:"annotations"`
	Links         BookmarkLinks       `db:"links"`
}

Bookmark is a bookmark record in database.

func (*Bookmark) Delete

func (b *Bookmark) Delete() error

Delete removes a bookmark from the database.

func (*Bookmark) GetBaseFileURL

func (b *Bookmark) GetBaseFileURL() (string, error)

GetBaseFileURL returns the base path for archive URL.

func (*Bookmark) GetFilePath

func (b *Bookmark) GetFilePath() string

GetFilePath returns the bookmark's associated file path.

func (*Bookmark) GetLastModified

func (b *Bookmark) GetLastModified() []time.Time

GetLastModified returns the last modified times.

func (*Bookmark) GetSumStrings

func (b *Bookmark) GetSumStrings() []string

GetSumStrings returns the string used to generate the etag of the bookmark(s).

func (*Bookmark) OpenContainer

func (b *Bookmark) OpenContainer() (*BookmarkContainer, error)

OpenContainer opens the bookmark's zipfile and returns a new bookmarkContainer instance.

func (*Bookmark) ReadingTime

func (b *Bookmark) ReadingTime() int

ReadingTime returns the duration or the aproximated reading time.

func (*Bookmark) RemoveFiles

func (b *Bookmark) RemoveFiles()

RemoveFiles removes all the bookmark's files.

func (*Bookmark) Save

func (b *Bookmark) Save() error

Save updates all the bookmark values.

func (*Bookmark) StateName

func (b *Bookmark) StateName() string

StateName returns the current bookmark state name.

func (*Bookmark) Update

func (b *Bookmark) Update(v interface{}) error

Update updates some bookmark values.

type BookmarkAnnotation

type BookmarkAnnotation struct {
	ID            string    `json:"id"`
	StartSelector string    `json:"start_selector"`
	StartOffset   int       `json:"start_offset"`
	EndSelector   string    `json:"end_selector"`
	EndOffset     int       `json:"end_offset"`
	Created       time.Time `json:"created"`
	Text          string    `json:"text"`
}

BookmarkAnnotation is an annotation that can be serialized in a database JSON column.

func (*BookmarkAnnotation) AddToNode

func (a *BookmarkAnnotation) AddToNode(root *html.Node, tagName string, options ...annotate.WrapCallback) error

AddToNode adds one annotation to a DOM node (the designated root).

type BookmarkAnnotations

type BookmarkAnnotations []*BookmarkAnnotation

BookmarkAnnotations is a mapping of annotations.

func (*BookmarkAnnotations) Add

Add adds a new annotation to the list.

func (BookmarkAnnotations) AddToNode

func (a BookmarkAnnotations) AddToNode(root *html.Node, tagName string, options ...func(string, *html.Node, int)) error

AddToNode adds all annotations to a DOM node (the designated root).

func (*BookmarkAnnotations) Delete

func (a *BookmarkAnnotations) Delete(id string)

Delete removes an annotation from the list.

func (*BookmarkAnnotations) Get

Get retrieves an annotation or returns nil if it does not exist.

func (*BookmarkAnnotations) Scan

func (a *BookmarkAnnotations) Scan(value interface{}) error

Scan loads a BookmarkAnnotations instance from a column.

func (*BookmarkAnnotations) Sort

func (a *BookmarkAnnotations) Sort(root *html.Node, tagName string)

Sort sorts the annotations based on their position in the root document.

func (BookmarkAnnotations) Value

func (a BookmarkAnnotations) Value() (driver.Value, error)

Value encodes a BookmarkAnnotations instance for storage.

type BookmarkContainer

type BookmarkContainer struct {
	*zip.ReadCloser
	// contains filtered or unexported fields
}

BookmarkContainer is a wrapper around zip.ReadCloser to handle a bookmark's zipfile.

func (*BookmarkContainer) ExtractBody

func (c *BookmarkContainer) ExtractBody() (err error)

ExtractBody extract the content of the article's HTML body.

func (*BookmarkContainer) GetArticle

func (c *BookmarkContainer) GetArticle() string

GetArticle returns a string of the article's HTML.

func (*BookmarkContainer) GetFile

func (c *BookmarkContainer) GetFile(name string) ([]byte, error)

GetFile returns a file's content.

func (*BookmarkContainer) ListResources

func (c *BookmarkContainer) ListResources() []*zip.File

ListResources returns a list of files located under "_resources/".

func (*BookmarkContainer) LoadArticle

func (c *BookmarkContainer) LoadArticle() error

LoadArticle loads the bookmark´s article when it exists.

func (c *BookmarkContainer) ReplaceLinks(orig, repl string) (err error)

ReplaceLinks replaces all the link to _resources/* in the article content.

type BookmarkFile

type BookmarkFile struct {
	Name string `json:"name"`
	Type string `json:"type"`
	Size [2]int `json:"size,omitempty"`
}

BookmarkFile represents a stored file (attachment) for a bookmark. The Size property is ony useful for images.

type BookmarkFiles

type BookmarkFiles map[string]*BookmarkFile

BookmarkFiles is a map of BookmarkFile instances.

func (*BookmarkFiles) Scan

func (f *BookmarkFiles) Scan(value interface{}) error

Scan loads a BookmarkFiles instance from a column.

func (BookmarkFiles) Value

func (f BookmarkFiles) Value() (driver.Value, error)

Value encodes a BookmarkFiles instance for storage.

type BookmarkLink struct {
	URL         string `json:"url"`
	Domain      string `json:"domain"`
	Title       string `json:"title"`
	IsPage      bool   `json:"is_page"`
	ContentType string `json:"content_type"`
}

BookmarkLink describes a link.

type BookmarkLinks []BookmarkLink

BookmarkLinks is a list of BookmarkLink instances.

func (BookmarkLinks) HasPages

func (l BookmarkLinks) HasPages() bool

HasPages returns true if the link list contains at least one link that refers to an HTML page.

func (BookmarkLinks) Pages

func (l BookmarkLinks) Pages() BookmarkLinks

Pages returns a list of pages only.

func (*BookmarkLinks) Scan

func (l *BookmarkLinks) Scan(value interface{}) error

Scan loads a BookmarkLinks instance from a column.

func (BookmarkLinks) Value

func (l BookmarkLinks) Value() (driver.Value, error)

Value encodes a BookmarkLinks instance for storage.

type BookmarkManager

type BookmarkManager struct{}

BookmarkManager is a query helper for bookmark entries.

func (*BookmarkManager) CountAll

func (m *BookmarkManager) CountAll(u *users.User) (CountResult, error)

CountAll returns a CountResult of all bookmarks for a given user.

func (*BookmarkManager) Create

func (m *BookmarkManager) Create(bookmark *Bookmark) error

Create inserts a new bookmark in the database.

func (*BookmarkManager) DeleteUserBookmakrs

func (m *BookmarkManager) DeleteUserBookmakrs(u *users.User) error

DeleteUserBookmakrs remove all bookmarks for a given user. Normally we don't need such a process but since, a bookmark holds a file, we can't only rely on the foreign key cascade deletion. Hence this.

func (*BookmarkManager) GetAnnotations

func (m *BookmarkManager) GetAnnotations() *goqu.SelectDataset

GetAnnotations returns a SelectDataset that can be used to select all the annotations.

func (*BookmarkManager) GetLabels

func (m *BookmarkManager) GetLabels() *goqu.SelectDataset

GetLabels returns a dataset that returns all the tags defined in the bookmark table.

func (*BookmarkManager) GetLastUpdate

func (m *BookmarkManager) GetLastUpdate(expressions ...goqu.Expression) (time.Time, error)

GetLastUpdate returns the most recent "updated" value from a bookrmark set.

func (*BookmarkManager) GetOne

func (m *BookmarkManager) GetOne(expressions ...goqu.Expression) (*Bookmark, error)

GetOne executes the a select query and returns the first result or an error when there's no result.

func (*BookmarkManager) Query

func (m *BookmarkManager) Query() *goqu.SelectDataset

Query returns a prepared goqu SelectDataset that can be extended later.

func (*BookmarkManager) RenameLabel

func (m *BookmarkManager) RenameLabel(u *users.User, old, new string) (ids []int, err error)

RenameLabel renames or deletes a label in all bookmarks for a given user. If "new" is empty, the label is deleted.

type BookmarkState

type BookmarkState int

BookmarkState is the current bookmark state.

const (
	// StateLoaded when the page is fully loaded.
	StateLoaded BookmarkState = iota

	// StateError when there was some unrecoverable
	// error during extraction.
	StateError

	// StateLoading when the page is loading.
	StateLoading
)

type Collection

type Collection struct {
	ID       int               `db:"id" goqu:"skipinsert,skipupdate"`
	UID      string            `db:"uid"`
	UserID   *int              `db:"user_id"`
	Created  time.Time         `db:"created" goqu:"skipupdate"`
	Updated  time.Time         `db:"updated"`
	Name     string            `db:"name"`
	IsPinned bool              `db:"is_pinned"`
	Filters  CollectionFilters `db:"filters"`
}

Collection is a collection record in the database.

func (*Collection) Delete

func (c *Collection) Delete() error

Delete removes a collection from the database.

func (*Collection) Flatten

func (c *Collection) Flatten() map[string]interface{}

Flatten returns a flat mapping of all the collection's property, including filters.

func (*Collection) GetSumStrings

func (c *Collection) GetSumStrings() []string

GetSumStrings returns the string used to generate the etag of the collection(s).

func (*Collection) Save

func (c *Collection) Save() error

Save updates all the collection values.

func (*Collection) Update

func (c *Collection) Update(v interface{}) error

Update updates some collection values.

type CollectionFilters

type CollectionFilters struct {
	Search     string `json:"search"`
	Title      string `json:"title"`
	Author     string `json:"author"`
	Site       string `json:"site"`
	Type       string `json:"type"`
	Labels     string `json:"labels"`
	IsMarked   *bool  `json:"is_marked"`
	IsArchived *bool  `json:"is_archived"`
	RangeStart string `json:"range_start"`
	RangeEnd   string `json:"range_end"`
}

CollectionFilters contains the filters applied by a collection.

func (*CollectionFilters) Scan

func (s *CollectionFilters) Scan(value interface{}) error

Scan loads a CollectionFilters instance from a column.

func (CollectionFilters) Value

func (s CollectionFilters) Value() (driver.Value, error)

Value encodes a CollectionFilters value for storage.

type CollectionManager

type CollectionManager struct{}

CollectionManager is a query helper for bookmark entries.

func (*CollectionManager) Create

func (m *CollectionManager) Create(collection *Collection) error

Create inserts a new collection in the database.

func (*CollectionManager) GetOne

func (m *CollectionManager) GetOne(expressions ...goqu.Expression) (*Collection, error)

GetOne executes the a select query and returns the first result or an error when there's no result.

func (*CollectionManager) Query

func (m *CollectionManager) Query() *goqu.SelectDataset

Query returns a prepared goqu SelectDataset that can be extended later.

type CountResult

type CountResult struct {
	Total    int
	Archived int
	Marked   int
	ByType   map[string]int
}

CountResult contains the result of the total bookmark count with marked, archived and types breakdown.

Directories

Path Synopsis
Package importer provides the necessary tooling to import bookmarks from various sources.
Package importer provides the necessary tooling to import bookmarks from various sources.
Package routes provides http routes for bookmarks and collections management.
Package routes provides http routes for bookmarks and collections management.
Package tasks contains the bookmark and collection related tasks.
Package tasks contains the bookmark and collection related tasks.

Jump to

Keyboard shortcuts

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