Add root_dir variable
This commit is contained in:
parent
ba6237d822
commit
19d58583c0
14
src/main.rs
14
src/main.rs
|
@ -12,7 +12,6 @@ fn main() {
|
|||
let mut verbose = false;
|
||||
let mut host = "localhost".to_string();
|
||||
let mut port = 3000; // TODO: change to 300
|
||||
//let mut root_dir = format!("/home/{}/public_spartan/", "username");
|
||||
// Arguments
|
||||
{
|
||||
let mut ap = ArgumentParser::new();
|
||||
|
@ -44,6 +43,7 @@ fn main() {
|
|||
|
||||
fn handle_connection(mut stream: TcpStream) {
|
||||
let mut buffer = [0; 1024];
|
||||
let root_dir = "/home/g1n/public_spartan/";
|
||||
|
||||
stream.read(&mut buffer).unwrap();
|
||||
println!("{}", String::from_utf8_lossy(&buffer[..]));
|
||||
|
@ -67,7 +67,7 @@ fn handle_connection(mut stream: TcpStream) {
|
|||
let get = format!( "{} {} {}\r\n {}\r\n", host, _path, _post_len, _post);
|
||||
let _get_bytes = get.as_bytes();
|
||||
|
||||
let status_line = if Path::new(&format!("{}{}", "/home/g1n/public_spartan", _path).to_string()).exists() {
|
||||
let status_line = if Path::new(&format!("{}{}", root_dir, _path).to_string()).exists() {
|
||||
"2 text/gemini"
|
||||
} else {
|
||||
"4 Not found"
|
||||
|
@ -80,15 +80,15 @@ fn handle_connection(mut stream: TcpStream) {
|
|||
let _contents = fs::read_to_string(_filename).unwrap();
|
||||
} else { */
|
||||
let mut _contents = "".to_string();
|
||||
let full_path = format!("{}{}", "/home/g1n/public_spartan", _path);
|
||||
let mut exists = Path::new(&format!("{}{}", "/home/g1n/public_spartan", _path).to_string()).exists();
|
||||
let full_path = format!("{}{}", root_dir, _path);
|
||||
let mut exists = Path::new(&format!("{}{}", root_dir, _path).to_string()).exists();
|
||||
if exists {
|
||||
if Path::new(&full_path).is_file(){
|
||||
_contents = fs::read_to_string(format!("{}{}", "/home/g1n/public_spartan", _path)).unwrap();
|
||||
_contents = fs::read_to_string(format!("{}{}", root_dir, _path)).unwrap();
|
||||
} else {
|
||||
exists = Path::new(&format!("{}{}/index.gmi", "/home/g1n/public_spartan", _path).to_string()).exists();
|
||||
exists = Path::new(&format!("{}{}/index.gmi", root_dir, _path).to_string()).exists();
|
||||
if exists {
|
||||
_contents = fs::read_to_string(format!("{}{}index.gmi", "/home/g1n/public_spartan", _path)).unwrap();
|
||||
_contents = fs::read_to_string(format!("{}{}index.gmi", root_dir, _path)).unwrap();
|
||||
} else {
|
||||
_contents = format!("=> ..\n");
|
||||
let path_to_folder = full_path.clone();
|
||||
|
|
Loading…
Reference in New Issue