mirror of
				https://github.com/nkanaev/yarr.git
				synced 2025-10-30 22:43:29 +00:00 
			
		
		
		
	podcasts
This commit is contained in:
		| @@ -55,6 +55,7 @@ type Item struct { | ||||
| 	DateUpdated *time.Time `json:"date_updated"` | ||||
| 	Status      ItemStatus `json:"status"` | ||||
| 	Image       string     `json:"image"` | ||||
| 	PodcastURL  string     `json:"podcast_url"` | ||||
| } | ||||
|  | ||||
| type ItemFilter struct { | ||||
| @@ -91,15 +92,15 @@ func (s *Storage) CreateItems(items []Item) bool { | ||||
| 				guid, feed_id, title, link, description, | ||||
| 				content, author, | ||||
| 				date, date_updated, date_arrived, | ||||
| 				status, image | ||||
| 				status, image, podcast_url | ||||
| 			) | ||||
| 			values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) | ||||
| 			values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) | ||||
| 			on conflict (feed_id, guid) do update set | ||||
| 			date_updated = ?, date_arrived = ?`, | ||||
| 			item.GUID, item.FeedId, html.UnescapeString(item.Title), item.Link, item.Description, | ||||
| 			item.Content, item.Author, | ||||
| 			item.Date, item.DateUpdated, now, | ||||
| 			UNREAD, item.Image, | ||||
| 			UNREAD, item.Image, item.PodcastURL, | ||||
| 			// upsert values | ||||
| 			item.DateUpdated, now, | ||||
| 		) | ||||
| @@ -165,7 +166,7 @@ func (s *Storage) ListItems(filter ItemFilter, offset, limit int, newestFirst bo | ||||
| 	query := fmt.Sprintf(` | ||||
| 		select | ||||
| 			i.id, i.guid, i.feed_id, i.title, i.link, i.description, | ||||
| 			i.content, i.author, i.date, i.date_updated, i.status, i.image | ||||
| 			i.content, i.author, i.date, i.date_updated, i.status, i.image, i.podcast_url | ||||
| 		from items i | ||||
| 		join feeds f on f.id = i.feed_id | ||||
| 		where %s | ||||
| @@ -192,6 +193,7 @@ func (s *Storage) ListItems(filter ItemFilter, offset, limit int, newestFirst bo | ||||
| 			&x.DateUpdated, | ||||
| 			&x.Status, | ||||
| 			&x.Image, | ||||
| 			&x.PodcastURL, | ||||
| 		) | ||||
| 		if err != nil { | ||||
| 			s.log.Print(err) | ||||
|   | ||||
| @@ -10,13 +10,14 @@ var migrations = []func(*sql.Tx)error{ | ||||
| 	m00_initial, | ||||
| 	m01_feed_states_and_errors, | ||||
| 	m02_on_delete_actions, | ||||
| 	m03_item_podcasturl, | ||||
| } | ||||
|  | ||||
| var maxVersion = int64(len(migrations)) | ||||
|  | ||||
| func migrate(db *sql.DB, log *log.Logger) error { | ||||
| 	var version int64 | ||||
| 	db.QueryRow("pragma user_version").Scan(&version);	 | ||||
| 	db.QueryRow("pragma user_version").Scan(&version); | ||||
|  | ||||
| 	if version >= maxVersion { | ||||
| 		return nil | ||||
| @@ -37,7 +38,7 @@ func migrate(db *sql.DB, log *log.Logger) error { | ||||
| 		if err = migratefunc(tx); err != nil { | ||||
| 			log.Printf("[migration:%d] failed to migrate", v) | ||||
| 			tx.Rollback() | ||||
| 			return err	 | ||||
| 			return err | ||||
| 		} | ||||
| 		if _, err = tx.Exec(fmt.Sprintf("pragma user_version = %d", v + 1)); err != nil { | ||||
| 			log.Printf("[migration:%d] failed to bump version", v) | ||||
| @@ -109,7 +110,7 @@ func m00_initial(tx *sql.Tx) error { | ||||
| 		  delete from search where rowid = old.search_rowid; | ||||
| 		end; | ||||
| 	` | ||||
| 	_, err := tx.Exec(sql)	 | ||||
| 	_, err := tx.Exec(sql) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| @@ -210,3 +211,11 @@ func m02_on_delete_actions(tx *sql.Tx) error { | ||||
| 	_, err := tx.Exec(sql) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| func m03_item_podcasturl(tx *sql.Tx) error { | ||||
| 	sql := ` | ||||
| 		alter table items add column podcast_url text | ||||
| 	` | ||||
| 	_, err := tx.Exec(sql) | ||||
| 	return err | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user