76 lines
4.2 KiB
Go
76 lines
4.2 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/bluesky-social/indigo/api/bsky"
|
|
"github.com/bluesky-social/indigo/atproto/syntax"
|
|
"github.com/nacorid/naco-api/internal/activitypub"
|
|
"github.com/nacorid/naco-api/internal/actor"
|
|
"github.com/nacorid/naco-api/internal/clustering"
|
|
"github.com/nacorid/naco-api/internal/nostr"
|
|
"github.com/nacorid/naco-api/internal/store"
|
|
"github.com/nacorid/naco-api/internal/twitter"
|
|
)
|
|
|
|
// The following interfaces let the server depend on platform behaviour rather than on the
|
|
// concrete client types. They exist so tests can inject fake backends; the production code in
|
|
// main.go keeps passing the real clients (which satisfy these interfaces).
|
|
|
|
type blueskyBackend interface {
|
|
GetPost(ctx context.Context, actor, collection, recordKey string) (*bsky.FeedDefs_PostView, error)
|
|
GetLatestNPosts(ctx context.Context, actor string, limit int) ([]*bsky.FeedDefs_FeedViewPost, error)
|
|
GetPostsInTimeframe(ctx context.Context, actor string, start, end time.Time, limit int) ([]*bsky.FeedDefs_FeedViewPost, error)
|
|
GetFeed(ctx context.Context, feedURI string, limit int) (*bsky.FeedGetFeed_Output, error)
|
|
ResolveUser(ctx context.Context, user string) (syntax.DID, error)
|
|
GetActor(ctx context.Context, author string) (*actor.Profile, error)
|
|
SearchActors(ctx context.Context, query string, limit int) ([]*actor.Profile, error)
|
|
}
|
|
|
|
type apBackend interface {
|
|
GetPost(ctx context.Context, postID string) (*activitypub.Post, error)
|
|
GetLatestNPosts(ctx context.Context, actor string, limit int) ([]*activitypub.Post, error)
|
|
GetPostsInTimeframe(ctx context.Context, actor string, start, end time.Time, limit int) ([]*activitypub.Post, error)
|
|
GetActor(ctx context.Context, author string) (*actor.Profile, error)
|
|
SearchActors(ctx context.Context, query string, limit int) ([]*actor.Profile, error)
|
|
}
|
|
|
|
type nostrBackend interface {
|
|
GetPost(ctx context.Context, id string) (*nostr.Post, error)
|
|
GetLatestNPosts(ctx context.Context, actor string, limit int) ([]*nostr.Post, error)
|
|
GetPostsInTimeframe(ctx context.Context, actor string, start, end time.Time, limit int) ([]*nostr.Post, error)
|
|
GetActor(ctx context.Context, author string) (*actor.Profile, error)
|
|
SearchActors(ctx context.Context, query string, limit int) ([]*actor.Profile, error)
|
|
}
|
|
|
|
type twitterBackend interface {
|
|
GetPost(ctx context.Context, id string) (*twitter.Post, error)
|
|
GetLatestNPosts(ctx context.Context, actor string, limit int) ([]*twitter.Post, error)
|
|
GetPostsInTimeframe(ctx context.Context, actor string, start, end time.Time, limit int) ([]*twitter.Post, error)
|
|
}
|
|
|
|
type ollamaBackend interface {
|
|
EmbedTexts(ctx context.Context, posts []clustering.Item) ([][]float64, error)
|
|
SummarizeStyle(ctx context.Context, posts []clustering.Item) (string, error)
|
|
}
|
|
|
|
// Store abstracts the persistence layer the server depends on. *store.Queries satisfies it;
|
|
// tests inject an in-memory fake so db-backed paths (style profiles, analytics, similar users)
|
|
// can be exercised without a live Postgres.
|
|
type Store interface {
|
|
GetAnalyticsCache(ctx context.Context, arg store.GetAnalyticsCacheParams) (json.RawMessage, error)
|
|
UpsertAnalyticsCache(ctx context.Context, arg store.UpsertAnalyticsCacheParams) error
|
|
GetAnalyticsPostsInRange(ctx context.Context, arg store.GetAnalyticsPostsInRangeParams) ([]store.GetAnalyticsPostsInRangeRow, error)
|
|
UpsertAnalyticsPosts(ctx context.Context, arg store.UpsertAnalyticsPostsParams) error
|
|
GetAnalyticsCoverageRanges(ctx context.Context, arg store.GetAnalyticsCoverageRangesParams) ([]store.GetAnalyticsCoverageRangesRow, error)
|
|
InsertAnalyticsCoverageRange(ctx context.Context, arg store.InsertAnalyticsCoverageRangeParams) error
|
|
GetStyleProfile(ctx context.Context, arg store.GetStyleProfileParams) (store.UserStyleProfile, error)
|
|
UpsertStyleProfile(ctx context.Context, arg store.UpsertStyleProfileParams) error
|
|
DeleteStylePosts(ctx context.Context, arg store.DeleteStylePostsParams) error
|
|
GetStylePosts(ctx context.Context, arg store.GetStylePostsParams) ([]store.GetStylePostsRow, error)
|
|
UpsertStylePosts(ctx context.Context, arg store.UpsertStylePostsParams) error
|
|
FindSimilarUsers(ctx context.Context, arg store.FindSimilarUsersParams) ([]store.FindSimilarUsersRow, error)
|
|
PruneStylePosts(ctx context.Context) error
|
|
}
|