Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
75c0a61bf9 | |||
6c3ee2fbe8 |
@ -1,7 +1,7 @@
|
||||
use std::io::Cursor;
|
||||
use rust_embed::RustEmbed;
|
||||
use rust_embed::{EmbeddedFile, RustEmbed};
|
||||
use rocket::{Data, Request, Response, Route};
|
||||
use rocket::http::{ContentType, Method};
|
||||
use rocket::http::{ContentType, Method, Status};
|
||||
use rocket::http::uri::{Segments};
|
||||
use rocket::http::uri::fmt::Path;
|
||||
use rocket::route::{Handler, Outcome};
|
||||
@ -13,8 +13,7 @@ struct Asset;
|
||||
|
||||
#[cfg(feature = "static")]
|
||||
#[derive(Clone)]
|
||||
pub struct CustomHandler {
|
||||
}
|
||||
pub struct CustomHandler {}
|
||||
|
||||
#[cfg(feature = "static")]
|
||||
impl Into<Vec<Route>> for CustomHandler {
|
||||
@ -38,8 +37,12 @@ impl Handler for CustomHandler {
|
||||
path
|
||||
};
|
||||
|
||||
let file_content =
|
||||
<Asset as RustEmbed>::get(path.to_string_lossy().as_ref()).unwrap();
|
||||
let file_content = <Asset as RustEmbed>::get(path.to_string_lossy().as_ref());
|
||||
let file_content = match file_content {
|
||||
None => return Outcome::Failure(Status::NotFound),
|
||||
Some(c) => c
|
||||
};
|
||||
|
||||
let content_type: ContentType = path
|
||||
.extension()
|
||||
.map(|x| x.to_string_lossy())
|
||||
|
@ -1,2 +1,3 @@
|
||||
pub mod mdstat_parser;
|
||||
pub mod lsblk_parser;
|
||||
pub mod lsblk_parser;
|
||||
mod smart_parser;
|
||||
|
39
lib/src/parser/smart_parser.rs
Normal file
39
lib/src/parser/smart_parser.rs
Normal file
@ -0,0 +1,39 @@
|
||||
use std::process::Command;
|
||||
use rocket::serde::json::serde_json;
|
||||
|
||||
use rocket::serde::{Deserialize};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
struct DiskInfo {
|
||||
model_family: String,
|
||||
model_name: String,
|
||||
serial_number: String,
|
||||
rotation_rate: u32,
|
||||
}
|
||||
|
||||
fn get_disk_info(diskpath: &str) -> Option<DiskInfo> {
|
||||
let mut cmd = Command::new("smartctl");
|
||||
cmd.arg("-i")
|
||||
.arg("-json")
|
||||
.arg(diskpath);
|
||||
let output = match cmd.output() {
|
||||
Ok(output) => output,
|
||||
Err(err) => {
|
||||
println!("error while getting smart info: {}", err);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
let rawsmart = output.stdout;
|
||||
|
||||
let info: DiskInfo = match serde_json::from_slice(&rawsmart) {
|
||||
Ok(info) => info,
|
||||
Err(err) => {
|
||||
println!("{}", err);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
Some(info)
|
||||
}
|
Loading…
Reference in New Issue
Block a user