pub fn dir_listing(path: &str, trim: &str) -> HttpResponse {
	let f;

	match glob::glob(&[path, "/*"].concat()) {
		Ok(fi) => {f = fi},
		Err(_) => {
			return http_error(StatusCode::NOT_FOUND, "404 Not Found", &["The resource ", path, " could not be found."].concat(), false)
		}
	}

	let html = [HEAD, "<title>Directory listing of ", &encode_minimal(&path[trim.len()..]), "</title><h1 class=ok>", FOLDERSVG, "Directory listing of ", &encode_minimal(&path[trim.len()..]), "</h1><table><tr><td><span>Name</span></td><td><span>Size</span></td></tr><tr><td><a href='..'>", BACKSVG, "Back</a></td></tr>"].concat();
	let (mut html1, mut html2) = ("".to_owned(), "".to_owned());
	for fpath in f {
		let fstr = fpath.unwrap();
		let (name, size, icon);
		match fstr.file_name() {
			Some(fst) => {name = fst.to_string_lossy()},
			None => {
				return http_error(StatusCode::NOT_FOUND, "500 Internal Server Error", "An unexpected condition was encountered.", false)
			}
		}
		let mut namep = fstr.to_string_lossy()[trim.len()..].to_owned();
		if namep.ends_with(".br") {
			continue
		}
		if let Ok(fmeta) = fstr.metadata() {
			size = fmeta.len();
			if fmeta.is_dir() {
				icon = FOLDERSVG;
				namep.push_str("/")
			} else {
				icon = FILESVG
			}
		} else {
			size = 0;
			icon = FILESVG
		}

		let link = &encode_attribute(&utf8_percent_encode(&namep, ENCODE_SET).collect::<String>());
		let mut sizestr = "".to_owned();
		if icon != FOLDERSVG {
			match NumberPrefix::decimal(size as f64) {
				Standalone(bytes)   => {sizestr = [bytes.to_string(), "b".to_owned()].concat()}
				Prefixed(prefix, n) => {sizestr = [&((n*10_f64).round()/10_f64).to_string(), prefix.symbol()].concat()}
			}
			html2 = [&html2, "<tr><td><a href='", link, "'>", icon, &encode_minimal(name.borrow()), "</td><td><span>", &sizestr, "</span></a></td></tr>"].concat();
			continue
		}

		html1 = [&html1, "<tr><td><a href='", link, "'>", icon, &encode_minimal(name.borrow()), "</td><td><span>", &sizestr, "</span></a></td></tr>"].concat();
	}

	// Return file listing page
	let html = [html, html1, html2, "</table><span class=btmright>Powered by KatWebX</span>".to_owned()].concat();
	HttpResponse::Ok()
		.encoding(ContentEncoding::Auto)
		.header(header::SERVER, "KatWebX")
		.content_type("text/html; charset=utf-8")
		.body(html)
}
// dir_listing generates a webpage that lists the contents of a directory.
dir_listing generates a webpage that lists the contents of a directory.
dir_listing generates a webpage that lists the contents of a directory .
pub fn dir_listing(path: &str, trim: &str) -> HttpResponse {
	let f;
	match glob::glob(&[path, "/*"].concat()) {
		Ok(fi) => {f = fi},
		Err(_) => {
			return http_error(StatusCode::NOT_FOUND, "404 Not Found", &["The resource ", path, " could not be found."].concat(), false)
		}
	}
	let html = [HEAD, "<title>Directory listing of ", &encode_minimal(&path[trim.len()..]), "</title><h1 class=ok>", FOLDERSVG, "Directory listing of ", &encode_minimal(&path[trim.len()..]), "</h1><table><tr><td><span>Name</span></td><td><span>Size</span></td></tr><tr><td><a href='..'>", BACKSVG, "Back</a></td></tr>"].concat();
	let (mut html1, mut html2) = ("".to_owned(), "".to_owned());
	for fpath in f {
		let fstr = fpath.unwrap();
		let (name, size, icon);
		match fstr.file_name() {
			Some(fst) => {name = fst.to_string_lossy()},
			None => {
				return http_error(StatusCode::NOT_FOUND, "500 Internal Server Error", "An unexpected condition was encountered.", false)
			}
		}
		let mut namep = fstr.to_string_lossy()[trim.len()..].to_owned();
		if namep.ends_with(".br") {
			continue
		}
		if let Ok(fmeta) = fstr.metadata() {
			size = fmeta.len();
			if fmeta.is_dir() {
				icon = FOLDERSVG;
				namep.push_str("/")
			} else {
				icon = FILESVG
			}
		} else {
			size = 0;
			icon = FILESVG
		}
		let link = &encode_attribute(&utf8_percent_encode(&namep, ENCODE_SET).collect::<String>());
		let mut sizestr = "".to_owned();
		if icon != FOLDERSVG {
			match NumberPrefix::decimal(size as f64) {
				Standalone(bytes)   => {sizestr = [bytes.to_string(), "b".to_owned()].concat()}
				Prefixed(prefix, n) => {sizestr = [&((n*10_f64).round()/10_f64).to_string(), prefix.symbol()].concat()}
			}
			html2 = [&html2, "<tr><td><a href='", link, "'>", icon, &encode_minimal(name.borrow()), "</td><td><span>", &sizestr, "</span></a></td></tr>"].concat();
			continue
		}
		html1 = [&html1, "<tr><td><a href='", link, "'>", icon, &encode_minimal(name.borrow()), "</td><td><span>", &sizestr, "</span></a></td></tr>"].concat();
	}
	// Return file listing page
	let html = [html, html1, html2, "</table><span class=btmright>Powered by KatWebX</span>".to_owned()].concat();
	HttpResponse::Ok()
		.encoding(ContentEncoding::Auto)
		.header(header::SERVER, "KatWebX")
		.content_type("text/html; charset=utf-8")
		.body(html)
}
pub fn dir_listing ( path : & str , trim : & str ) -> HttpResponse { let f ; match glob :: glob ( & [ path , " " ] . concat ( ) ) { Ok ( fi ) => { f = fi } , Err ( _ ) => { return http_error ( StatusCode :: NOT_FOUND , " " , & [ " " , path , " " ] . concat ( ) , false ) } } let html = [ HEAD , " " , & encode_minimal ( & path [ trim . len ( ) .. ] ) , " " , FOLDERSVG , " " , & encode_minimal ( & path [ trim . len ( ) .. ] ) , " " , BACKSVG , " " ] . concat ( ) ; let ( mut html1 , mut html2 ) = ( " " . to_owned ( ) , " " . to_owned ( ) ) ; for fpath in f { let fstr = fpath . unwrap ( ) ; let ( name , size , icon ) ; match fstr . file_name ( ) { Some ( fst ) => { name = fst . to_string_lossy ( ) } , None => { return http_error ( StatusCode :: NOT_FOUND , " " , " " , false ) } } let mut namep = fstr . to_string_lossy ( ) [ trim . len ( ) .. ] . to_owned ( ) ; if namep . ends_with ( " " ) { continue } if let Ok ( fmeta ) = fstr . metadata ( ) { size = fmeta . len ( ) ; if fmeta . is_dir ( ) { icon = FOLDERSVG ; namep . push_str ( " " ) } else { icon = FILESVG } } else { size = 0 ; icon = FILESVG } let link = & encode_attribute ( & utf8_percent_encode ( & namep , ENCODE_SET ) . collect :: < String > ( ) ) ; let mut sizestr = " " . to_owned ( ) ; if icon != FOLDERSVG { match NumberPrefix :: decimal ( size as f64 ) { Standalone ( bytes ) => { sizestr = [ bytes . to_string ( ) , " " . to_owned ( ) ] . concat ( ) } Prefixed ( prefix , n ) => { sizestr = [ & ( ( n * 10_f64 ) . round ( ) / 10_f64 ) . to_string ( ) , prefix . symbol ( ) ] . concat ( ) } } html2 = [ & html2 , " " , link , " " , icon , & encode_minimal ( name . borrow ( ) ) , " " , & sizestr , " " ] . concat ( ) ; continue } html1 = [ & html1 , " " , link , " " , icon , & encode_minimal ( name . borrow ( ) ) , " " , & sizestr , " " ] . concat ( ) ; } // Return file listing page let html = [ html , html1 , html2 , " " . to_owned ( ) ] . concat ( ) ; HttpResponse :: Ok ( ) . encoding ( ContentEncoding :: Auto ) . header ( header :: SERVER , " " ) . content_type ( " " ) . body ( html ) }
dir_listing generates a webpage that lists the contents of a directory.
dir_listing generates a webpage that lists the contents of a directory .
path
&str
trim
&str
path
&str
trim
&str