service

package
v0.166.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2026 License: AGPL-3.0 Imports: 53 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFeed added in v0.128.0

func AddFeed(ctx context.Context, feed *models.Feed) error

AddFeed adds a new feed to Elasticsearch and the cache.

func AddItems added in v0.131.2

func AddItems(ctx context.Context, items models.Items) (map[string]models.Items, error)

AddItems wraps an elastic bulk update to index items.

func AddSubscriptions

func AddSubscriptions(ctx context.Context, subscriptions ...*models.Subscription) error

AddSubscriptions adds the given subscriptions to a user.

func BuildItemQueries

func BuildItemQueries(
	user *models.User,
	view models.View,
	subscriptions models.Subscriptions,
) []query.Option

BuildItemQueries generates a slices of queries for the given subscriptions, based on the given filters.

func BuildSearchResultsQuery added in v0.128.0

func BuildSearchResultsQuery(
	ctx context.Context,
	user *models.User,
	request *models.SearchRequest,
	clause query.BoolOption,
) (query.Option, error)

BuildSearchResultsQuery generates a query that can be used to fetch appropriate results for a given SearchRequest criteria.

func BulkImportFeeds

func BulkImportFeeds(ctx context.Context, requests ...models.FeedSubscriptionRequest) []models.FeedSubscriptionResult

BulkImportFeeds handles processing any number of NewFeedSubscriptionRequest requests.

func CheckUserLimits added in v0.151.0

func CheckUserLimits(ctx context.Context) error

func CountItems added in v0.131.2

func CountItems(ctx context.Context, query query.Option) (int64, error)

CountItems returns a count of items that match the given query.

func CreateSearchSubscriptions

func CreateSearchSubscriptions(ctx context.Context, requests ...*models.SearchSubscriptionRequest) error

CreateSearchSubscriptions will create new SearchSubscriptions for the user from the given requests.

func DeleteUser added in v0.143.0

func DeleteUser(ctx context.Context, user *models.User) error

DeleteUser deletes the user and the user's subscription objects from Elasticsearch.

func ElasticsearchToAPIError added in v0.132.2

func ElasticsearchToAPIError(err error) error

ElasticsearchToAPIError will extract and wrap a types.ElasticsearchError from the given error, in an APIError containing its pertinent information. If the given error does not contain types.ElasticsearchError, the given error is wrapped in a generic APIError is created.

func ExtractFavicon added in v0.147.1

func ExtractFavicon(ctx context.Context, rawURL string) (string, error)

ExtractFavicon will attempt to extract a URL to what is likely the favicon of a page.

func ExtractMainImage added in v0.147.1

func ExtractMainImage(ctx context.Context, rawURL string) (string, error)

ExtractMainImage will attempt to extract a URL to what is likely the "main" image of a page (i.e., typically used on article/post pages).

func FetchFeed added in v0.147.0

func FetchFeed(ctx context.Context, feedURL string, options ...FetchOption) (*models.Feed, error)

FetchFeed retrieves the feed found at the given URL.

func FilterArticles added in v0.128.0

func FilterArticles(
	ctx context.Context,
	request *models.ListRequest,
) (models.Articles, models.Pagination, error)

FilterArticles returns Articles filtered by the given filters and paginated by the given pagination.

func FindOrCreateFeed added in v0.147.0

func FindOrCreateFeed(ctx context.Context, feedURL string) (*models.Feed, bool, error)

FindOrCreateFeed will either generate a new feed or return the existing feed for the given URL. If the feed is new, the boolean return value will be true.

func FindSimilarArticles added in v0.128.0

func FindSimilarArticles(ctx context.Context, count int, itemIDs ...models.ItemID) (models.Articles, error)

FindSimilarArticles performs a "more like this" search to find other Articles that are similar to the Items with the given IDs.

func GenerateArticles added in v0.128.0

func GenerateArticles(ctx context.Context, items models.Items) (models.Articles, error)

