Moved file paths into a common struct
This commit is contained in:
parent
bba2c0a4f0
commit
c54265a6bd
27
src/main.rs
27
src/main.rs
@ -199,6 +199,12 @@ fn handle_connection(context: Arc<Mutex<Context>>, path: PathBuf, mut stream: Tc
|
||||
(Some(pki_path), 1, path.to_string(), num)
|
||||
};
|
||||
|
||||
let file_paths = DocumentPaths {
|
||||
pk: &pk_path,
|
||||
pki: pki_path.as_ref().map(|path| path.as_ref()),
|
||||
data: &data_path,
|
||||
};
|
||||
|
||||
if let Some((_, ending)) = relative_path.rsplit_once('.') {
|
||||
let path = path.to_path_buf();
|
||||
let ending = ending.to_lowercase();
|
||||
@ -248,9 +254,7 @@ fn handle_connection(context: Arc<Mutex<Context>>, path: PathBuf, mut stream: Tc
|
||||
&request.body,
|
||||
&relative_path,
|
||||
&path,
|
||||
&pk_path,
|
||||
pki_path.as_ref().map(|path| path.as_ref()),
|
||||
&data_path,
|
||||
file_paths,
|
||||
partial,
|
||||
start_level,
|
||||
)
|
||||
@ -277,15 +281,20 @@ fn reply_image(mut stream: TcpStream, relative_path: &str, image_type: &str, mut
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct DocumentPaths<'a> {
|
||||
pk: &'a Path,
|
||||
pki: Option<&'a Path>,
|
||||
data: &'a Path,
|
||||
}
|
||||
|
||||
fn handle_relative_connection(
|
||||
info: Arc<Mutex<SiteInfo>>,
|
||||
mut stream: TcpStream,
|
||||
body: &str,
|
||||
relative_path: &str,
|
||||
path: &Path,
|
||||
pk_path: &Path,
|
||||
pki_path: Option<&Path>,
|
||||
data_path: &Path,
|
||||
file_paths: DocumentPaths,
|
||||
partial: Option<usize>,
|
||||
start_level: usize,
|
||||
) {
|
||||
@ -352,7 +361,7 @@ fn handle_relative_connection(
|
||||
return;
|
||||
};
|
||||
|
||||
if let Ok(mut file) = File::create(data_path) {
|
||||
if let Ok(mut file) = File::create(file_paths.data) {
|
||||
if to_stream::<PortableSettings, _, _>(&info, &mut file).is_err() {
|
||||
eprintln!("Error saving data!");
|
||||
eprintln!();
|
||||
@ -414,7 +423,7 @@ fn handle_relative_connection(
|
||||
);
|
||||
};
|
||||
|
||||
if let Ok(pk_file) = File::open(pk_path) {
|
||||
if let Ok(pk_file) = File::open(file_paths.pk) {
|
||||
let lines = BufReader::new(pk_file).lines();
|
||||
|
||||
if let Some(i) = partial {
|
||||
@ -506,7 +515,7 @@ fn handle_relative_connection(
|
||||
|
||||
section(&mut stream);
|
||||
|
||||
if let Some(pki_path) = pki_path {
|
||||
if let Some(pki_path) = file_paths.pki {
|
||||
if let Ok(pki_file) = File::open(pki_path) {
|
||||
let _ = writeln!(stream, "<h1>Description</h1>");
|
||||
let lines = BufReader::new(pki_file).lines();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user