store

package
v0.0.0-...-b325b5c Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package store contains methods and structures that we use to persist our data in the data store.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteCronJob

func DeleteCronJob(ctx context.Context, id int64) error

DeleteCronJob deletes the given cron job from the database.

func DeletePodcast

func DeletePodcast(ctx context.Context, podcast *Podcast) error

DeletePodcast deletes the podcast with the given ID. This should remove the podcast as well as all episodes, subscriptions and so on.

func DeleteSubscription

func DeleteSubscription(ctx context.Context, acct *Account, podcastID int64) error

DeleteSubscription deletes a subscription for the given podcast.

func GetBlobStorePath

func GetBlobStorePath(name string) (string, error)

GetBlobStorePath gets the path where we store blobs with the given name.

func GetCurrentSchemaVersion

func GetCurrentSchemaVersion(ctx context.Context) int

GetCurrentSchemaVersion gets the current version of the database schema. A completely fresh database will have version of 0.

func GetTimeToNextCronJob

func GetTimeToNextCronJob(ctx context.Context, now time.Time) time.Duration

Gets the time we need to wait until the next cron job. Maximum duration is 30 minutes.

func IsSubscribed

func IsSubscribed(ctx context.Context, acct *Account, podcastID int64) bool

IsSubscribed returns true if the given account is subscribed to the given podcast or not.

func LoadEpisodesNewAndInProgress

func LoadEpisodesNewAndInProgress(ctx context.Context, acct *Account, numDays int) (newEpisodes []*Episode, inProgress []*Episode, err error)

LoadEpisodesNewAndInProgress gets the new and in-progress episodes for the given account. In this case, new episodes are ones that don't have any progress at all (and only from the last numDays days). And of course, in-progress ones are ones that have progress but are not yet marked done. For in-progress episode, we don't just limit them to the last numDays days, we will return them all.

func LoadSubscriptionIDs

func LoadSubscriptionIDs(ctx context.Context, acct *Account) (map[int64]struct{}, error)

LoadSubscriptionIDs gets the ID of all the podcasts the given account is subscribed to.

func SaveCronJob

func SaveCronJob(ctx context.Context, job *CronJob) error

SaveCronJob saves the given cron job to the database.

func SaveEpisode

func SaveEpisode(ctx context.Context, p *Podcast, ep *Episode) error

SaveEpisode saves the given episode to the data store.

func SaveEpisodeProgress

func SaveEpisodeProgress(ctx context.Context, progress *EpisodeProgress) error

SaveEpisodeProgress saves the given EpisodeProgress to the database.

func SavePodcast

func SavePodcast(ctx context.Context, p *Podcast) (int64, error)

SavePodcast saves the given podcast to the store.

func SaveSubscription

func SaveSubscription(ctx context.Context, acct *Account, podcastID int64) error

SaveSubscription saves a new subscription to the data store.

func Setup

func Setup() error

func UpgradeSchema

func UpgradeSchema(ctx context.Context, currentVersion int) error

UpgradeSchema upgrades the current database schema to the latest version, starting from the given current version.

func VerifyUsernameExists

func VerifyUsernameExists(ctx context.Context, username string) (bool, error)

VerifyUsernameExists returns true if the given username exists or false if it does not exist. An error is returned if there is an error talking to the database.

Types

type Account

type Account struct {
	// A unique ID for this account.
	ID           int64
	Cookie       string
	Username     string
	PasswordHash []byte
}

Account ...

func LoadAccountByCookie

func LoadAccountByCookie(ctx context.Context, cookie string) (*Account, error)

LoadAccountByCookie loads the Account for the user with the given cookie. Returns an error if no account with that cookie exists.

func LoadAccountByUsername

func LoadAccountByUsername(ctx context.Context, username, password string) (*Account, error)

LoadAccountByUsername loads the Account for the user with the given username. Returns nil, nil if no account with that username exists.

func SaveAccount

func SaveAccount(ctx context.Context, username, password string) (*Account, error)

SaveAccount saves an account to the data store.

type CronJob

type CronJob struct {
	ID       int64
	Name     string
	Schedule string
	Enabled  bool
	NextRun  *time.Time
}

CronJob is a job that we want to run regularly.

func LoadCrobJob

func LoadCrobJob(ctx context.Context, id int64) (*CronJob, error)

LoadCronJob returns a single cron job with the given ID from the database.

func LoadCrobJobs