GenerateArticles takes a slice of items and creates articles from them, grabbing the necessary data from the user object.

func GenerateOPML added in v0.152.0

func GenerateOPML(ctx context.Context, feedIDs ...models.FeedID) ([]byte, error)

GenerateOPML generates an OPML file of the feeds listed by the given IDs.

func GetAllSubscriptions added in v0.128.0

func GetAllSubscriptions(
	ctx context.Context,
) (models.Subscriptions, error)

GetAllSubscriptions returns all subscriptions for the given user.

func GetArticleRemoteContent added in v0.147.0

func GetArticleRemoteContent(ctx context.Context, article *models.Article) error

GetArticleRemoteContent attempts to fetch remote content for an article. It will check if the remote content has already been fetched and cached in GCS and use that content. Otherwise, it uses the Zyte API to fetch the remote content and then cache it for reuse.

func GetArticles added in v0.128.0

func GetArticles(ctx context.Context, itemIDs ...models.ItemID) (models.Articles, error)

GetArticles generates Article objects from the Items with the given IDs.

func GetCategoriesForSubscriptions added in v0.128.0

func GetCategoriesForSubscriptions(
	ctx context.Context,
	subscriptionIDs ...models.SubscriptionID,
) (models.CategoryCounts, error)

func GetEmailSubscription

func GetEmailSubscription(ctx context.Context, user *models.User, from *mail.Address) (*models.Subscription, error)

GetEmailSubscription retrieves an EmailSubscription for the given user ID and email sender.

func GetFeed added in v0.132.0

func GetFeed(ctx context.Context, id models.FeedID) (*models.Feed, error)

GetFeed retrieves a feed with the given FeedID.

func GetFeedLatestItems added in v0.128.0

func GetFeedLatestItems(
	ctx context.Context,
	count int,
	feedIDs []models.FeedID,
	extraQuery query.Option,
) (map[models.FeedID]models.Items, error)

GetFeedLatestItems fetches the most recent count items for each given feed. An optional query clause can be specified that will be added to the bool filter clause of the query to apply additional filtering to the items.

func GetFeeds added in v0.132.0

func GetFeeds(ctx context.Context, ids ...models.FeedID) (models.Feeds, error)

GetFeeds retrieves the Feeds matching the given FeedIDs. It will fetch any cached versions before fetching from Elasticsearch (and then caching those).

func GetItems added in v0.131.2

func GetItems(ctx context.Context, ids ...models.ItemID) (models.Items, error)

GetItems retrieves the Items matching the given ItemIDs.

func GetLatestItems added in v0.144.0

func GetLatestItems(ctx context.Context, view models.View, subscriptions models.Subscriptions) *sync.Map

func GetSubscription added in v0.128.0

func GetSubscription(
	ctx context.Context,
	id models.SubscriptionID,
) (*models.Subscription, error)

GetSubscription returns the subscription that matches the given ID for the given user.

func GetSubscriptionSuggestions added in v0.128.0

func GetSubscriptionSuggestions(
	ctx context.Context,
	text string,
	count int,
	ignoredSubscriptions []models.SubscriptionID,
) (models.Subscriptions, error)

GetSubscriptionSuggestions returns subscriptions that match the given text. A set of ids can be optionally passed to ignore those subscriptions.

func GetSubscriptionsByID added in v0.131.2

func GetSubscriptionsByID(
	ctx context.Context,
	ids ...models.SubscriptionID,
) (models.Subscriptions, error)

GetSubscriptionsByID returns all subscriptions that match the given SubscriptionIDs.

func GetTopCategoriesForItems added in v0.132.2

func GetTopCategoriesForItems(ctx context.Context, itemsQuery query.Option) (models.CategoryCounts, error)

func GetUser

func GetUser(ctx context.Context, id models.UserID) (*models.User, error)

GetUser retrieves the user doc with the given id.

func GetUserByEmail

func GetUserByEmail(ctx context.Context, email string) (*models.User, error)

