Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterRoutes(e *echo.Echo, db *bun.DB, authMiddleware *auth.Middleware)
- type APIKey
- type APIKeyPermission
- type APIKeyShortURL
- type CreateRequest
- type Service
- func (s *Service) AddPermission(ctx context.Context, userID int, keyID string, permission string) (*APIKey, error)
- func (s *Service) ClearKoboSyncHistory(ctx context.Context, userID int, keyID string) error
- func (s *Service) Create(ctx context.Context, userID int, name string) (*APIKey, error)
- func (s *Service) Delete(ctx context.Context, userID int, keyID string) error
- func (s *Service) GenerateShortURL(ctx context.Context, userID int, keyID string) (*APIKeyShortURL, error)
- func (s *Service) GetByKey(ctx context.Context, key string) (*APIKey, error)
- func (s *Service) List(ctx context.Context, userID int) ([]*APIKey, error)
- func (s *Service) RemovePermission(ctx context.Context, userID int, keyID string, permission string) (*APIKey, error)
- func (s *Service) ResolveShortCode(ctx context.Context, shortCode string) (*APIKey, error)
- func (s *Service) TouchLastAccessed(ctx context.Context, keyID string) error
- func (s *Service) UpdateName(ctx context.Context, userID int, keyID string, name string) (*APIKey, error)
- type UpdateNameRequest
Constants ¶
const PermissionEReaderBrowser = "ereader_browser"
PermissionEReaderBrowser is the permission for accessing the eReader browser UI.
const PermissionKoboSync = "kobo_sync"
PermissionKoboSync is the permission for Kobo sync API access.
Variables ¶
var ErrNotFound = errors.New("api key not found")
Functions ¶
func RegisterRoutes ¶
RegisterRoutes registers API key management routes.
Types ¶
type APIKey ¶
type APIKey struct {
bun.BaseModel `bun:"table:api_keys,alias:ak" json:"-"`
ID string `bun:"id,pk" json:"id"`
UserID int `bun:"user_id,notnull" json:"userId"`
Name string `bun:"name,notnull" json:"name"`
Key string `bun:"key,notnull,unique" json:"key"`
CreatedAt time.Time `bun:"created_at,notnull" json:"createdAt"`
UpdatedAt time.Time `bun:"updated_at,notnull" json:"updatedAt"`
LastAccessedAt *time.Time `bun:"last_accessed_at" json:"lastAccessedAt"`
Permissions []*APIKeyPermission `bun:"rel:has-many,join:id=api_key_id" json:"permissions"`
}
APIKey represents a user's API key for programmatic access.
func (*APIKey) HasPermission ¶
HasPermission checks if the API key has a specific permission.
func (*APIKey) PermissionStrings ¶
PermissionStrings returns a list of permission strings.
type APIKeyPermission ¶
type APIKeyPermission struct {
bun.BaseModel `bun:"table:api_key_permissions,alias:akp" json:"-"`
ID string `bun:"id,pk" json:"id"`
APIKeyID string `bun:"api_key_id,notnull" json:"apiKeyId"`
Permission string `bun:"permission,notnull" json:"permission"`
CreatedAt time.Time `bun:"created_at,notnull" json:"createdAt"`
}
APIKeyPermission represents a permission granted to an API key.
type APIKeyShortURL ¶
type APIKeyShortURL struct {
bun.BaseModel `bun:"table:api_key_short_urls,alias:aksu" json:"-"`
ID string `bun:"id,pk" json:"id"`
APIKeyID string `bun:"api_key_id,notnull" json:"apiKeyId"`
ShortCode string `bun:"short_code,notnull,unique" json:"shortCode"`
ExpiresAt time.Time `bun:"expires_at,notnull" json:"expiresAt"`
CreatedAt time.Time `bun:"created_at,notnull" json:"createdAt"`
APIKey *APIKey `bun:"rel:belongs-to,join:api_key_id=id" json:"-"`
}
APIKeyShortURL represents a temporary short URL for eReader setup.
type CreateRequest ¶
type CreateRequest struct {
Name string `json:"name"`
}
CreateRequest is the payload for creating an API key.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) AddPermission ¶
func (s *Service) AddPermission(ctx context.Context, userID int, keyID string, permission string) (*APIKey, error)
AddPermission adds a permission to an API key.
func (*Service) ClearKoboSyncHistory ¶
ClearKoboSyncHistory deletes all Kobo sync points for an API key, forcing a fresh sync.
func (*Service) GenerateShortURL ¶
func (s *Service) GenerateShortURL(ctx context.Context, userID int, keyID string) (*APIKeyShortURL, error)
GenerateShortURL creates a temporary short URL for an API key.
func (*Service) RemovePermission ¶
func (s *Service) RemovePermission(ctx context.Context, userID int, keyID string, permission string) (*APIKey, error)
RemovePermission removes a permission from an API key.
func (*Service) ResolveShortCode ¶
ResolveShortCode looks up a short code and returns the associated API key.
func (*Service) TouchLastAccessed ¶
TouchLastAccessed updates the last_accessed_at timestamp for an API key.
type UpdateNameRequest ¶
type UpdateNameRequest struct {
Name string `json:"name"`
}
UpdateNameRequest is the payload for updating an API key's name.