@@ -125,20 +125,21 @@ pub fn read(conn: &DbConnection, key: &SettingKey) -> Result<Setting> {
125125}
126126
127127pub fn update ( conn : & DbConnection , arg : & SettingToUpdate ) -> Result < usize > {
128+ let mut value = arg. value . clone ( ) ;
129+
128130 match arg. key {
129131 SettingKey :: PollingFrequency => {
130- if arg . value . parse :: < i32 > ( ) . map ( |x| x < 30 ) . unwrap_or ( false ) {
132+ if value. parse :: < i32 > ( ) . map ( |x| x < 30 ) . unwrap_or ( false ) {
131133 return Err ( Error :: Unknown ) ;
132134 }
133135 }
134136 SettingKey :: Notification | SettingKey :: FetchOldItems => {
135- if arg . value . parse :: < bool > ( ) . unwrap_or ( false ) {
137+ if value. parse :: < bool > ( ) . unwrap_or ( false ) {
136138 return Err ( Error :: Unknown ) ;
137139 }
138140 }
139141 SettingKey :: Proxy => {
140- if arg
141- . value
142+ if value
142143 . parse :: < String > ( )
143144 . map ( |x| reqwest:: Proxy :: http ( x. deref ( ) ) )
144145 . map ( |_| false )
@@ -147,14 +148,20 @@ pub fn update(conn: &DbConnection, arg: &SettingToUpdate) -> Result<usize> {
147148 return Err ( Error :: Unknown ) ;
148149 }
149150 }
151+ SettingKey :: UpstreamUrl => {
152+ if !value. is_empty ( ) && !value. starts_with ( "http://" ) && !value. starts_with ( "https://" )
153+ {
154+ value = format ! ( "https://{}" , value) ;
155+ }
156+ }
150157 SettingKey :: DbSchemeVersion => return Err ( Error :: Forbidden ) ,
151158 _ => { }
152159 }
153160
154161 let ( sql, values) = Query :: insert ( )
155162 . into_table ( Settings :: Table )
156163 . columns ( [ Settings :: Key , Settings :: Value ] )
157- . values_panic ( [ arg. key . to_string ( ) . into ( ) , arg . value . clone ( ) . into ( ) ] )
164+ . values_panic ( [ arg. key . to_string ( ) . into ( ) , value. into ( ) ] )
158165 . on_conflict (
159166 OnConflict :: column ( Settings :: Key )
160167 . update_column ( Settings :: Value )
0 commit comments