From 50aac68b6a614c224cb529dac45efd76841dd841 Mon Sep 17 00:00:00 2001 From: madeofpendletonwool Date: Sun, 4 Aug 2024 10:35:16 -0500 Subject: [PATCH 1/2] Adjust bt and fix floating points --- completed_todos.md | 4 +- startup/setupdatabase.py | 11 +++++- startup/setuppostgresdatabase.py | 13 +++++-- web/src/requests/pod_req.rs | 67 +++++++++++++++++++++++++++++++- 4 files changed, 87 insertions(+), 8 deletions(-) diff --git a/completed_todos.md b/completed_todos.md index 103e3f02..7c8a4dc0 100644 --- a/completed_todos.md +++ b/completed_todos.md @@ -29,7 +29,7 @@ Version 0.6.4 - [x] Added a fallback to the opml import for when the opml file uses text instead of title for the podcast name key - [x] Added a new route for the version tag that dynamically updates when the application is compiled. This allows for automation around the version numbers all based around the the Github release tag as the original source of truth. - [x] Fixed layout for podcasts when searching -- [] Support floating point chapters +- [x] Support floating point chapters - [x] Fixed issue with white space at the bottom of every page #229 - [x] Cleaned up incorrect or not needed logging at startup #219 - [x] Fixed issue with user stats page where it would lose user context on reload #135 @@ -46,7 +46,7 @@ Version 0.6.4 - [x] Implemented adjustment on all modals throughout the app so clicking outside them closes them (episode layout confiramtions missing yet - also test all login modals) - [x] Implemented adjustment on all modals so that they overlap everything in the app (This was causing issues on small screens) - [x] Added Confirmation dialog modal to podcast deletion on /podcasts layout page -- [] Changed name of bt user to background_tasks to make the user more clear on api key settings display +- [x] Changed name of bt user to background_tasks to make the user more clear on api key settings display Version 0.6.3 diff --git a/startup/setupdatabase.py b/startup/setupdatabase.py index 26836ec6..ba50f7b3 100644 --- a/startup/setupdatabase.py +++ b/startup/setupdatabase.py @@ -187,14 +187,21 @@ def insert_or_update_user(cursor, hashed_password): UPDATE Users SET Fullname = %s, Username = %s, Email = %s, Hashed_PW = %s, IsAdmin = %s WHERE Username = %s - """, ('Background Tasks', 'bt', 'inactive', hashed_password, False, 'guest')) + """, ('Background Tasks', 'background_tasks', 'inactive', hashed_password, False, 'guest')) + logging.info("Updated existing 'guest' user to 'bt' user.") + elif user_exists(cursor, 'bt'): + cursor.execute(""" + UPDATE Users + SET Fullname = %s, Username = %s, Email = %s, Hashed_PW = %s, IsAdmin = %s + WHERE Username = %s + """, ('Background Tasks', 'background_tasks', 'inactive', hashed_password, False, 'guest')) logging.info("Updated existing 'guest' user to 'bt' user.") else: cursor.execute(""" INSERT INTO Users (Fullname, Username, Email, Hashed_PW, IsAdmin) VALUES (%s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE Username=VALUES(Username) - """, ('Background Tasks', 'bt', 'inactive', hashed_password, False)) + """, ('Background Tasks', 'background_tasks', 'inactive', hashed_password, False, 'guest')) except Exception as e: print(f"Error inserting or updating user: {e}") logging.error("Error inserting or updating user: %s", e) diff --git a/startup/setuppostgresdatabase.py b/startup/setuppostgresdatabase.py index 5d11324d..dc2e8d2f 100644 --- a/startup/setuppostgresdatabase.py +++ b/startup/setuppostgresdatabase.py @@ -176,14 +176,21 @@ def insert_or_update_user(cursor, hashed_password): UPDATE "Users" SET Fullname = %s, Username = %s, Email = %s, Hashed_PW = %s, IsAdmin = %s WHERE Username = %s - """, ('Background Tasks', 'bt', 'inactive', hashed_password, False, 'guest')) - logging.info("Updated existing 'guest' user to 'bt' user.") + """, ('Background Tasks', 'background_tasks', 'inactive', hashed_password, False, 'guest')) + logging.info("Updated existing 'guest' user to 'background_tasks' user.") + elif user_exists(cursor, 'bt'): + cursor.execute(""" + UPDATE "Users" + SET Fullname = %s, Username = %s, Email = %s, Hashed_PW = %s, IsAdmin = %s + WHERE Username = %s + """, ('Background Tasks', 'background_tasks', 'inactive', hashed_password, False, 'guest')) + logging.info("Updated existing 'guest' user to 'background_tasks' user.") else: cursor.execute(""" INSERT INTO "Users" (Fullname, Username, Email, Hashed_PW, IsAdmin) VALUES (%s, %s, %s, %s, %s) ON CONFLICT (Username) DO NOTHING - """, ('Background Tasks', 'bt', 'inactive', hashed_password, False)) + """, ('Background Tasks', 'bt', 'inactive', hashed_password, False, 'guest')) except Exception as e: print(f"Error inserting or updating user: {e}") logging.error("Error inserting or updating user: %s", e) diff --git a/web/src/requests/pod_req.rs b/web/src/requests/pod_req.rs index f4cc4a2e..995484f6 100644 --- a/web/src/requests/pod_req.rs +++ b/web/src/requests/pod_req.rs @@ -1,7 +1,9 @@ use anyhow::{Context, Error}; use gloo_net::http::Request; +use serde::de::{self, Visitor}; use serde::{Deserialize, Deserializer, Serialize}; use std::collections::HashMap; +use std::fmt; fn bool_from_int<'de, D>(deserializer: D) -> Result where @@ -1142,12 +1144,75 @@ pub async fn call_get_episode_metadata( #[serde(rename_all = "snake_case")] #[allow(non_snake_case)] pub struct Chapter { - pub startTime: Option, // Changed to Option + #[serde(deserialize_with = "deserialize_start_time")] + pub startTime: Option, // Changed to Option with custom deserializer pub title: String, pub url: Option, pub img: Option, } +fn deserialize_start_time<'de, D>(deserializer: D) -> Result, D::Error> +where + D: Deserializer<'de>, +{ + struct StartTimeVisitor; + + impl<'de> Visitor<'de> for StartTimeVisitor { + type Value = Option; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("an integer or a floating point number as start time") + } + + fn visit_none(self) -> Result + where + E: de::Error, + { + Ok(None) + } + + fn visit_some(self, deserializer: D) -> Result + where + D: Deserializer<'de>, + { + deserializer.deserialize_any(self) + } + + fn visit_i64(self, value: i64) -> Result + where + E: de::Error, + { + Ok(Some(value as i32)) + } + + fn visit_u64(self, value: u64) -> Result + where + E: de::Error, + { + Ok(Some(value as i32)) + } + + fn visit_f64(self, value: f64) -> Result + where + E: de::Error, + { + Ok(Some(value.round() as i32)) + } + + fn visit_str(self, value: &str) -> Result + where + E: de::Error, + { + value + .parse::() + .map(|v| Some(v.round() as i32)) + .map_err(de::Error::custom) + } + } + + deserializer.deserialize_option(StartTimeVisitor) +} + #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] #[serde(rename_all = "snake_case")] pub struct Transcript { From 18dc1c6f78188b83148380ddf1dc78887e334bab Mon Sep 17 00:00:00 2001 From: madeofpendletonwool Date: Sun, 4 Aug 2024 14:16:48 -0500 Subject: [PATCH 2/2] Fixed update user where clause --- completed_todos.md | 1 + startup/setuppostgresdatabase.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/completed_todos.md b/completed_todos.md index 7c8a4dc0..bf946432 100644 --- a/completed_todos.md +++ b/completed_todos.md @@ -13,6 +13,7 @@ Next Minor Version: - [] Push completion status to Nextcloud/gpodder - [] Test with LXC containers - [] Queue adjmustment for mobile devices +- [] Update queue slider to be centered - [] Adjust download checkboxes to look nicer - [] Change download multiple buttons to be on same line as header - [] Full Show deletion with checkbox on download page diff --git a/startup/setuppostgresdatabase.py b/startup/setuppostgresdatabase.py index dc2e8d2f..3d9dd972 100644 --- a/startup/setuppostgresdatabase.py +++ b/startup/setuppostgresdatabase.py @@ -183,7 +183,7 @@ def insert_or_update_user(cursor, hashed_password): UPDATE "Users" SET Fullname = %s, Username = %s, Email = %s, Hashed_PW = %s, IsAdmin = %s WHERE Username = %s - """, ('Background Tasks', 'background_tasks', 'inactive', hashed_password, False, 'guest')) + """, ('Background Tasks', 'background_tasks', 'inactive', hashed_password, False, 'bt')) logging.info("Updated existing 'guest' user to 'background_tasks' user.") else: cursor.execute("""