This commit is contained in:
Alex Emmet 2026-04-05 00:03:19 +02:00
commit 1ea0b97f6d
49 changed files with 869 additions and 289 deletions

View file

@ -1,6 +1,6 @@
use crate::server::server::is_local_network;
use crate::util::config_util::CONFIG;
use crate::server::is_local_network;
use actix_web::{HttpRequest, HttpResponse, Responder, web};
use iota_storage::util::config_util::CONFIG;
use serde_json::{Value, json};
use std::net::SocketAddr;
use std::sync::Arc;
@ -56,15 +56,15 @@ async fn communities_get(req: HttpRequest, ssl: web::Data<bool>) -> impl Respond
return forbidden();
}
let communities = crate::communities::community_manager::get_communities().await;
// let communities = decentralized::communities::community_manager::get_communities().await;
let mut list = Vec::new();
let list: Vec<Value> = Vec::new();
for c in communities {
let val = c.frontend().await;
let s_val: Value = serde_json::to_value(val.to_string()).unwrap();
list.push(s_val);
}
// for c in communities {
// let val = c.frontend().await.to_string();
// let s_val: Value = serde_json::from_str(&val).unwrap_or(Value::Null);
// list.push(s_val);
// }
HttpResponse::Ok().json(list)
}
@ -77,12 +77,13 @@ async fn communities_add(
return forbidden();
}
let name = payload["name"].as_str().unwrap_or("").to_string();
let owner = payload["owner"].as_i64().unwrap_or(0);
// let name = payload["name"].as_str().unwrap_or("").to_string();
// let owner = payload["owner"].as_i64().unwrap_or(0);
let community = Arc::new(crate::communities::community::Community::create(name, owner).await);
// let community =
// Arc::new(decentralized::communities::community::Community::create(name, owner).await);
crate::communities::community_manager::add_community(community).await;
// decentralized::communities::community_manager::add_community(community).await;
success()
}
@ -92,13 +93,13 @@ async fn users_get(req: HttpRequest, ssl: web::Data<bool>) -> impl Responder {
return forbidden();
}
let users = crate::users::user_manager::get_users();
let users = iota_storage::users::user_manager::get_users();
let list: Vec<_> = users
.into_iter()
.map(|u| {
let val = u.frontend();
serde_json::to_value(val.to_string()).unwrap()
let val = u.frontend().to_string();
serde_json::from_str(&val).unwrap_or(Value::Null)
})
.collect();
@ -116,8 +117,8 @@ async fn users_remove(
let uuid = payload.get("uuid").and_then(|v| v.as_i64()).unwrap_or(0);
crate::users::user_manager::remove_user(uuid);
crate::users::user_manager::save_users();
iota_storage::users::user_manager::remove_user(uuid);
iota_storage::users::user_manager::save_users();
success()
}
@ -136,9 +137,9 @@ async fn users_add(
_ => return error(),
};
if let (Some(user), Some(_)) = crate::users::user_manager::create_user(username).await {
let val = user.frontend();
let s_val: Value = serde_json::to_value(val.to_string()).unwrap();
if let (Some(user), Some(_)) = omikron_connector::user_ops::create_user(username).await {
let val = user.frontend().to_string();
let s_val: Value = serde_json::from_str(&val).unwrap_or(Value::Null);
HttpResponse::Ok().json(s_val)
} else {
error()
@ -150,7 +151,7 @@ async fn shutdown(req: HttpRequest, ssl: web::Data<bool>) -> impl Responder {
return forbidden();
}
*crate::SHUTDOWN.write().await = true;
*iota_state::SHUTDOWN.write().await = true;
success()
}
@ -159,8 +160,8 @@ async fn reload(req: HttpRequest, ssl: web::Data<bool>) -> impl Responder {
return forbidden();
}
*crate::SHUTDOWN.write().await = true;
*crate::RELOAD.write().await = true;
*iota_state::SHUTDOWN.write().await = true;
*iota_state::RELOAD.write().await = true;
success()
}

View file

@ -1,10 +1,9 @@
use crate::log;
use crate::server::api::api_config;
use crate::server::web_path_parser;
use crate::util::file_util::load_file_buf;
use crate::{ACTIVE_TASKS, SHUTDOWN};
use crate::api::api_config;
use crate::web_path_parser;
use actix_web::{App, Error, HttpRequest, HttpServer, Responder, dev::ServerHandle, web};
use actix_web_actors::ws;
use iota_logger::log;
use iota_state::{ACTIVE_TASKS, SHUTDOWN};
use iota_util::file_util::load_file_buf;
use rustls::ServerConfig;
use rustls::pki_types::{CertificateDer, PrivateKeyDer};
use std::{
@ -15,13 +14,6 @@ use std::{
time::Duration,
};
async fn ws_handler(req: HttpRequest, stream: web::Payload) -> Result<impl Responder, Error> {
let path = req.path().to_string();
log!("WS connection from {:?}", req.peer_addr());
let session = WsSession::new(path);
ws::start(session, &req, stream)
}
use tokio::sync::oneshot;
pub async fn start(port: u16) -> bool {
@ -36,7 +28,6 @@ pub async fn start(port: u16) -> bool {
App::new()
.app_data(web::Data::new(true))
.configure(api_config)
.service(web::resource("/ws/{path:.*}").route(web::get().to(ws_handler)))
.default_service(web::to(web_path_parser::handle))
})
.bind(("0.0.0.0", port))
@ -49,7 +40,6 @@ pub async fn start(port: u16) -> bool {
App::new()
.app_data(web::Data::new(false))
.configure(api_config)
.service(web::resource("/ws/{path:.*}").route(web::get().to(ws_handler)))
.default_service(web::to(web_path_parser::handle))
})
.bind(("0.0.0.0", port))

0
web-ui/src/socket.rs Normal file
View file

View file

@ -1,7 +1,7 @@
use actix_web::{HttpRequest, HttpResponse};
use std::path::{Path, PathBuf};
use crate::util::file_util::load_file_vec;
use iota_util::file_util::load_file_vec;
fn codec_for_ext(ext: &str) -> &'static str {
match ext {