Documentation
¶
Overview ¶
Package httpapi serves the RoNote HTTP API.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Accounts ¶
type Accounts interface {
SignIn(ctx context.Context, id store.Identity) (store.User, error)
GetAccount(ctx context.Context, user uuid.UUID, provider string) (store.Account, error)
CreateSession(ctx context.Context, hash []byte, user uuid.UUID, lifetime time.Duration) error
GetSession(ctx context.Context, hash []byte, idle, touch time.Duration) (store.Session, error)
TouchSession(ctx context.Context, hash []byte) error
DeleteSession(ctx context.Context, hash []byte) error
DeleteUserSessions(ctx context.Context, user uuid.UUID) error
DeleteUser(ctx context.Context, user uuid.UUID) error
}
Accounts is where sign-in keeps users and sessions. *store.Store implements it; it is an interface so handler tests can run without a database.
type Backend ¶
type Backend interface {
Request(ctx context.Context, owner uuid.UUID, rawURL string) (importer.Requested, error)
RequestPDF(ctx context.Context, owner uuid.UUID, filename string, file io.ReadSeeker, size int64) (importer.Requested, error)
Original(ctx context.Context, owner, id uuid.UUID) (string, *blob.Object, error)
GetImport(ctx context.Context, owner, id uuid.UUID) (store.Import, error)
GetDocument(ctx context.Context, owner, id uuid.UUID) (store.Document, error)
DocumentExtraction(ctx context.Context, owner, id uuid.UUID) (*ir.Doc, error)
SaveDocument(ctx context.Context, owner, id uuid.UUID, content *doccontent.Doc, version int) (int, error)
DeleteDocument(ctx context.Context, owner, id uuid.UUID) ([]uuid.UUID, error)
ListDocuments(ctx context.Context, owner uuid.UUID, after *store.DocumentCursor, limit int) ([]store.DocumentSummary, error)
ResolveDocuments(ctx context.Context, owner uuid.UUID, urls []string) (map[string]uuid.UUID, error)
ListAnnotations(ctx context.Context, owner, document uuid.UUID) ([]store.Annotation, error)
CreateAnnotation(ctx context.Context, owner, document uuid.UUID, a store.NewAnnotation) (store.Annotation, error)
UpdateAnnotation(ctx context.Context, owner, id uuid.UUID, change store.AnnotationChange) (store.Annotation, error)
ReanchorAnnotations(ctx context.Context, owner, document uuid.UUID, moves []store.Reanchor) ([]store.Annotation, error)
DeleteAnnotation(ctx context.Context, owner, id uuid.UUID) error
}
Backend is what /api/v1 reads and writes through: the import service and the store, scoped to the signed-in user. It is an interface so handler tests can run without a database.
type Events ¶
Events is where event streams hear about status changes. *events.Broker implements it; it is an interface so handler tests can drive it.
type Limits ¶
type Limits struct {
// APIPerMinute counts one user's requests, the import event stream
// excepted.
APIPerMinute int
// AuthPerMinute counts one IP's requests to /api/v1/auth.
AuthPerMinute int
}
Limits are the API's rate limits; zero means none (docs/adr/0010-sign-in-and-sessions.md).
type Options ¶
type Options struct {
// Logger logs requests and panics.
Logger *slog.Logger
// DB answers /readyz.
DB Pinger
// Backend serves /api/v1.
Backend Backend
// Events feeds the import event streams.
Events Events
// Done closes when the server begins to shut down, which ends event
// streams so the shutdown need not wait for their clients.
Done <-chan struct{}
// Accounts keeps users and their sessions.
Accounts Accounts
// Cookies carry sessions and sign-ins in progress.
Cookies auth.Cookies
// GitHub is where people sign in.
GitHub auth.GitHub
// PublicURL is RoNote's origin, the one origin trusted to send unsafe
// requests from another site.
PublicURL string
// Limits are the rate limits.
Limits Limits
// TrustedProxies may say, in X-Forwarded-For, which client a request
// is from.
TrustedProxies Proxies
// Searcher searches users' libraries; ShowScores puts each result's
// scores in the answer, in dev and test.
Searcher Searcher
ShowScores bool
// Chat answers questions over a user's library; nil, or turned off,
// answers its routes with 503.
Chat *chat.Service
}
Options are what the API handler serves with.