♻️ refactor: more clippy lints, and make read_git_version simpler

main
_ 2021-03-21 03:45:00 +00:00
parent c6b2418a49
commit 235e134cb2
5 changed files with 9 additions and 20 deletions

View File

@ -1,14 +1,3 @@
pub async fn read_git_version () -> Option <String> {
use tokio::{
fs::File,
io::AsyncReadExt,
};
let mut buf = vec! [0_u8; 512];
let mut f = File::open ("git_version.txt").await.ok ()?;
let bytes_read = f.read (&mut buf).await.ok ()?;
buf.truncate (bytes_read);
Some (String::from_utf8 (buf).ok ()?)
pub async fn read () -> Option <String> {
tokio::fs::read_to_string ("git_version.txt").await.ok ()
}

View File

@ -277,7 +277,7 @@ async fn handle_server_list_internal (state: &Arc <RelayState>)
let guard = state.config.read ().await;
guard.iso.dev_mode.is_some ()
};
let git_version = git_version::read_git_version ().await;
let git_version = git_version::read ().await;
let server_list = scraper_api::v1_server_list (&state).await;

View File

@ -17,7 +17,7 @@ use tracing_subscriber::{
use ptth_relay::{
Config,
git_version::read_git_version,
git_version,
RelayState,
run_relay,
};
@ -52,7 +52,7 @@ async fn main () -> Result <(), Box <dyn Error>> {
let config_path = PathBuf::from ("config/ptth_relay.toml");
let config = Config::from_file (&config_path).await?;
if let Some (x) = read_git_version ().await {
if let Some (x) = git_version::read ().await {
info! ("ptth_relay Git version: {:?}", x);
}
else {

View File

@ -62,7 +62,7 @@ pub async fn serve_root (
let s = state.handlebars.render ("file_server_root", &params)?;
Ok (serve_html (s))
Ok (serve (s))
}
#[instrument (level = "debug", skip (handlebars, instance_metrics, dir))]
@ -87,7 +87,7 @@ pub async fn serve_dir (
instance_metrics,
})?;
Ok (serve_html (s))
Ok (serve (s))
}
async fn read_dir_entry (entry: FsDirEntry) -> DirEntry
@ -144,7 +144,7 @@ async fn read_dir_entry (entry: FsDirEntry) -> DirEntry
}
}
pub fn serve_html (s: String) -> Response {
pub fn serve (s: String) -> Response {
let mut resp = Response::default ();
resp
.header ("content-type".to_string (), "text/html; charset=UTF-8".to_string ().into_bytes ())

View File

@ -288,7 +288,7 @@ pub async fn serve_all (
serve_error (code, e.to_string ())
},
MarkdownPreview (s) => html::serve_html (s),
MarkdownPreview (s) => html::serve (s),
})
}