diff --git a/README.md b/README.md index 7f04c6c..152a912 100644 --- a/README.md +++ b/README.md @@ -65,9 +65,16 @@ $ gpodder2go serve --no-auth Alternatively, you can switch to use [Antennapod](https://antennapod.org/) which has implemented the login spec which gpodder2go currently supports. -### Supports +### Supported Clients -- [Antennapod](https://antennapod.org/) +#### [Antennapod](https://antennapod.org/) + +These features are all working with Antennapod: + - Authentication API + - Subscriptions API + - Episode Actions API + - Device API + - Device Synchronization API ### Development diff --git a/go.mod b/go.mod index 3c12660..017e5c9 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ require ( github.com/spf13/cobra v1.4.0 k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b modernc.org/sqlite v1.26.0 - github.com/relvacode/iso8601 v1.3.0 ) require ( diff --git a/go.sum b/go.sum index f0f9292..9bcf121 100644 --- a/go.sum +++ b/go.sum @@ -971,8 +971,6 @@ github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= -github.com/relvacode/iso8601 v1.3.0 h1:HguUjsGpIMh/zsTczGN3DVJFxTU/GX+MMmzcKoMO7ko= -github.com/relvacode/iso8601 v1.3.0/go.mod h1:FlNp+jz+TXpyRqgmM7tnzHHzBnz776kmAH2h3sZCn0I= github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= diff --git a/pkg/data/sqlite.go b/pkg/data/sqlite.go index f7126df..e78217a 100644 --- a/pkg/data/sqlite.go +++ b/pkg/data/sqlite.go @@ -140,17 +140,11 @@ func (s *SQLite) RetrieveDevices(username string) ([]Device, error) { func (l *SQLite) AddEpisodeActionHistory(username string, e EpisodeAction) error { db := l.db - tx, err := db.Begin() - if err != nil { - return err - } - _, err = tx.Exec("INSERT INTO episode_actions(device_id, podcast, episode, action, position, started, total, timestamp) VALUES (?,?,?,?,?,?,?,?)", e.Device, e.Podcast, e.Episode, e.Action, e.Position, e.Started, e.Total, e.Timestamp.Unix()) + _, err := db.Exec("INSERT INTO episode_actions(device_id, podcast, episode, action, position, started, total, timestamp) VALUES (?,?,?,?,?,?,?,?)", e.Device, e.Podcast, e.Episode, e.Action, e.Position, e.Started, e.Total, e.Timestamp.Unix()) if err != nil { - tx.Rollback() return err } - tx.Commit() return nil } @@ -161,14 +155,8 @@ func (l *SQLite) RetrieveEpisodeActionHistory(username string, deviceId string, query := "SELECT a.podcast, a.episode, a.device_id, a.action, a.position, a.started, a.total, a.timestamp" query = query + " FROM episode_actions as a, devices as d, users as u" - query = query + " WHERE a.device_id = d.name AND d.user_id = u.id AND u.username = ?" - var args []interface{} - args = append(args, username) - if !since.IsZero() { - query = query + " AND a.timestamp > ?" - args = append(args, since) - } - query = query + " ORDER BY a.id" + query = query + " WHERE a.device_id = d.name AND d.user_id = u.id AND u.username = ? ORDER BY a.id" + args := []interface{}{username} rows, err := db.Query(query, args...) if err != nil { return nil, err @@ -200,8 +188,20 @@ func (l *SQLite) RetrieveEpisodeActionHistory(username string, deviceId string, timestamp.Time = time.Unix(g, 0) a.Timestamp = timestamp - actions = append(actions, a) + // For some reason, the timestamp for episode actions has been stored as + // an integer, but in a field of type varchar(255). (that's why you see + // the ParseInt call above). So we cannot use a DB query to sort or + // filter by timestamp, because the DB would sort the integers + // alphabetically. Someone should probably fix that by making a + // migration to change the timestamp type in the DB, and then let the DB + // handle the filtering. + if !since.IsZero() { + if a.Timestamp.Before(since) { + continue + } + } + actions = append(actions, a) } return actions, nil diff --git a/pkg/data/types.go b/pkg/data/types.go index 394456c..19e686a 100644 --- a/pkg/data/types.go +++ b/pkg/data/types.go @@ -38,7 +38,7 @@ type Subscription struct { Devices []int `json:"devices"` Podcast string `json:"podcast"` Action string `json:"action"` - Timestamp CustomTimestamp `json:"timestamp"` + Timestamp CustomTimestamp `json:"timestamp"` // sqlite stores this as a varchar(255) } type Device struct {