func LoadCrobJobs(ctx context.Context) ([]*CronJob, error)

LoadCronJobs returns all cron jobs in the database.

func LoadPendingCronJobs

func LoadPendingCronJobs(ctx context.Context, now time.Time) ([]*CronJob, error)

LoadPendingCronJobs all the cron jobs that are currently scheduled to run now.

type Episode

type Episode struct {
	ID               int64     `json:"id"`
	PodcastID        int64     `json:"podcastID"`
	GUID             string    `json:"-"`
	Title            string    `json:"title"`
	Description      string    `json:"description"`
	DescriptionHTML  bool      `json:"descriptionHtml"`
	ShortDescription string    `json:"shortDescription"`
	PubDate          time.Time `json:"pubDate"`
	MediaURL         string    `json:"mediaUrl"`

	// Position is the offset, in seconds, that the user is at for the episode. This will be null for
	// episodes that don't have any progress (either the user is not subscribed, or they haven't
	// started watching yet).
	Position *int32 `json:"position"`

	// IsComplete will be true if the user has fully listened to this episode.
	IsComplete *bool `json:"isComplete"`

	// LastListenTime is the last time you listened to this episode. Null if you haven't listened yet.
	LastListenTime *time.Time `json:"lastListenTime"`
}

Episode is a single episode in a podcast.

func GetMostRecentPlaybackState

func GetMostRecentPlaybackState(ctx context.Context, acct *Account) (*Episode, error)

func LoadEpisode

func LoadEpisode(ctx context.Context, p *Podcast, episodeID int64) (*Episode, error)

LoadEpisode gets the episode with the given ID for the given podcast.

func LoadEpisodes

func LoadEpisodes(ctx context.Context, podcastID int64, limit int) ([]*Episode, error)

LoadEpisodes loads all episodes for the given podcast, up to the given limit. If limit is < 0 then loads all episodes.

func LoadEpisodesForSubscription

func LoadEpisodesForSubscription(ctx context.Context, acct *Account, p *Podcast) ([]*Episode, error)

LoadEpisodesForSubscription gets the episodes to display for the given subscribed account. We'll return all episodes that the account has not finished listening to.

type EpisodeProgress

type EpisodeProgress struct {
	// PodcastID is the ID of the podcast this episode belongs to.
	AccountID int64

	// EpisodeID is the ID of the episode.
	EpisodeID int64

	// Position is the position, in seconds, that playback is up to. Negative means you've completely
	// finished the episode and we mark it "done".
	PositionSecs int32

	// EpisodeComplete is true when the user has marked this episode complete.
	EpisodeComplete bool

	// LastUpdated is the date/time this playback state was actually saved.
	LastUpdated time.Time
}

EpisodeProgress is the state of a single episode of a podcast for a given account.

type Podcast

type Podcast struct {
	// A unique ID for this podcast.
	ID int64 `json:"id"`

	// The title of the podcast.
	Title string `json:"title"`

	// The description of the podcast.
	Description string `json:"description"`

	// The URL of the title image for the podcast.
	ImageURL string `json:"imageUrl"`

	// If true, the image is external and we should link to it directly rather than as a blob.
	IsImageExternal bool `json:"isImageExternal"`

	// The path on disk to the file where we have the image for this podcast saved. This will be
	// null before we've fetched the image.
	ImagePath *string `json:"-"`

	// The URL of the podcast's RSS feed.
	FeedURL string `json:"feedUrl"`

	// The time that this podcast was last fetched When fetching the RSS feed again, we'll tell the
	// server to only give us new data if it has been changed since this time.
	LastFetchTime time.Time `json:"lastFetchTime"`

	// Episodes is the list of episodes that belong to this podcast.
	Episodes []*Episode `json:"episodes"`
}

Podcast is the parent entity for a podcast.

func GetSubscriptions

func GetSubscriptions(ctx context.Context, acct *Account) ([]*Podcast, error)

GetSubscriptions return the Podcasts that this account is subscribed to.

func LoadPodcast

func LoadPodcast(ctx context.Context, podcastID int64) (*Podcast, error)

LoadPodcast returns the podcast with the given ID.

func LoadPodcasts

func LoadPodcasts(ctx context.Context) ([]*Podcast, error)

LoadPodcasts loads all podcasts from the data store. TODO: support paging, filtering, sorting(?), etc.

Jump to

Keyboard shortcuts

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