chore: update configuration
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
5dda11f170
commit
d9e9a33b3d
@ -25,50 +25,17 @@ pub struct LightConfigurationRequest {
|
|||||||
|
|
||||||
#[post("/configure", data= "<data>")]
|
#[post("/configure", data= "<data>")]
|
||||||
pub async fn configure(data: Json<LightConfigurationRequest>, db: &State<DBPool>, action: &State<ASender<Action>>) -> String {
|
pub async fn configure(data: Json<LightConfigurationRequest>, db: &State<DBPool>, action: &State<ASender<Action>>) -> String {
|
||||||
|
let conn = get_conn(db);
|
||||||
let conn = db.get();
|
if let Err(e) = conn {
|
||||||
|
return e;
|
||||||
if conn.is_err() || conn.as_ref().ok().is_none() {
|
|
||||||
return json!(ApiResponse {code: 500, message: "Clould not configure. Err: 1".to_string()}).to_string();
|
|
||||||
}
|
}
|
||||||
|
let conn = conn.unwrap();
|
||||||
|
|
||||||
let conn = conn.ok().unwrap();
|
let recreate = is_configured(&conn);
|
||||||
|
if let Err(e) = recreate {
|
||||||
let stmt = conn.prepare("SELECT configured from meta");
|
return e;
|
||||||
|
|
||||||
if stmt.is_err() || stmt.as_ref().ok().is_none() {
|
|
||||||
return json!(ApiResponse {code: 500, message: format!("Clould not configure. Err: 2, {:?}", stmt)}).to_string();
|
|
||||||
}
|
}
|
||||||
|
let recreate = recreate.unwrap();
|
||||||
let mut stmt = stmt.ok().unwrap();
|
|
||||||
|
|
||||||
struct Data {
|
|
||||||
configured: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
let version_iter = stmt.query_map([], |row| {
|
|
||||||
Ok(Data {
|
|
||||||
configured: row.get(0)?
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
if version_iter.is_err() || version_iter.as_ref().ok().is_none() {
|
|
||||||
return json!(ApiResponse {code: 500, message: "Clould not configure. Err: 3".to_string()}).to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
let version_iter = version_iter.unwrap();
|
|
||||||
|
|
||||||
let mut recreate = false;
|
|
||||||
|
|
||||||
for data in version_iter {
|
|
||||||
if data.unwrap().configured {
|
|
||||||
println!("Already configured deleting current");
|
|
||||||
recreate = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
drop(stmt);
|
|
||||||
|
|
||||||
if recreate {
|
if recreate {
|
||||||
let stmt = conn.execute("DELETE FROM configuration;", ());
|
let stmt = conn.execute("DELETE FROM configuration;", ());
|
||||||
@ -100,6 +67,11 @@ pub async fn configure(data: Json<LightConfigurationRequest>, db: &State<DBPool>
|
|||||||
return json!(ApiResponse {code: 500, message: "Failed to reload".to_string()}).to_string()
|
return json!(ApiResponse {code: 500, message: "Failed to reload".to_string()}).to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let stmt = conn.execute("UPDATE meta set configured=1 where id=1;", ());
|
||||||
|
if stmt.is_err() || stmt.as_ref().ok().is_none() {
|
||||||
|
return json!(ApiResponse {code: 500, message: format!("Clould not configure. Err: 5, {:?}", stmt)}).to_string();
|
||||||
|
}
|
||||||
|
|
||||||
json!(ApiResponse {code: 200, message: "Configuration was successful".to_string()}).to_string()
|
json!(ApiResponse {code: 200, message: "Configuration was successful".to_string()}).to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user