Documentation ¶
Overview ¶
Package store contains methods and structures that we use to persist our data in the data store.
Index ¶
- func DeleteCronJob(ctx context.Context, id int64) error
- func DeletePodcast(ctx context.Context, podcast *Podcast) error
- func DeleteSubscription(ctx context.Context, acct *Account, podcastID int64) error
- func GetBlobStorePath(name string) (string, error)
- func GetCurrentSchemaVersion(ctx context.Context) int
- func GetTimeToNextCronJob(ctx context.Context, now time.Time) time.Duration
- func IsSubscribed(ctx context.Context, acct *Account, podcastID int64) bool
- func LoadEpisodesNewAndInProgress(ctx context.Context, acct *Account, numDays int) (newEpisodes []*Episode, inProgress []*Episode, err error)
- func LoadSubscriptionIDs(ctx context.Context, acct *Account) (map[int64]struct{}, error)
- func SaveCronJob(ctx context.Context, job *CronJob) error
- func SaveEpisode(ctx context.Context, p *Podcast, ep *Episode) error
- func SaveEpisodeProgress(ctx context.Context, progress *EpisodeProgress) error
- func SavePodcast(ctx context.Context, p *Podcast) (int64, error)
- func SaveSubscription(ctx context.Context, acct *Account, podcastID int64) error
- func Setup() error
- func UpgradeSchema(ctx context.Context, currentVersion int) error
- func VerifyUsernameExists(ctx context.Context, username string) (bool, error)
- type Account
- type CronJob
- type Episode
- func GetMostRecentPlaybackState(ctx context.Context, acct *Account) (*Episode, error)
- func LoadEpisode(ctx context.Context, p *Podcast, episodeID int64) (*Episode, error)
- func LoadEpisodes(ctx context.Context, podcastID int64, limit int) ([]*Episode, error)
- func LoadEpisodesForSubscription(ctx context.Context, acct *Account, p *Podcast) ([]*Episode, error)
- type EpisodeProgress
- type Podcast
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteCronJob ¶
DeleteCronJob deletes the given cron job from the database.
func DeletePodcast ¶
DeletePodcast deletes the podcast with the given ID. This should remove the podcast as well as all episodes, subscriptions and so on.
func DeleteSubscription ¶
DeleteSubscription deletes a subscription for the given podcast.
func GetBlobStorePath ¶
GetBlobStorePath gets the path where we store blobs with the given name.
func GetCurrentSchemaVersion ¶
GetCurrentSchemaVersion gets the current version of the database schema. A completely fresh database will have version of 0.
func GetTimeToNextCronJob ¶
Gets the time we need to wait until the next cron job. Maximum duration is 30 minutes.
func IsSubscribed ¶
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 ¶
LoadSubscriptionIDs gets the ID of all the podcasts the given account is subscribed to.
func SaveCronJob ¶
SaveCronJob saves the given cron job to the database.
func SaveEpisode ¶
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 ¶
SavePodcast saves the given podcast to the store.
func SaveSubscription ¶
SaveSubscription saves a new subscription to the data store.
func UpgradeSchema ¶
UpgradeSchema upgrades the current database schema to the latest version, starting from the given current version.
Types ¶
type Account ¶
type Account struct { // A unique ID for this account. ID int64 Cookie string Username string PasswordHash []byte }
Account ...
func LoadAccountByCookie ¶
LoadAccountByCookie loads the Account for the user with the given cookie. Returns an error if no account with that cookie exists.
func LoadAccountByUsername ¶
LoadAccountByUsername loads the Account for the user with the given username. Returns nil, nil if no account with that username exists.
type CronJob ¶
CronJob is a job that we want to run regularly.
func LoadCrobJob ¶
LoadCronJob returns a single cron job with the given ID from the database.
func LoadCrobJobs ¶
LoadCronJobs returns all cron jobs in the database.
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 LoadEpisode ¶
LoadEpisode gets the episode with the given ID for the given podcast.
func LoadEpisodes ¶
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 ¶
GetSubscriptions return the Podcasts that this account is subscribed to.
func LoadPodcast ¶
LoadPodcast returns the podcast with the given ID.