mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
remove item.date_updated, item.description & item.author fields in storage
This commit is contained in:
parent
ecdfcb5017
commit
6acf9af887
@ -248,7 +248,6 @@ func (s *Server) handleItem(c *router.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
item.Content = sanitizer.Sanitize(item.Link, item.Content)
|
item.Content = sanitizer.Sanitize(item.Link, item.Content)
|
||||||
item.Description = sanitizer.Sanitize(item.Link, item.Description)
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, item)
|
c.JSON(http.StatusOK, item)
|
||||||
} else if c.Req.Method == "PUT" {
|
} else if c.Req.Method == "PUT" {
|
||||||
|
@ -49,14 +49,11 @@ type Item struct {
|
|||||||
FeedId int64 `json:"feed_id"`
|
FeedId int64 `json:"feed_id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Link string `json:"link"`
|
Link string `json:"link"`
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
Content string `json:"content,omitempty"`
|
Content string `json:"content,omitempty"`
|
||||||
Author string `json:"author"`
|
Date time.Time `json:"date"`
|
||||||
Date *time.Time `json:"date"`
|
|
||||||
DateUpdated *time.Time `json:"date_updated"`
|
|
||||||
Status ItemStatus `json:"status"`
|
Status ItemStatus `json:"status"`
|
||||||
Image string `json:"image"`
|
ImageURL *string `json:"image"`
|
||||||
PodcastURL *string `json:"podcast_url"`
|
AudioURL *string `json:"podcast_url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ItemFilter struct {
|
type ItemFilter struct {
|
||||||
@ -77,25 +74,21 @@ func (s *Storage) CreateItems(items []Item) bool {
|
|||||||
log.Print(err)
|
log.Print(err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
_, err = tx.Exec(`
|
_, err = tx.Exec(`
|
||||||
insert into items (
|
insert into items (
|
||||||
guid, feed_id, title, link, description,
|
guid, feed_id, title, link, date,
|
||||||
content, author,
|
content, image, podcast_url,
|
||||||
date, date_updated, date_arrived,
|
date_arrived, status
|
||||||
status, image, podcast_url
|
|
||||||
)
|
)
|
||||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
on conflict (feed_id, guid) do update set
|
on conflict (feed_id, guid) do nothing`,
|
||||||
date_updated = ?, date_arrived = ?`,
|
item.GUID, item.FeedId, item.Title, item.Link, item.Date,
|
||||||
item.GUID, item.FeedId, item.Title, item.Link, item.Description,
|
item.Content, item.ImageURL, item.AudioURL,
|
||||||
item.Content, item.Author,
|
now, UNREAD,
|
||||||
item.Date, item.DateUpdated, now,
|
|
||||||
UNREAD, item.Image, item.PodcastURL,
|
|
||||||
// upsert values
|
|
||||||
item.DateUpdated, now,
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
@ -158,8 +151,9 @@ func (s *Storage) ListItems(filter ItemFilter, offset, limit int, newestFirst bo
|
|||||||
|
|
||||||
query := fmt.Sprintf(`
|
query := fmt.Sprintf(`
|
||||||
select
|
select
|
||||||
i.id, i.guid, i.feed_id, i.title, i.link,
|
i.id, i.guid, i.feed_id,
|
||||||
i.author, i.date, i.date_updated, i.status, i.image, i.podcast_url
|
i.title, i.link, i.date,
|
||||||
|
i.status, i.image, i.podcast_url
|
||||||
from items i
|
from items i
|
||||||
join feeds f on f.id = i.feed_id
|
join feeds f on f.id = i.feed_id
|
||||||
where %s
|
where %s
|
||||||
@ -174,17 +168,9 @@ func (s *Storage) ListItems(filter ItemFilter, offset, limit int, newestFirst bo
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var x Item
|
var x Item
|
||||||
err = rows.Scan(
|
err = rows.Scan(
|
||||||
&x.Id,
|
&x.Id, &x.GUID, &x.FeedId,
|
||||||
&x.GUID,
|
&x.Title, &x.Link, &x.Date,
|
||||||
&x.FeedId,
|
&x.Status, &x.ImageURL, &x.AudioURL,
|
||||||
&x.Title,
|
|
||||||
&x.Link,
|
|
||||||
&x.Author,
|
|
||||||
&x.Date,
|
|
||||||
&x.DateUpdated,
|
|
||||||
&x.Status,
|
|
||||||
&x.Image,
|
|
||||||
&x.PodcastURL,
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
@ -199,13 +185,13 @@ func (s *Storage) GetItem(id int64) *Item {
|
|||||||
i := &Item{}
|
i := &Item{}
|
||||||
err := s.db.QueryRow(`
|
err := s.db.QueryRow(`
|
||||||
select
|
select
|
||||||
i.id, i.guid, i.feed_id, i.title, i.link, i.content, i.description,
|
i.id, i.guid, i.feed_id, i.title, i.link, i.content,
|
||||||
i.author, i.date, i.date_updated, i.status, i.image, i.podcast_url
|
i.date, i.status, i.image, i.podcast_url
|
||||||
from items i
|
from items i
|
||||||
where i.id = ?
|
where i.id = ?
|
||||||
`, id).Scan(
|
`, id).Scan(
|
||||||
&i.Id, &i.GUID, &i.FeedId, &i.Title, &i.Link, &i.Content, &i.Description,
|
&i.Id, &i.GUID, &i.FeedId, &i.Title, &i.Link, &i.Content,
|
||||||
&i.Author, &i.Date, &i.DateUpdated, &i.Status, &i.Image, &i.PodcastURL,
|
&i.Date, &i.Status, &i.ImageURL, &i.AudioURL,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
@ -296,7 +282,7 @@ func (s *Storage) FeedStats() []FeedStat {
|
|||||||
|
|
||||||
func (s *Storage) SyncSearch() {
|
func (s *Storage) SyncSearch() {
|
||||||
rows, err := s.db.Query(`
|
rows, err := s.db.Query(`
|
||||||
select id, title, content, description
|
select id, title, content
|
||||||
from items
|
from items
|
||||||
where search_rowid is null;
|
where search_rowid is null;
|
||||||
`)
|
`)
|
||||||
@ -308,14 +294,14 @@ func (s *Storage) SyncSearch() {
|
|||||||
items := make([]Item, 0)
|
items := make([]Item, 0)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var item Item
|
var item Item
|
||||||
rows.Scan(&item.Id, &item.Title, &item.Content, &item.Description)
|
rows.Scan(&item.Id, &item.Title, &item.Content)
|
||||||
items = append(items, item)
|
items = append(items, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
result, err := s.db.Exec(`
|
result, err := s.db.Exec(`
|
||||||
insert into search (title, description, content) values (?, ?, ?)`,
|
insert into search (title, description, content) values (?, "", ?)`,
|
||||||
item.Title, htmlutil.ExtractText(item.Description), htmlutil.ExtractText(item.Content),
|
item.Title, htmlutil.ExtractText(item.Content),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
|
@ -240,3 +240,6 @@ func m04_item_podcasturl(tx *sql.Tx) error {
|
|||||||
_, err := tx.Exec(sql)
|
_, err := tx.Exec(sql)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: description -> content
|
||||||
|
@ -136,22 +136,24 @@ func ConvertItems(items []parser.Item, feed storage.Feed) []storage.Item {
|
|||||||
result := make([]storage.Item, len(items))
|
result := make([]storage.Item, len(items))
|
||||||
for i, item := range items {
|
for i, item := range items {
|
||||||
item := item
|
item := item
|
||||||
var podcastURL *string = nil
|
var audioURL *string = nil
|
||||||
if item.AudioURL != "" {
|
if item.AudioURL != "" {
|
||||||
podcastURL = &item.AudioURL
|
audioURL = &item.AudioURL
|
||||||
|
}
|
||||||
|
var imageURL *string = nil
|
||||||
|
if item.ImageURL != "" {
|
||||||
|
imageURL = &item.ImageURL
|
||||||
}
|
}
|
||||||
result[i] = storage.Item{
|
result[i] = storage.Item{
|
||||||
GUID: item.GUID,
|
GUID: item.GUID,
|
||||||
FeedId: feed.Id,
|
FeedId: feed.Id,
|
||||||
Title: item.Title,
|
Title: item.Title,
|
||||||
Link: item.URL,
|
Link: item.URL,
|
||||||
Description: "",
|
|
||||||
Content: item.Content,
|
Content: item.Content,
|
||||||
Author: "",
|
Date: item.Date,
|
||||||
Date: &item.Date,
|
|
||||||
Status: storage.UNREAD,
|
Status: storage.UNREAD,
|
||||||
Image: item.ImageURL,
|
ImageURL: imageURL,
|
||||||
PodcastURL: podcastURL,
|
AudioURL: audioURL,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
Loading…
x
Reference in New Issue
Block a user