🚧 Can index directories now, but a lot of stuff is missing
parent
af226cb36c
commit
8a301a6d03
|
@ -83,7 +83,7 @@ impl <'a> ResponseHandle <'a> {
|
||||||
|
|
||||||
async fn serve_dir (
|
async fn serve_dir (
|
||||||
response_handle: ResponseHandle <'_>,
|
response_handle: ResponseHandle <'_>,
|
||||||
dir: ReadDir
|
mut dir: ReadDir
|
||||||
) {
|
) {
|
||||||
let (tx, rx) = channel (2);
|
let (tx, rx) = channel (2);
|
||||||
|
|
||||||
|
@ -92,8 +92,35 @@ async fn serve_dir (
|
||||||
|
|
||||||
tx.send (Ok::<_, Infallible> (String::from ("<style>body {font-family:sans;}</style><ul>").into_bytes ())).await.unwrap ();
|
tx.send (Ok::<_, Infallible> (String::from ("<style>body {font-family:sans;}</style><ul>").into_bytes ())).await.unwrap ();
|
||||||
|
|
||||||
for i in 0u8..10 {
|
while let Ok (entry) = dir.next_entry ().await {
|
||||||
let s = format! ("<li><a href=\"{}\">Dir entry {}</a></li>\n", i, i);
|
let entry: tokio::fs::DirEntry = match entry {
|
||||||
|
Some (x) => x,
|
||||||
|
None => break,
|
||||||
|
};
|
||||||
|
|
||||||
|
let trailing_slash = match entry.file_type ().await {
|
||||||
|
Ok (t) => if t.is_dir () {
|
||||||
|
"/"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
""
|
||||||
|
},
|
||||||
|
Err (_) => "",
|
||||||
|
};
|
||||||
|
|
||||||
|
let file_name = match entry.file_name ().into_string () {
|
||||||
|
Ok (x) => x,
|
||||||
|
Err (_) => {
|
||||||
|
let s = format! ("<li>(file_name error)</li>\n");
|
||||||
|
if tx.send (Ok::<_, Infallible> (s.into_bytes ())).await.is_err ()
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let s = format! ("<li><a href=\"{}{}\">{}{}</a></li>\n", file_name, trailing_slash, file_name, trailing_slash);
|
||||||
if tx.send (Ok::<_, Infallible> (s.into_bytes ())).await.is_err ()
|
if tx.send (Ok::<_, Infallible> (s.into_bytes ())).await.is_err ()
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|
2
todo.md
2
todo.md
|
@ -1,5 +1,5 @@
|
||||||
- Index directories
|
|
||||||
- Handle trailing slash problem for directories
|
- Handle trailing slash problem for directories
|
||||||
|
- Handle URL encoding for spaces in file names
|
||||||
- Set up tokens or something so clients can't trivially
|
- Set up tokens or something so clients can't trivially
|
||||||
impersonate servers
|
impersonate servers
|
||||||
- Fix possible timing gap when refreshing http_listen (Just have client wait a few seconds?)
|
- Fix possible timing gap when refreshing http_listen (Just have client wait a few seconds?)
|
||||||
|
|
Loading…
Reference in New Issue