Local API for communities
This commit is contained in:
parent
1f878b9314
commit
b6fac5fa33
7 changed files with 74 additions and 32 deletions
|
|
@ -141,22 +141,46 @@ pub async fn handle(
|
|||
if path_parts.len() >= 4 {
|
||||
match path_parts[3] {
|
||||
"add" => {
|
||||
if body.is_none() {
|
||||
"{\"type\":\"error\"}".to_string()
|
||||
} else {
|
||||
let name = body.unwrap()["name"].as_str().unwrap().to_string();
|
||||
let community = Arc::new(Community::create(name).await);
|
||||
if let Some(body) = body {
|
||||
let name = body["name"].as_str().unwrap().to_string();
|
||||
let user_id = body["owner"].as_i64().unwrap_or(0);
|
||||
let community = Arc::new(Community::create(name, user_id).await);
|
||||
community_manager::add_community(community).await;
|
||||
"{\"type\":\"success\"}".to_string()
|
||||
} else {
|
||||
"{\"type\":\"error\"}".to_string()
|
||||
}
|
||||
}
|
||||
"remove" => {
|
||||
if body.is_none() {
|
||||
"{\"type\":\"error\"}".to_string()
|
||||
} else {
|
||||
let name = body.unwrap()["name"].as_str().unwrap().to_string();
|
||||
if let Some(body) = body {
|
||||
let name = body["name"].as_str().unwrap().to_string();
|
||||
community_manager::remove_community(&name).await;
|
||||
"{\"type\":\"success\"}".to_string()
|
||||
} else {
|
||||
"{\"type\":\"error\"}".to_string()
|
||||
}
|
||||
}
|
||||
"change" => {
|
||||
if path_parts.len() >= 5 {
|
||||
match path_parts[4] {
|
||||
"owner" => {
|
||||
if let Some(body) = body {
|
||||
let name = body["name"].as_str().unwrap().to_string();
|
||||
let owner = body["owner"].as_i64().unwrap_or(0);
|
||||
community_manager::get_community(&name)
|
||||
.await
|
||||
.unwrap()
|
||||
.set_owner(owner)
|
||||
.await;
|
||||
"{\"type\":\"success\"}".to_string()
|
||||
} else {
|
||||
"{\"type\":\"error\"}".to_string()
|
||||
}
|
||||
}
|
||||
_ => "{\"type\":\"error\"}".to_string(),
|
||||
}
|
||||
} else {
|
||||
"{\"type\":\"error\"}".to_string()
|
||||
}
|
||||
}
|
||||
"get" => {
|
||||
|
|
|
|||
|
|
@ -465,7 +465,7 @@ pub async fn start(port: u16) -> bool {
|
|||
|
||||
match tls_result {
|
||||
Ok(Some(tls_config)) => run_tls_server(port, tls_config).await,
|
||||
Ok(None) => run_http_server(port).await,
|
||||
Ok(_) => run_http_server(port).await,
|
||||
Err(e) => {
|
||||
log_message(format!("Fatal error during TLS config load: {}", e));
|
||||
false
|
||||
|
|
|
|||
Loading…
Reference in a new issue