GetUserByEmail will retrieve a user by their email.

func GetUserByExternalID

func GetUserByExternalID(ctx context.Context, externalID string) (*models.User, error)

GetUserByExternalID will search for and return a user that matches the given external ID, if exists.

func GetUserBySubscriptionEmail

func GetUserBySubscriptionEmail(ctx context.Context, emails ...string) (*models.User, error)

GetUserBySubscriptionEmail will retrieve a user from their Foragd newsletter subscription email.

func GetUserBySubscriptionID added in v0.143.0

func GetUserBySubscriptionID(ctx context.Context, id string) (*models.User, error)

GetUserBySubscriptionID will retrieve a user from their payment subscription ID.

func ListFiltersFromCtx

func ListFiltersFromCtx(ctx context.Context) models.ListFilters

ListFiltersFromCtx retrieves list filters from the context. If none are found, new list filters are returned.

func ListFiltersToCtx

func ListFiltersToCtx(ctx context.Context, filters models.ListFilters) context.Context

ListFiltersToCtx stores list filters in the context.

func MarkSubscriptions added in v0.127.1

func MarkSubscriptions(
	ctx context.Context,
	mark models.Mark,
	subscriptionIDs ...models.SubscriptionID,
) error

MarkSubscriptions will mark as appropriate all the given subscriptions. Marking a subscription includes updating the subscription data in the user object and clearing any individual item states for a subscription.

func NewEmailItem added in v0.147.1

func NewEmailItem(email models.Email, subscription *models.Subscription) *models.Item

NewEmailItem generates a new Item from an email.

func NewFeed added in v0.147.1

func NewFeed(url string, id models.FeedID, source *feeds.Feed) *models.Feed

NewFeed converts a feed source from the go-syndication library into a models.Feed object.

func NewFeedItem added in v0.147.1

func NewFeedItem(source *feeds.Item, feed *models.Feed) *models.Item

NewFeedItem generates an Item from the underlying feed data.

func NewFeedSortCombinations added in v0.160.0

func NewFeedSortCombinations(sort *models.Sort) []estypes.SortCombinations

func NewFeedSortOptions added in v0.160.0

func NewFeedSortOptions(sort *models.Sort) []estypes.SortCombinationsVariant

func NewItemSortCombinations added in v0.132.2

func NewItemSortCombinations(sort *models.Sort) []estypes.SortCombinations

func NewItemSortOptions added in v0.132.2

func NewItemSortOptions(sort *models.Sort) []estypes.SortCombinationsVariant

func RemoveSubscriptions

func RemoveSubscriptions(ctx context.Context, ids ...models.SubscriptionID) error

RemoveSubscriptions removes subscriptions with the given ID from a user.

func SearchItems added in v0.131.2

func SearchItems(
	ctx context.Context,
	query query.Option,
	count int,
	sort *models.Sort,
	pagination *models.Pagination,
) (models.Items, models.Pagination, error)

SearchItems will search the items index for items matching the given query. Count, sort and pagination values are optional.

func SuggestFeeds added in v0.133.0

func SuggestFeeds(ctx context.Context, text string) (*models.FeedSuggestionsResults, error)

SuggestFeeds returns a feeds and their latest articles that match the given text. It will search first for existing feeds in Elasticsearch. If the given text is a URL, it will fallback to searching the website for a feed.

func SuggestGoogleNewsFeeds added in v0.154.0

func SuggestGoogleNewsFeeds(ctx context.Context, text string) (*models.FeedSuggestionsResults, error)

SuggestGoogleNewsFeeds will return a google news RSS feed for the given search query.

func SuggestYoutubeFeeds added in v0.133.0

func SuggestYoutubeFeeds(ctx context.Context, text string) (*models.FeedSuggestionsResults, error)

SuggestYoutubeFeeds will return a list of youtube feeds that match the given text.

func SyncUser added in v0.142.3

func SyncUser(ctx context.Context, localUser *models.User)

SyncUser tries to sync relevant user data from the auth backend to the local data.

