From 1a97587381196e9a1c680e0714b4868c701d4059 Mon Sep 17 00:00:00 2001 From: SamTV12345 Date: Mon, 2 Sep 2024 11:22:16 +0200 Subject: [PATCH] Fixed gpodder sync --- src/models/episode.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/models/episode.rs b/src/models/episode.rs index 91c3459a..d025ec78 100644 --- a/src/models/episode.rs +++ b/src/models/episode.rs @@ -4,7 +4,7 @@ use crate::dbconfig::schema::episodes::dsl::episodes as episodes_dsl; use crate::DBType as DbConnection; use chrono::{NaiveDateTime, Utc}; use diesel::sql_types::{Integer, Nullable, Text, Timestamp}; -use diesel::{ExpressionMethods, JoinOnDsl}; +use diesel::{debug_query, ExpressionMethods, JoinOnDsl}; use diesel::{ BoolExpressionMethods, Insertable, NullableExpressionMethods, OptionalExtension, QueryDsl, QueryId, Queryable, QueryableByName, RunQueryDsl, Selectable, @@ -14,7 +14,9 @@ use serde::{Deserialize, Serialize}; use std::fmt; use std::io::Error; use diesel::query_dsl::methods::DistinctDsl; +use diesel::sqlite::Sqlite; use utoipa::ToSchema; +use crate::dbconfig::{DBType, MultiBackend}; use crate::models::gpodder_available_podcasts::GPodderAvailablePodcasts; use crate::models::misc_models::{ PodcastWatchedEpisodeModelWithPodcastEpisode, PodcastWatchedPostModel, @@ -150,8 +152,9 @@ impl Episode { let mut query = ep_table.filter(username.eq(username1)).into_boxed(); + println!("Since {}", since_date.unwrap()); if let Some(since_date) = since_date { - query = query.filter(timestamp.gt(since_date)); + query = query.filter(timestamp.ge(since_date)); } if let Some(device) = opt_device { @@ -161,12 +164,15 @@ impl Episode { .eq(device) .or(ep_dsl::device.eq(DEFAULT_DEVICE)), ); + } else { + query = query.filter(ep_dsl::device.eq(DEFAULT_DEVICE)) } if let Some(podcast) = opt_podcast { query = query.filter(ep_dsl::podcast.eq(podcast)); } + query .load::(conn) .expect("Error querying episodes") @@ -385,13 +391,14 @@ impl Episode { return Ok(()); } Ok(None) => { + let naive_date = Utc::now().naive_utc(); let episode = Episode { id, username, device: DEFAULT_DEVICE.to_string(), podcast: podcast.unwrap().rssfeed, episode: found_episode.url.clone(), - timestamp: Default::default(), + timestamp: naive_date, guid: Some(found_episode.guid.clone()), action: "play".to_string(), started: None,