Skip to content

Commit

Permalink
Reformat and restructure code
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Sep 26, 2024
1 parent 2d885bf commit be4b3fb
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
14 changes: 7 additions & 7 deletions src/legacy/disks.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::str;
use regex::Regex;
use serde_json::Value;
use std::collections::HashMap;
use std::str;

use crate::legacy::helper::{run_command, size_converter};

Expand Down Expand Up @@ -53,7 +53,7 @@ fn is_physical_disk(lib_path: &str, device_id: &str) -> bool {
Err(_) => {
log::error!("Failed to get disk info");
return false;
},
}
};
for line in output.split("\n") {
if line.contains("Virtual:") && line.contains("Yes") {
Expand All @@ -79,7 +79,7 @@ fn linux_disks(lib_path: &str) -> Vec<HashMap<String, String>> {
Err(_) => {
log::error!("Failed to get disk info");
return Vec::new();
},
}
};
let disks: Vec<&str> = output.lines().collect();
let filtered_disks: Vec<&str> = disks.into_iter().filter(|&disk| !disk.contains("loop")).collect();
Expand Down Expand Up @@ -118,7 +118,7 @@ fn darwin_disks(lib_path: &str) -> Vec<HashMap<String, String>> {
Err(_) => {
log::error!("Failed to get disk info");
return Vec::new();
},
}
};
let disks: Vec<&str> = output.lines().collect();
let disk_lines: Vec<&str> = disks.into_iter().filter(|&line| line.starts_with("/dev/disk")).collect();
Expand All @@ -134,7 +134,7 @@ fn darwin_disks(lib_path: &str) -> Vec<HashMap<String, String>> {
Err(_) => {
log::error!("Failed to get disk info");
return Vec::new();
},
}
};
let info_lines: Vec<&str> = disk_info_output.lines().collect();
let mut disk_data = HashMap::new();
Expand Down Expand Up @@ -189,7 +189,7 @@ fn windows_disks(lib_path: &str) -> Vec<HashMap<String, String>> {
Err(_) => {
log::error!("Failed to get disk info");
return Vec::new();
},
}
};
let disks_info: Value = serde_json::from_str(&output).unwrap();
let mut disk_info = Vec::new();
Expand Down
12 changes: 6 additions & 6 deletions src/resources/info.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{resources, squire, legacy};
use crate::{legacy, resources, squire};
use chrono::Utc;
use std::collections::HashMap;
use std::collections::HashSet;
use sysinfo::System;
use sysinfo::Disks;
use sysinfo::System;

/// Function to get total disk usage.
///
Expand Down Expand Up @@ -58,11 +58,11 @@ fn get_cpu_brand(sys: &System) -> String {
if cpu_brands.is_empty() {
log::warn!("Unable to get brand information for all {} CPUs", cpus.len());
let legacy_cpu_brand_name = legacy::cpu_brand::get_name();
return if legacy_cpu_brand_name.is_some() {
legacy_cpu_brand_name.unwrap()
return if let Some(cpu_brand) = legacy_cpu_brand_name {
cpu_brand
} else {
"Unknown".to_string()
}
};
}
let mut cpu_brand_list: Vec<String> = cpu_brands.into_iter().collect();
cpu_brand_list.sort_by_key(|brand| brand.len());
Expand Down Expand Up @@ -105,7 +105,7 @@ pub fn get_sys_info(disks: &Disks) -> HashMap<&'static str, HashMap<&'static str
("Uptime", uptime),
("CPU cores", sys.cpus().len().to_string()),
("CPU brand", get_cpu_brand(&sys))
]);
]);
let mut hash_vec = vec![
("Memory", total_memory),
("Storage", total_storage)
Expand Down
2 changes: 1 addition & 1 deletion src/resources/stream.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use sysinfo::{CpuRefreshKind, Disks, RefreshKind, System};

use crate::{squire, resources};
use crate::{resources, squire};
use serde_json::{self, Value};

/// Function to get disk statistics.
Expand Down
4 changes: 2 additions & 2 deletions src/routes/auth.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::sync::Arc;

use actix_web::{HttpRequest, HttpResponse, web};
use actix_web::cookie::{Cookie, SameSite};
use actix_web::cookie::time::{Duration, OffsetDateTime};
use actix_web::cookie::{Cookie, SameSite};
use actix_web::http::StatusCode;
use actix_web::{web, HttpRequest, HttpResponse};
use fernet::Fernet;
use minijinja;
use serde::Serialize;
Expand Down
6 changes: 3 additions & 3 deletions src/squire/util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use regex::Regex;
use std::process::Command;
use std::collections::HashMap;
use std::process::Command;

/// Function to retrieve the REGEX object for an IPv4 address format
///
Expand All @@ -27,8 +27,8 @@ pub fn public_ip_mapping() -> HashMap<String, bool> {
("https://httpbin.org/ip".to_string(), false), // expects JSON
("https://myip.dnsomatic.com/".to_string(), true), // expects text
]
.into_iter()
.collect();
.into_iter()
.collect();
mapping
}

Expand Down

0 comments on commit be4b3fb

Please sign in to comment.