Documentation
¶
Overview ¶
Package sharelinks holds the Share Link feature: anonymous, expiring links that grant access to one Book.
Index ¶
- Constants
- func GenerateToken() (string, error)
- func RegisterBookRoutes(booksGroup *echo.Group, authMiddleware *auth.Middleware, ...)
- func RegisterPublicRoutes(api *echo.Group, shareLinkService *Service, bookService *books.Service, ...)
- func RegisterRoutes(api *echo.Group, authMiddleware *auth.Middleware, ...)
- func SaveSettings(ctx context.Context, store *appsettings.Service, s Settings) error
- type CreateOptions
- type CreateShareLinkPayload
- type Service
- func (svc *Service) BookLibraryID(ctx context.Context, bookID int) (int, error)
- func (svc *Service) Create(ctx context.Context, opts CreateOptions) (*models.ShareLink, error)
- func (svc *Service) Delete(ctx context.Context, link *models.ShareLink) error
- func (svc *Service) ListForBook(ctx context.Context, bookID int) ([]*models.ShareLink, error)
- func (svc *Service) RecordDownload(ctx context.Context, linkID int) error
- func (svc *Service) RecordOpen(ctx context.Context, linkID int) error
- func (svc *Service) RetrieveByToken(ctx context.Context, token string) (*models.ShareLink, error)
- func (svc *Service) RetrieveForBook(ctx context.Context, bookID, linkID int) (*models.ShareLink, error)
- func (svc *Service) Revoke(ctx context.Context, link *models.ShareLink) (*models.ShareLink, error)
- type Settings
- type ShareLinkResponse
- type SharedBookResponse
- type SharingSettingsResponse
- type UpdateSharingSettingsPayload
Constants ¶
const SettingsKey = "sharing"
SettingsKey is the app_settings key holding the sharing settings document.
SharedFailedPartwayMessage is a Share Link's answer to a Download as entry whose earlier build failed partway (downloadcache.ErrFailedPartway). The recipient cannot edit the book, so it points them to the sharer.
Variables ¶
This section is empty.
Functions ¶
func GenerateToken ¶
GenerateToken returns a new random Share Link token: 32 bytes from a cryptographically secure source, base64url encoded without padding or a prefix.
func RegisterBookRoutes ¶
func RegisterBookRoutes(booksGroup *echo.Group, authMiddleware *auth.Middleware, shareLinkService *Service, appSettingsService *appsettings.Service)
RegisterBookRoutes registers the management routes under /books on a group that only authenticates, since a role may hold shares operations without Books Read. Each route checks its shares operation here and the book's library access in the handler.
func RegisterPublicRoutes ¶
func RegisterPublicRoutes(api *echo.Group, shareLinkService *Service, bookService *books.Service, dlCache *downloadcache.Cache, coverCache *covers.ThumbnailCache)
RegisterPublicRoutes registers the unauthenticated recipient family under /share/:token. The server skips it in Demo Mode. Every handler calls publicHandler.resolve first, and none mounts a books handler: those require an authenticated user, so they would 401 every recipient and skip the refusal rules. A new refusal rule goes in resolve.
func RegisterRoutes ¶
func RegisterRoutes(api *echo.Group, authMiddleware *auth.Middleware, appSettingsService *appsettings.Service)
RegisterRoutes registers the sharing settings endpoints under /settings. They live here rather than in pkg/settings because pkg/books imports pkg/settings, and this package imports pkg/books.
func SaveSettings ¶
SaveSettings persists the sharing settings.
Types ¶
type CreateOptions ¶
CreateOptions describes a new Share Link.
type CreateShareLinkPayload ¶
type CreateShareLinkPayload struct {
}
CreateShareLinkPayload is the request body for POST /books/:id/share-links. The client turns an expiration preset into an absolute timestamp; the server knows nothing about presets. An omitted expires_at means the link never expires, which the sharing settings can forbid.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) BookLibraryID ¶
BookLibraryID returns the library a book belongs to, or errcodes.NotFound.
func (*Service) Create ¶
Create inserts a Share Link with a fresh token and returns it with its creator loaded.
func (*Service) ListForBook ¶
ListForBook returns every Share Link on a book from every creator, newest first, with creators and their library access loaded.
func (*Service) RecordDownload ¶
RecordDownload counts one file download and sets last used.
func (*Service) RecordOpen ¶
RecordOpen counts one opening of the recipient page and sets last used.
func (*Service) RetrieveByToken ¶
RetrieveByToken returns the Share Link with the given token, its creator, and the creator's library access, or errcodes.NotFound.
func (*Service) RetrieveForBook ¶
func (svc *Service) RetrieveForBook(ctx context.Context, bookID, linkID int) (*models.ShareLink, error)
RetrieveForBook returns the Share Link with the given id on the given book, or errcodes.NotFound when the link does not exist or belongs to another book.
type Settings ¶
type Settings struct {
Enabled bool `json:"enabled"`
RequireExpiration bool `json:"require_expiration"`
}
Settings is the admin-controlled sharing policy. It lives in the settings store rather than server config (ADR 0008). The zero value is the default: sharing off and expiration optional.
func LoadSettings ¶
LoadSettings reads the sharing settings, returning the defaults if none have been saved.
type ShareLinkResponse ¶
type ShareLinkResponse struct {
}
ShareLinkResponse is one Share Link as the sharer sees it: the model plus its derived state, why an active link is paused (omitted when it is not), and the creator's username. The list endpoint returns a bare array of these, and create and revoke return one.
type SharedBookResponse ¶
type SharedBookResponse struct {
}
SharedBookResponse is the book a recipient sees through a Share Link. It is the Book shape the detail page already renders, with every filesystem path and cover filename blanked and the library removed, plus who shared it, when the link expires, the library's cover aspect ratio so the cover box keeps its shape, and its tag namespaces so the tags group as they do on the book page.
type SharingSettingsResponse ¶
type SharingSettingsResponse struct {
Enabled bool `json:"enabled"`
RequireExpiration bool `json:"require_expiration"`
}
SharingSettingsResponse is the response for GET/PUT /settings/sharing.
Field shape must stay identical to Settings (same field names, same types, same order) because the handler converts between them with `SharingSettingsResponse(settings)`.
type UpdateSharingSettingsPayload ¶
type UpdateSharingSettingsPayload struct {
Enabled *bool `json:"enabled,omitempty"`
RequireExpiration *bool `json:"require_expiration,omitempty"`
}
UpdateSharingSettingsPayload is the request body for PUT /settings/sharing.
Fields are pointers so each switch can save on its own: an omitted field keeps its saved value.