Skip to content

Commit

Permalink
ws::events > append missing user site data for siteChanged event
Browse files Browse the repository at this point in the history
  • Loading branch information
canewsin committed Jan 22, 2024
1 parent 662598a commit 17cf9bc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
42 changes: 27 additions & 15 deletions src/plugins/websocket/handlers/sites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use super::{
users::{get_current_user, handle_cert_set},
};
use crate::{
core::site::models::SiteInfo,
environment::SITE_PERMISSIONS_DETAILS,
plugins::site_server::handlers::{
sites::{DBQueryRequest, SiteInfoListRequest, SiteInfoRequest},
Expand Down Expand Up @@ -259,18 +260,37 @@ pub fn handle_site_info(ws: &ZeruWebsocket, command: &Command) -> Result<Message
error: String::from("Site info not found"),
});
}
let mut site_info = result.unwrap();
if let Some(site_info) = append_user_site_data(ws, &mut site_info) {
if let Value::Object(params) = &command.params {
if let Some(Value::String(path)) = params.get("file_status") {
site_info.event = Some(json!(["file_done", path])); //TODO!: get file status
}
}
command.respond(site_info)
} else {
Err(Error {
error: String::from("Site info not found"),
})
}
}

pub fn append_user_site_data<'a>(
ws: &ZeruWebsocket,
site_info: &'a mut SiteInfo,
) -> Option<&'a mut SiteInfo> {
if let Some(map) = block_on(ws.user_controller.send(UserSiteData {
user_addr: String::from("current"),
site_addr: ws.address.address.clone(),
site_addr: site_info.address.clone(),
}))
.unwrap()
{
let user_site_data = map.values().last().unwrap();
let mut site_info = result.unwrap();
if let Some(provider) = user_site_data.get_cert_provider() {
let user = get_current_user(ws)?;
let user_name = &user.certs.get(&provider).unwrap().auth_user_name;
site_info.cert_user_id = Some(format!("{}@{}", user_name, provider));
let user = get_current_user(ws).unwrap();
if let Some(cert) = &user.certs.get(&provider) {
site_info.cert_user_id = Some(format!("{}@{}", cert.auth_user_name, provider));
}
}
if let Some(auth) = user_site_data.get_auth_pair() {
site_info.auth_address = auth.auth_address;
Expand All @@ -280,22 +300,14 @@ pub fn handle_site_info(ws: &ZeruWebsocket, command: &Command) -> Result<Message
site_info.privatekey = true;
}
}
if let Value::Object(params) = &command.params {
if let Some(Value::String(path)) = params.get("file_status") {
site_info.event = Some(json!(["file_done", path])); //TODO!: get file status
}
}
#[cfg(debug_assertions)]
{
site_info.size_limit = 25;
site_info.next_size_limit = 25;
}
command.respond(site_info)
} else {
Err(Error {
error: String::from("Site info not found"),
})
return Some(site_info);
}
None
}

pub fn handle_db_query(ws: &ZeruWebsocket, command: &Command) -> Result<Message, Error> {
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/websocket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,9 @@ impl ZeruWebsocket {
let mut site_info = block_on(self.site_addr.send(SiteInfoRequest()))
.unwrap()
.unwrap();
let site_info = append_user_site_data(&self, &mut site_info).unwrap();

Check warning on line 492 in src/plugins/websocket/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> src/plugins/websocket/mod.rs:492:55 | 492 | let site_info = append_user_site_data(&self, &mut site_info).unwrap(); | ^^^^^ help: change this to: `self` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
site_info.event = Some(add_params.clone());
self.send_event(EventType::SiteInfo(site_info))?;
self.send_event(EventType::SiteInfo(site_info.clone()))?;
} else if listener == "serverChanged" {
let server_info = server_info(self)?;
if params.len() > 0 {

Check warning on line 497 in src/plugins/websocket/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

length comparison to zero

warning: length comparison to zero --> src/plugins/websocket/mod.rs:497:20 | 497 | if params.len() > 0 { | ^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!params.is_empty()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero = note: `#[warn(clippy::len_zero)]` on by default
Expand Down

0 comments on commit 17cf9bc

Please sign in to comment.