Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src-tauri/src/models/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,21 @@ pub fn read(conn: &DbConnection, key: &SettingKey) -> Result<Setting> {
}

pub fn update(conn: &DbConnection, arg: &SettingToUpdate) -> Result<usize> {
let mut value = arg.value.clone();

match arg.key {
SettingKey::PollingFrequency => {
if arg.value.parse::<i32>().map(|x| x < 30).unwrap_or(false) {
if value.parse::<i32>().map(|x| x < 30).unwrap_or(false) {
return Err(Error::Unknown);
}
}
SettingKey::Notification | SettingKey::FetchOldItems => {
if arg.value.parse::<bool>().unwrap_or(false) {
if value.parse::<bool>().unwrap_or(false) {
return Err(Error::Unknown);
}
}
SettingKey::Proxy => {
if arg
.value
if value
.parse::<String>()
.map(|x| reqwest::Proxy::http(x.deref()))
.map(|_| false)
Expand All @@ -147,14 +148,20 @@ pub fn update(conn: &DbConnection, arg: &SettingToUpdate) -> Result<usize> {
return Err(Error::Unknown);
}
}
SettingKey::UpstreamUrl => {
if !value.is_empty() && !value.starts_with("http://") && !value.starts_with("https://")
{
value = format!("https://{}", value);
}
}
SettingKey::DbSchemeVersion => return Err(Error::Forbidden),
_ => {}
}

let (sql, values) = Query::insert()
.into_table(Settings::Table)
.columns([Settings::Key, Settings::Value])
.values_panic([arg.key.to_string().into(), arg.value.clone().into()])
.values_panic([arg.key.to_string().into(), value.into()])
.on_conflict(
OnConflict::column(Settings::Key)
.update_column(Settings::Value)
Expand Down