handle duplicate feeds
This commit is contained in:
parent
5563a293f5
commit
8183feb229
1 changed files with 14 additions and 5 deletions
19
src/db.rs
19
src/db.rs
|
@ -25,7 +25,7 @@ const FEEDS_TABLE_CREATE: &str = "CREATE TABLE IF NOT EXISTS 'feeds' (
|
|||
'title' TEXT NOT NULL,
|
||||
'description' TEXT,
|
||||
'icon' BLOB,
|
||||
'url' text,
|
||||
'url' text not null unique,
|
||||
'subscribed' INTEGER NOT NULL default 0,
|
||||
'last_updated' TEXT ,
|
||||
PRIMARY KEY('feedID')
|
||||
|
@ -86,22 +86,31 @@ pub fn initialize() {
|
|||
}
|
||||
|
||||
|
||||
pub fn add_feed(url: &str) {
|
||||
pub fn add_feed(url: &str) -> Option<usize> {
|
||||
let conn = Connection::open(get_db_path()).unwrap();
|
||||
let feed = load_rss(url).unwrap();
|
||||
let new_feed = feed.clone();
|
||||
let time = Utc::now().to_rfc2822();
|
||||
conn.execute(
|
||||
match conn.execute(
|
||||
"insert into feeds(title,url,description,last_updated) values(?1,?2,?3,?4)",
|
||||
[feed.title, url.to_string(), feed.description, time],
|
||||
)
|
||||
.unwrap();
|
||||
) {
|
||||
Ok(_) => {
|
||||
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Couldn't add feed:{}\nError:{}",url,e);
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
let mut stmt = conn.prepare("select feedID from feeds where url=?1").unwrap();
|
||||
let id: usize = stmt.query_row([url],|row| {
|
||||
row.get(0)
|
||||
}).unwrap();
|
||||
//need to get the feed_id from the DB and then make sure items are mapped to feed
|
||||
store_items(new_feed,id);
|
||||
Some(id)
|
||||
}
|
||||
|
||||
pub fn store_items(feed: rss::Channel,feed_id: usize) {
|
||||
|
|
Loading…
Reference in a new issue