Documentation ¶
Overview ¶
Package bookmarks provides storage and tooling for bookmarks and collections management.
Index ¶
- Constants
- Variables
- func DecryptID(value string) (time.Time, uint64, error)
- func EncryptID(id uint64, expires time.Time) (string, error)
- func GetContentScripts(logger *log.Logger) []*contentscripts.Program
- func GetURLfilename(uri string, contentType string) string
- func LoadContentScripts()
- func NewArchive(_ context.Context, ex *extract.Extractor) (*archiver.Archiver, error)
- func ResourceDirName() string
- func StoragePath() string
- type AnnotationQueryResult
- type Bookmark
- func (b *Bookmark) Delete() error
- func (b *Bookmark) GetBaseFileURL() (string, error)
- func (b *Bookmark) GetFilePath() string
- func (b *Bookmark) GetLastModified() []time.Time
- func (b *Bookmark) GetSumStrings() []string
- func (b *Bookmark) OpenContainer() (*BookmarkContainer, error)
- func (b *Bookmark) ReadingTime() int
- func (b *Bookmark) RemoveFiles()
- func (b *Bookmark) Save() error
- func (b *Bookmark) StateName() string
- func (b *Bookmark) Update(v interface{}) error
- type BookmarkAnnotation
- type BookmarkAnnotations
- func (a *BookmarkAnnotations) Add(item *BookmarkAnnotation)
- func (a BookmarkAnnotations) AddToNode(root *html.Node, tagName string, options ...func(string, *html.Node, int)) error
- func (a *BookmarkAnnotations) Delete(id string)
- func (a *BookmarkAnnotations) Get(id string) *BookmarkAnnotation
- func (a *BookmarkAnnotations) Scan(value interface{}) error
- func (a *BookmarkAnnotations) Sort(root *html.Node, tagName string)
- func (a BookmarkAnnotations) Value() (driver.Value, error)
- type BookmarkContainer
- func (c *BookmarkContainer) ExtractBody() (err error)
- func (c *BookmarkContainer) GetArticle() string
- func (c *BookmarkContainer) GetFile(name string) ([]byte, error)
- func (c *BookmarkContainer) ListResources() []*zip.File
- func (c *BookmarkContainer) LoadArticle() error
- func (c *BookmarkContainer) ReplaceLinks(orig, repl string) (err error)
- type BookmarkFile
- type BookmarkFiles
- type BookmarkLink
- type BookmarkLinks
- type BookmarkManager
- func (m *BookmarkManager) CountAll(u *users.User) (CountResult, error)
- func (m *BookmarkManager) Create(bookmark *Bookmark) error
- func (m *BookmarkManager) DeleteUserBookmakrs(u *users.User) error
- func (m *BookmarkManager) GetAnnotations() *goqu.SelectDataset
- func (m *BookmarkManager) GetLabels() *goqu.SelectDataset
- func (m *BookmarkManager) GetLastUpdate(expressions ...goqu.Expression) (time.Time, error)
- func (m *BookmarkManager) GetOne(expressions ...goqu.Expression) (*Bookmark, error)
- func (m *BookmarkManager) Query() *goqu.SelectDataset
- func (m *BookmarkManager) RenameLabel(u *users.User, old, new string) (ids []int, err error)
- type BookmarkState
- type Collection
- type CollectionFilters
- type CollectionManager
- type CountResult
Constants ¶
const (
// CollectionTable is the collection table name in database.
CollectionTable = "bookmark_collection"
)
const (
// TableName is the bookmark table name in database.
TableName = "bookmark"
)
Variables ¶
var ( // Bookmarks is the bookmark query manager. Bookmarks = BookmarkManager{} // ErrBookmarkNotFound is returned when a bookmark record was not found. ErrBookmarkNotFound = errors.New("not found") )
var ( // Collections is the collection query manager. Collections = CollectionManager{} // ErrCollectionNotFound is returned when a collection record was not found. ErrCollectionNotFound = errors.New("not found") )
var StateNames = map[BookmarkState]string{ StateLoaded: "loaded", StateError: "error", StateLoading: "loading", }
StateNames returns a string with the state name.
Functions ¶
func DecryptID ¶
DecryptID deciphers a base64 encrypted value into a timestamp and a unsigned integer.
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 ¶
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 ¶
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) GetBaseFileURL ¶
GetBaseFileURL returns the base path for archive URL.
func (*Bookmark) GetFilePath ¶
GetFilePath returns the bookmark's associated file path.
func (*Bookmark) GetLastModified ¶
GetLastModified returns the last modified times.
func (*Bookmark) GetSumStrings ¶
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 ¶
ReadingTime returns the duration or the aproximated reading time.
func (*Bookmark) RemoveFiles ¶
func (b *Bookmark) RemoveFiles()
RemoveFiles removes all the bookmark's files.
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 ¶
func (a *BookmarkAnnotations) Add(item *BookmarkAnnotation)
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 ¶
func (a *BookmarkAnnotations) Get(id string) *BookmarkAnnotation
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.
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 (*BookmarkContainer) ReplaceLinks ¶
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.
type BookmarkLink ¶
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 ¶
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.
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 ¶
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) 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.
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.
Source Files ¶
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. |