Documentation
¶
Index ¶
- Constants
- Variables
- func GetArchivePath(bookmark *BookmarkDTO) string
- func GetEbookPath(bookmark *BookmarkDTO) string
- func GetThumbnailPath(bookmark *BookmarkDTO) string
- func Ptr[t any](a t) *t
- func SliceDifference[T comparable](haystack, needle []T) []T
- type Account
- type AccountDTO
- type AccountsDomain
- type ArchiverDomain
- type AuthDomain
- type Bookmark
- type BookmarkDTO
- type BookmarkTag
- type BookmarksDomain
- type DB
- type DBGetBookmarksOptions
- type DBID
- type DBListAccountsOptions
- type DBListTagsOptions
- type DBOrderMethod
- type DBTagOrderBy
- type Dependencies
- type DomainDependencies
- type HttpHandler
- type HttpMiddleware
- type JWTClaim
- type LegacyLoginHandler
- type ListTagsOptions
- type StorageDomain
- type Tag
- type TagDTO
- type TagsDomain
- type UserConfig
- type ValidationError
- type WebContext
Constants ¶
const ( // ContextAccountKey is the key used to store the account model in the gin context. ContextAccountKey = "account" // AuthorizationHeader is the name of the header used to send the token. AuthorizationHeader = "Authorization" // AuthorizationTokenType is the type of token used in the Authorization header. AuthorizationTokenType = "Bearer" )
const DataDirPerm = 0744
DataDirPerm the default filesystem permissions for the data directory/archives
const DatabaseDateFormat = "2006-01-02 15:04:05"
DatabaseDateFormat the string formatting of datetimes for the database
const (
// ShioriNamespace
ShioriURLNamespace = "https://github.com/go-shiori/shiori"
)
Variables ¶
var ( ErrBookmarkNotFound = errors.New("bookmark not found") ErrBookmarkInvalidID = errors.New("invalid bookmark ID") ErrTagNotFound = errors.New("tag not found") ErrNotFound = errors.New("not found") ErrAlreadyExists = errors.New("already exists") )
var ( BuildVersion = "dev" BuildCommit = "none" BuildDate = "unknown" )
Variables set my the main package coming from ldflags
Functions ¶
func GetArchivePath ¶ added in v1.6.0
func GetArchivePath(bookmark *BookmarkDTO) string
GetArchivePath returns the relative path to the archive of a bookmark in the filesystem
func GetEbookPath ¶ added in v1.6.0
func GetEbookPath(bookmark *BookmarkDTO) string
GetEbookPath returns the relative path to the ebook of a bookmark in the filesystem
func GetThumbnailPath ¶ added in v1.6.0
func GetThumbnailPath(bookmark *BookmarkDTO) string
GetTumnbailPath returns the relative path to the thumbnail of a bookmark in the filesystem
func Ptr ¶ added in v1.8.0
func Ptr[t any](a t) *t
Ptr returns a pointer to the value passed as argument.
func SliceDifference ¶ added in v1.8.0
func SliceDifference[T comparable](haystack, needle []T) []T
SliceDifference returns the elements that are in haystack but not in needle. It's a generic function that works with any comparable type.
Types ¶
type Account ¶
type Account struct {
ID DBID `db:"id" json:"id"`
Username string `db:"username" json:"username"`
Password string `db:"password" json:"password,omitempty"`
Owner bool `db:"owner" json:"owner"`
Config UserConfig `db:"config" json:"config"`
}
Account is the database representation for account.
func (Account) ToDTO ¶ added in v1.6.0
func (a Account) ToDTO() AccountDTO
ToDTO converts Account to AccountDTO.
type AccountDTO ¶ added in v1.6.0
type AccountDTO struct {
ID DBID `json:"id"`
Username string `json:"username"`
Password string `json:"passowrd,omitempty"` // Used only to store, not to retrieve
Owner *bool `json:"owner"`
Config *UserConfig `json:"config"`
}
AccountDTO is data transfer object for Account.
func (*AccountDTO) IsOwner ¶ added in v1.8.0
func (adto *AccountDTO) IsOwner() bool
func (*AccountDTO) IsValidCreate ¶ added in v1.8.0
func (adto *AccountDTO) IsValidCreate() error
func (*AccountDTO) IsValidUpdate ¶ added in v1.8.0
func (adto *AccountDTO) IsValidUpdate() error
type AccountsDomain ¶ added in v1.6.0
type AccountsDomain interface {
ListAccounts(ctx context.Context) ([]AccountDTO, error)
GetAccountByUsername(ctx context.Context, username string) (*AccountDTO, error)
CreateAccount(ctx context.Context, account AccountDTO) (*AccountDTO, error)
UpdateAccount(ctx context.Context, account AccountDTO) (*AccountDTO, error)
DeleteAccount(ctx context.Context, id int) error
}
type ArchiverDomain ¶ added in v1.6.0
type ArchiverDomain interface {
DownloadBookmarkArchive(book BookmarkDTO) (*BookmarkDTO, error)
GetBookmarkArchive(book *BookmarkDTO) (*warc.Archive, error)
}
type AuthDomain ¶ added in v1.8.0
type AuthDomain interface {
CheckToken(ctx context.Context, userJWT string) (*AccountDTO, error)
GetAccountFromCredentials(ctx context.Context, username, password string) (*AccountDTO, error)
CreateTokenForAccount(account *AccountDTO, expiration time.Time) (string, error)
}
type Bookmark ¶
type Bookmark struct {
ID int `db:"id"`
URL string `db:"url"`
Title string `db:"title"`
Excerpt string `db:"excerpt"`
Author string `db:"author"`
Public int `db:"public"`
CreatedAt string `db:"created_at"`
ModifiedAt string `db:"modified_at"`
HasContent bool `db:"has_content"`
}
Bookmark is the database representation of a bookmark
func (*Bookmark) ToDTO ¶ added in v1.8.0
func (b *Bookmark) ToDTO() BookmarkDTO
ToDTO converts a Bookmark to a BookmarkDTO
type BookmarkDTO ¶ added in v1.6.0
type BookmarkDTO struct {
ID int `db:"id" json:"id"`
URL string `db:"url" json:"url"`
Title string `db:"title" json:"title"`
Excerpt string `db:"excerpt" json:"excerpt"`
Author string `db:"author" json:"author"`
Public int `db:"public" json:"public"`
CreatedAt string `db:"created_at" json:"createdAt"`
ModifiedAt string `db:"modified_at" json:"modifiedAt"`
Content string `db:"content" json:"-"`
HTML string `db:"html" json:"html,omitempty"`
ImageURL string `db:"image_url" json:"imageURL"`
HasContent bool `db:"has_content" json:"hasContent"`
Tags []TagDTO `json:"tags"`
HasArchive bool `json:"hasArchive"`
HasEbook bool `json:"hasEbook"`
CreateArchive bool `json:"create_archive"` // TODO: migrate outside the DTO
CreateEbook bool `json:"create_ebook"` // TODO: migrate outside the DTO
}
BookmarkDTO is the bookmark object representation in database and the data transfer object at the same time, pending a refactor to two separate object to represent each role.
func (*BookmarkDTO) ToBookmark ¶ added in v1.8.0
func (dto *BookmarkDTO) ToBookmark() Bookmark
ToBookmark converts a BookmarkDTO to a Bookmark
type BookmarkTag ¶ added in v1.8.0
BookmarkTag is the relationship between a bookmark and a tag.
type BookmarksDomain ¶ added in v1.6.0
type BookmarksDomain interface {
HasEbook(b *BookmarkDTO) bool
HasArchive(b *BookmarkDTO) bool
HasThumbnail(b *BookmarkDTO) bool
GetBookmark(ctx context.Context, id DBID) (*BookmarkDTO, error)
GetBookmarks(ctx context.Context, ids []int) ([]BookmarkDTO, error)
UpdateBookmarkCache(ctx context.Context, bookmark BookmarkDTO, keepMetadata bool, skipExist bool) (*BookmarkDTO, error)
BulkUpdateBookmarkTags(ctx context.Context, bookmarkIDs []int, tagIDs []int) error
AddTagToBookmark(ctx context.Context, bookmarkID int, tagID int) error
RemoveTagFromBookmark(ctx context.Context, bookmarkID int, tagID int) error
BookmarkExists(ctx context.Context, id int) (bool, error)
}
type DB ¶ added in v1.8.0
type DB interface {
// WriterDB is the underlying sqlx.DB
WriterDB() *sqlx.DB
// ReaderDB is the underlying sqlx.DB
ReaderDB() *sqlx.DB
// Init initializes the database
Init(ctx context.Context) error
// Migrate runs migrations for this database
Migrate(ctx context.Context) error
// GetDatabaseSchemaVersion gets the version of the database
GetDatabaseSchemaVersion(ctx context.Context) (string, error)
// SetDatabaseSchemaVersion sets the version of the database
SetDatabaseSchemaVersion(ctx context.Context, version string) error
// SaveBookmarks saves bookmarks data to database.
SaveBookmarks(ctx context.Context, create bool, bookmarks ...BookmarkDTO) ([]BookmarkDTO, error)
// SaveBookmark saves a single bookmark to database without handling tags.
// It only updates the bookmark data in the database.
SaveBookmark(ctx context.Context, bookmark Bookmark) error
// GetBookmarks fetch list of bookmarks based on submitted options.
GetBookmarks(ctx context.Context, opts DBGetBookmarksOptions) ([]BookmarkDTO, error)
// GetBookmarksCount get count of bookmarks in database.
GetBookmarksCount(ctx context.Context, opts DBGetBookmarksOptions) (int, error)
// DeleteBookmarks removes all record with matching ids from database.
DeleteBookmarks(ctx context.Context, ids ...int) error
// GetBookmark fetches bookmark based on its ID or URL.
GetBookmark(ctx context.Context, id int, url string) (BookmarkDTO, bool, error)
// CreateAccount saves new account in database
CreateAccount(ctx context.Context, a Account) (*Account, error)
// UpdateAccount updates account in database
UpdateAccount(ctx context.Context, a Account) error
// ListAccounts fetch list of account (without its password) with matching keyword.
ListAccounts(ctx context.Context, opts DBListAccountsOptions) ([]Account, error)
// GetAccount fetch account with matching username.
GetAccount(ctx context.Context, id DBID) (*Account, bool, error)
// DeleteAccount removes account with matching id
DeleteAccount(ctx context.Context, id DBID) error
// CreateTags creates new tags in database.
CreateTags(ctx context.Context, tags ...Tag) ([]Tag, error)
// CreateTag creates a new tag in database.
CreateTag(ctx context.Context, tag Tag) (Tag, error)
// GetTags fetch list of tags and its frequency from database.
GetTags(ctx context.Context, opts DBListTagsOptions) ([]TagDTO, error)
// RenameTag change the name of a tag.
RenameTag(ctx context.Context, id int, newName string) error
// GetTag fetch a tag by its ID.
GetTag(ctx context.Context, id int) (TagDTO, bool, error)
// UpdateTag updates a tag in the database.
UpdateTag(ctx context.Context, tag Tag) error
// DeleteTag removes a tag from the database.
DeleteTag(ctx context.Context, id int) error
// BulkUpdateBookmarkTags updates tags for multiple bookmarks.
// It ensures that all bookmarks and tags exist before proceeding.
BulkUpdateBookmarkTags(ctx context.Context, bookmarkIDs []int, tagIDs []int) error
// AddTagToBookmark adds a tag to a bookmark
AddTagToBookmark(ctx context.Context, bookmarkID int, tagID int) error
// RemoveTagFromBookmark removes a tag from a bookmark
RemoveTagFromBookmark(ctx context.Context, bookmarkID int, tagID int) error
// TagExists checks if a tag with the given ID exists in the database
TagExists(ctx context.Context, tagID int) (bool, error)
// BookmarkExists checks if a bookmark with the given ID exists in the database
BookmarkExists(ctx context.Context, bookmarkID int) (bool, error)
}
DB is interface for accessing and manipulating data in database.
type DBGetBookmarksOptions ¶ added in v1.8.0
type DBGetBookmarksOptions struct {
IDs []int
Tags []string
ExcludedTags []string
Keyword string
WithContent bool
OrderMethod DBOrderMethod
Limit int
Offset int
}
DBGetBookmarksOptions is options for fetching bookmarks from database.
type DBListAccountsOptions ¶ added in v1.8.0
type DBListAccountsOptions struct {
// Filter accounts by a keyword
Keyword string
// Filter accounts by exact useranme
Username string
// Return owner accounts only
Owner bool
// Retrieve password content
WithPassword bool
}
DBListAccountsOptions is options for fetching accounts from database.
type DBListTagsOptions ¶ added in v1.8.0
type DBListTagsOptions struct {
BookmarkID int
WithBookmarkCount bool
OrderBy DBTagOrderBy
Search string
}
DBListTagsOptions is options for fetching tags from database.
type DBOrderMethod ¶ added in v1.8.0
type DBOrderMethod int
DBOrderMethod is the order method for getting bookmarks
const ( // DefaultOrder is oldest to newest. DefaultOrder DBOrderMethod = iota // ByLastAdded is from newest addition to the oldest. ByLastAdded // ByLastModified is from latest modified to the oldest. ByLastModified )
type DBTagOrderBy ¶ added in v1.8.0
type DBTagOrderBy string
const (
DBTagOrderByTagName DBTagOrderBy = "name"
)
type Dependencies ¶ added in v1.8.0
type Dependencies interface {
Logger() *logrus.Logger
Domains() DomainDependencies
Config() *config.Config
Database() DB
}
Dependencies represents the interface for application dependencies
type DomainDependencies ¶ added in v1.8.0
type DomainDependencies interface {
Auth() AuthDomain
SetAuth(auth AuthDomain)
Accounts() AccountsDomain
SetAccounts(accounts AccountsDomain)
Bookmarks() BookmarksDomain
SetBookmarks(bookmarks BookmarksDomain)
Archiver() ArchiverDomain
SetArchiver(archiver ArchiverDomain)
Storage() StorageDomain
SetStorage(storage StorageDomain)
Tags() TagsDomain
SetTags(tags TagsDomain)
}
DomainDependencies represents the interface for domain-specific dependencies
type HttpHandler ¶ added in v1.8.0
type HttpHandler func(deps Dependencies, c WebContext)
Handler is a custom handler function that receives dependencies and web context
type HttpMiddleware ¶ added in v1.8.0
type HttpMiddleware interface {
OnRequest(deps Dependencies, c WebContext) error
OnResponse(deps Dependencies, c WebContext) error
}
Middleware defines the interface for request/response customization
type JWTClaim ¶ added in v1.7.2
type JWTClaim struct {
jwt.RegisteredClaims
Account *Account
}
type LegacyLoginHandler ¶ added in v1.6.0
type LegacyLoginHandler func(account *AccountDTO, expTime time.Duration) (string, error)
type ListTagsOptions ¶ added in v1.8.0
type ListTagsOptions struct {
BookmarkID int
WithBookmarkCount bool
OrderBy DBTagOrderBy
Search string
}
ListTagsOptions is options for fetching tags from database.
func (ListTagsOptions) IsValid ¶ added in v1.8.0
func (o ListTagsOptions) IsValid() error
IsValid validates the ListTagsOptions. Returns an error if the options are invalid, nil otherwise. Currently, it checks that Search and BookmarkID are not used together.
type StorageDomain ¶ added in v1.6.0
type TagDTO ¶ added in v1.8.0
type TagDTO struct {
Tag
BookmarkCount int64 `db:"bookmark_count" json:"bookmark_count"` // Number of bookmarks with this tag
Deleted bool `json:"deleted"` // Marks when a tag is deleted from a bookmark
}
TagDTO represents a tag in the application
type TagsDomain ¶ added in v1.8.0
type TagsDomain interface {
ListTags(ctx context.Context, opts ListTagsOptions) ([]TagDTO, error)
CreateTag(ctx context.Context, tag TagDTO) (TagDTO, error)
GetTag(ctx context.Context, id int) (TagDTO, error)
UpdateTag(ctx context.Context, tag TagDTO) (TagDTO, error)
DeleteTag(ctx context.Context, id int) error
TagExists(ctx context.Context, id int) (bool, error)
}
type UserConfig ¶ added in v1.6.0
type UserConfig struct {
ShowId bool
ListMode bool
HideThumbnail bool
HideExcerpt bool
Theme string
KeepMetadata bool
UseArchive bool
CreateEbook bool
MakePublic bool
}
func (*UserConfig) Scan ¶ added in v1.6.0
func (c *UserConfig) Scan(value interface{}) error
type ValidationError ¶ added in v1.8.0
ValidationError represents a validation error. This errors are used in the domain layer to indicate an error that is caused generally by the user and has to be sent back via the API or appropriate channel.
func NewValidationError ¶ added in v1.8.0
func NewValidationError(field, message string) ValidationError
func (ValidationError) Error ¶ added in v1.8.0
func (v ValidationError) Error() string
type WebContext ¶ added in v1.8.0
type WebContext interface {
Request() *http.Request
ResponseWriter() http.ResponseWriter
SetResponseWriter(w http.ResponseWriter)
GetAccount() *AccountDTO
SetAccount(*AccountDTO)
UserIsLogged() bool
GetRequestID() string
SetRequestID(id string)
}
WebContext represents the context of an HTTP request