func UpdateFavoriteSubscription added in v0.127.1

func UpdateFavoriteSubscription(ctx context.Context, id models.SubscriptionID, favorite bool) error

UpdateFavoriteSubscription changes the favorite status of a subscription by updating the user object to flag the subscription as appropriate.

func UpdateFeed added in v0.128.0

func UpdateFeed(ctx context.Context, id models.FeedID, updates map[string]any) error

UpdateFeed applies the given updates to a Feed. Any cached version of the feed is invalidated.

func UpdateFeedDetails added in v0.142.3

func UpdateFeedDetails(ctx context.Context, oldData, newData *models.Feed, lastFetched time.Time) error

UpdateFeedDetails takes a copy of a feed that has been recently fetched/refreshed and checks/updates various fields. If there are updates, these are then saved.

func UpdateSubscriptionDynamicInfo added in v0.142.1

func UpdateSubscriptionDynamicInfo(ctx context.Context, subscriptions models.Subscriptions) error

UpdateSubscriptionDynamicInfo adds dynamically generated information (e.g., unread count, stats, etc.) to subscriptions. At the least, all subscriptions will have an unread count and last updated info generated. Other stats will also be generated if the user has set the display option ShowSubscriptionStats in their account settings.

func UpdateSubscriptions added in v0.127.1

func UpdateSubscriptions(
	ctx context.Context,
	subscriptions ...*models.Subscription,
) (map[models.SubscriptionID]*bulk.OperationResponse, error)

UpdateSubscriptions will bulk update the given subscriptions in Elasticsearch.

func UpdateUser

func UpdateUser(ctx context.Context, user *models.User, updates map[string]any) error

UpdateUser will apply the given updates to the user.

Types

type FeedSorting added in v0.160.0

type FeedSorting struct {
	Updated   string `json:"updated"`
	Published string `json:"published"`
	FeedID    string `json:"feed_id"`
}

FeedSorting contains the sort options for sorting item search results.

func (*FeedSorting) SortCombinationsCaster added in v0.160.0

func (s *FeedSorting) SortCombinationsCaster() *estypes.SortCombinations

SortCombinationsCaster is required to allow FeedSorting to be used as Elasticsearch sort values.

type FetchOption added in v0.148.1

type FetchOption func(*FetchOptions)

FetchOption is a functional option that controls some aspect of how a feed will be fetched.

func FetchWithFeedID added in v0.147.0

func FetchWithFeedID(id models.FeedID) FetchOption

FetchWithFeedID assigns the given FeedID to the feed object.

func FetchWithProxy added in v0.147.0

func FetchWithProxy(value bool) FetchOption

FetchWithProxy option will ensure the fetch feed request is proxied.

type FetchOptions added in v0.147.0

type FetchOptions struct {
	Proxy  bool
	FeedID models.FeedID
}

FetchOptions defines options that manipulate how a feed will be fetched from a remote URL.

type ItemSorting added in v0.132.2

type ItemSorting struct {
	Published string `json:"published"`
	Updated   string `json:"updated"`
	ItemID    string `json:"item_id"`
}

ItemSorting contains the sort options for sorting item search results.

func (*ItemSorting) SortCombinationsCaster added in v0.132.2

func (s *ItemSorting) SortCombinationsCaster() *estypes.SortCombinations

SortCombinationsCaster is required to allow ItemSorting to be used as Elasticsearch sort values.

type SubscriptionSorting added in v0.128.0

type SubscriptionSorting struct {
	MarkedReadAt   string `json:"marked_read_at"`
	SubscriptionID string `json:"subscription_id"`
}

SubscriptionSorting contains the sort options for sorting subscription results.

func (*SubscriptionSorting) SortCombinationsCaster added in v0.128.0

func (s *SubscriptionSorting) SortCombinationsCaster() *types.SortCombinations

SortCombinationsCaster is required to allow FeedSorting to be used as Elasticsearch sort values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL