Documentation
¶
Index ¶
- Constants
- Variables
- func AugmentedDocumentsFromDocuments(results result.Paginated[[]index.Document]) result.Paginated[[]AugmentedDocument]
- func Hash(s string) string
- func Paginate(currentPage int, pageSize int) func(db *gorm.DB) *gorm.DB
- type AugmentedDocument
- type CompletedYearStats
- type Highlight
- type HighlightRepository
- func (u *HighlightRepository) Highlight(userID int, documentSlug string) error
- func (u *HighlightRepository) Highlighted(userID int, doc AugmentedDocument) AugmentedDocument
- func (u *HighlightRepository) HighlightedPaginatedResult(userID int, results result.Paginated[[]AugmentedDocument]) result.Paginated[[]AugmentedDocument]
- func (u *HighlightRepository) Highlights(userID int, page int, resultsPerPage int, sortBy, filter string) (result.Paginated[[]AugmentedDocument], error)
- func (u *HighlightRepository) Remove(userID int, documentSlug string) error
- func (u *HighlightRepository) RemoveDocument(documentSlug string) error
- func (u *HighlightRepository) Share(senderID int, documentSlug, comment string, recipientIDs []int) error
- func (u *HighlightRepository) Total(userID int) (int, error)
- type Invitation
- type InvitationRepository
- type Reading
- type ReadingRepository
- func (u *ReadingRepository) CompletedBetweenDates(userID int, startDate, endDate *time.Time) ([]string, error)
- func (u *ReadingRepository) CompletedOn(userID int, documentSlug string) (*time.Time, error)
- func (u *ReadingRepository) CompletedPaginatedBetweenDates(userID int, startDate, endDate *time.Time, page int, resultsPerPage int, ...) (result.Paginated[[]AugmentedDocument], error)
- func (u *ReadingRepository) CompletedPaginatedResult(userID int, results result.Paginated[[]AugmentedDocument]) result.Paginated[[]AugmentedDocument]
- func (u *ReadingRepository) CompletedStatsByYear(userID int, wordsPerMinute float64) ([]CompletedYearStats, error)
- func (u *ReadingRepository) CompletedYears(userID uint) ([]int, error)
- func (u *ReadingRepository) Get(userID int, documentSlug string) (Reading, error)
- func (u *ReadingRepository) Latest(userID int, page int, resultsPerPage int) (result.Paginated[[]string], error)
- func (u *ReadingRepository) RemoveDocument(documentSlug string) error
- func (u *ReadingRepository) Touch(userID int, documentSlug string) error
- func (u *ReadingRepository) Update(userID int, documentSlug, position string) error
- func (u *ReadingRepository) UpdateCompletionDate(userID int, documentSlug string, completedAt *time.Time) error
- type Session
- type User
- type UserRepository
- func (u *UserRepository) Admins() int64
- func (u *UserRepository) Create(user *User) error
- func (u *UserRepository) Delete(uuid string) error
- func (u *UserRepository) FindByEmail(email string) (*User, error)
- func (u *UserRepository) FindByRecoveryUuid(recoveryUuid string) (*User, error)
- func (u *UserRepository) FindByUsername(username string) (*User, error)
- func (u *UserRepository) FindByUuid(uuid string) (*User, error)
- func (u *UserRepository) List(page int, resultsPerPage int, filter string) (result.Paginated[[]User], error)
- func (u *UserRepository) Total(filter string) int64
- func (u *UserRepository) Update(user *User) error
- func (u *UserRepository) UpdateLastRequest(userID uint) error
- func (u *UserRepository) UsernamesAndNames(filter string) ([]User, error)
Constants ¶
const ( ResultsPerPage = 10.0 )
const ( RoleRegular = iota + 1 RoleAdmin )
User roles identifiers
const UsernamePattern = `^[A-z0-9_\-.]+$`
Variables ¶
var AllowedDefaultActions = []string{"download", "send", "share", "copy"}
Functions ¶
func AugmentedDocumentsFromDocuments ¶ added in v4.19.0
Types ¶
type AugmentedDocument ¶ added in v4.19.0
type CompletedYearStats ¶ added in v4.21.0
type CompletedYearStats struct {
Year int
DocumentCount int
ReadingTime string // estimated reading time (e.g. "2h 30m") from word count and user's words-per-minute
}
CompletedYearStats holds aggregated stats for documents completed in a year (or all time when Year is 0).
type HighlightRepository ¶
func (*HighlightRepository) Highlight ¶
func (u *HighlightRepository) Highlight(userID int, documentSlug string) error
func (*HighlightRepository) Highlighted ¶
func (u *HighlightRepository) Highlighted(userID int, doc AugmentedDocument) AugmentedDocument
func (*HighlightRepository) HighlightedPaginatedResult ¶
func (u *HighlightRepository) HighlightedPaginatedResult(userID int, results result.Paginated[[]AugmentedDocument]) result.Paginated[[]AugmentedDocument]
func (*HighlightRepository) Highlights ¶
func (u *HighlightRepository) Highlights(userID int, page int, resultsPerPage int, sortBy, filter string) (result.Paginated[[]AugmentedDocument], error)
Highlights returns paginated highlights as AugmentedDocuments (index-backed). Rows whose documents are missing from the index are omitted from Hits() but still count toward TotalHits.
func (*HighlightRepository) Remove ¶
func (u *HighlightRepository) Remove(userID int, documentSlug string) error
func (*HighlightRepository) RemoveDocument ¶
func (u *HighlightRepository) RemoveDocument(documentSlug string) error
type Invitation ¶ added in v4.15.0
type Invitation struct {
ID uint `gorm:"primarykey"`
Email string `gorm:"uniqueIndex; not null"`
UUID string `gorm:"uniqueIndex; not null"`
ValidUntil time.Time
}
Invitation represents a user invitation
type InvitationRepository ¶ added in v4.15.0
func (*InvitationRepository) Create ¶ added in v4.15.0
func (i *InvitationRepository) Create(invitation *Invitation) error
func (*InvitationRepository) DeleteByEmail ¶ added in v4.15.0
func (i *InvitationRepository) DeleteByEmail(email string) error
func (*InvitationRepository) FindByUUID ¶ added in v4.15.0
func (i *InvitationRepository) FindByUUID(uuid string) (*Invitation, error)
type ReadingRepository ¶ added in v4.9.0
func (*ReadingRepository) CompletedBetweenDates ¶ added in v4.15.0
func (u *ReadingRepository) CompletedBetweenDates(userID int, startDate, endDate *time.Time) ([]string, error)
CompletedBetweenDates returns slugs of all readings completed by a user. If startDate and endDate are provided, it filters readings completed between those dates (inclusive). If startDate or endDate are nil, they are not used as filters.
func (*ReadingRepository) CompletedOn ¶ added in v4.19.0
func (*ReadingRepository) CompletedPaginatedBetweenDates ¶ added in v4.21.0
func (u *ReadingRepository) CompletedPaginatedBetweenDates(userID int, startDate, endDate *time.Time, page int, resultsPerPage int, orderBy string) (result.Paginated[[]AugmentedDocument], error)
CompletedPaginatedBetweenDates returns paginated completed readings for a user as AugmentedDocuments, optionally filtered by date range (inclusive). When startDate and endDate are both nil, all completed readings are returned. orderBy is e.g. "completed_on DESC" or "completed_on ASC"; if empty, "completed_on DESC" is used. Requires Idx to be set; documents missing from the index are skipped from the page but total count is the DB count.
func (*ReadingRepository) CompletedPaginatedResult ¶ added in v4.15.0
func (u *ReadingRepository) CompletedPaginatedResult(userID int, results result.Paginated[[]AugmentedDocument]) result.Paginated[[]AugmentedDocument]
func (*ReadingRepository) CompletedStatsByYear ¶ added in v4.21.0
func (u *ReadingRepository) CompletedStatsByYear(userID int, wordsPerMinute float64) ([]CompletedYearStats, error)
CompletedStatsByYear returns aggregated stats per year (and "all time" as year 0) including estimated reading time. wordsPerMinute is used to compute ReadingTime for each year. Requires Idx (TotalWordCount) to be set.
func (*ReadingRepository) CompletedYears ¶ added in v4.18.1
func (u *ReadingRepository) CompletedYears(userID uint) ([]int, error)
CompletedYears returns the years with completed readings for a user.
func (*ReadingRepository) Get ¶ added in v4.14.0
func (u *ReadingRepository) Get(userID int, documentSlug string) (Reading, error)
func (*ReadingRepository) RemoveDocument ¶ added in v4.9.0
func (u *ReadingRepository) RemoveDocument(documentSlug string) error
func (*ReadingRepository) Touch ¶ added in v4.14.0
func (u *ReadingRepository) Touch(userID int, documentSlug string) error
Touch creates a reading record if it doesn't exist, but doesn't update it if it does. This is used to track that a document has been opened without overwriting existing positions. Sets updated_at to NULL initially - it will only be set when the reading position is actually updated.
func (*ReadingRepository) Update ¶ added in v4.9.0
func (u *ReadingRepository) Update(userID int, documentSlug, position string) error
func (*ReadingRepository) UpdateCompletionDate ¶ added in v4.15.0
type User ¶
type User struct {
ID uint `gorm:"primarykey"`
CreatedAt time.Time
UpdatedAt time.Time
Uuid string `gorm:"uniqueIndex; not null"`
Name string `gorm:"not null"`
Username string `gorm:"type:text collate nocase; not null; unique"`
Email string `gorm:"uniqueIndex; not null"`
SendToEmail string
Password string
Role int `gorm:"not null"`
WordsPerMinute float64
RecoveryUUID string
RecoveryValidUntil time.Time
Highlights []Highlight `gorm:"constraint:OnDelete:CASCADE"`
Readings []Reading `gorm:"constraint:OnDelete:CASCADE"`
LastRequest time.Time
ShowFileName bool `gorm:"default:false; not null"`
PrivateProfile int `gorm:"default:0; not null"`
PreferredEpubType string `gorm:"default:'epub'; not null"`
DefaultAction string `gorm:"default:'download'; not null"`
Language string
}
func (User) ConfirmPassword ¶
type UserRepository ¶
func (*UserRepository) Admins ¶
func (u *UserRepository) Admins() int64
func (*UserRepository) Create ¶
func (u *UserRepository) Create(user *User) error
func (*UserRepository) Delete ¶
func (u *UserRepository) Delete(uuid string) error
func (*UserRepository) FindByEmail ¶
func (u *UserRepository) FindByEmail(email string) (*User, error)
func (*UserRepository) FindByRecoveryUuid ¶
func (u *UserRepository) FindByRecoveryUuid(recoveryUuid string) (*User, error)
func (*UserRepository) FindByUsername ¶
func (u *UserRepository) FindByUsername(username string) (*User, error)
func (*UserRepository) FindByUuid ¶
func (u *UserRepository) FindByUuid(uuid string) (*User, error)
func (*UserRepository) Total ¶
func (u *UserRepository) Total(filter string) int64
func (*UserRepository) Update ¶
func (u *UserRepository) Update(user *User) error
func (*UserRepository) UpdateLastRequest ¶ added in v4.17.0
func (u *UserRepository) UpdateLastRequest(userID uint) error
func (*UserRepository) UsernamesAndNames ¶ added in v4.19.0
func (u *UserRepository) UsernamesAndNames(filter string) ([]User, error)