Skip to content

Commit

Permalink
Merge pull request #249 from madeofpendletonwool/bt-user-adjustments
Browse files Browse the repository at this point in the history
Bt user adjustments
  • Loading branch information
madeofpendletonwool authored Aug 4, 2024
2 parents efa99e0 + 18dc1c6 commit 92711a2
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 8 deletions.
5 changes: 3 additions & 2 deletions completed_todos.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,7 +30,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
Expand All @@ -46,7 +47,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

Expand Down
11 changes: 9 additions & 2 deletions startup/setupdatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 10 additions & 3 deletions startup/setuppostgresdatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, 'bt'))
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)
Expand Down
67 changes: 66 additions & 1 deletion web/src/requests/pod_req.rs
Original file line number Diff line number Diff line change
@@ -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<bool, D::Error>
where
Expand Down Expand Up @@ -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<i32>, // Changed to Option<String>
#[serde(deserialize_with = "deserialize_start_time")]
pub startTime: Option<i32>, // Changed to Option<i32> with custom deserializer
pub title: String,
pub url: Option<String>,
pub img: Option<String>,
}

fn deserialize_start_time<'de, D>(deserializer: D) -> Result<Option<i32>, D::Error>
where
D: Deserializer<'de>,
{
struct StartTimeVisitor;

impl<'de> Visitor<'de> for StartTimeVisitor {
type Value = Option<i32>;

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<E>(self) -> Result<Self::Value, E>
where
E: de::Error,
{
Ok(None)
}

fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where
D: Deserializer<'de>,
{
deserializer.deserialize_any(self)
}

fn visit_i64<E>(self, value: i64) -> Result<Self::Value, E>
where
E: de::Error,
{
Ok(Some(value as i32))
}

fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E>
where
E: de::Error,
{
Ok(Some(value as i32))
}

fn visit_f64<E>(self, value: f64) -> Result<Self::Value, E>
where
E: de::Error,
{
Ok(Some(value.round() as i32))
}

fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where
E: de::Error,
{
value
.parse::<f64>()
.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 {
Expand Down

0 comments on commit 92711a2

Please sign in to comment.