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