mirror of
https://github.com/YGGverse/nexy.git
synced 2026-03-31 17:25:27 +00:00
give semantical names to response members
This commit is contained in:
parent
90b8b8c921
commit
23c9c1b96e
3 changed files with 53 additions and 36 deletions
|
|
@ -50,18 +50,25 @@ impl Public {
|
|||
match p.canonicalize() {
|
||||
Ok(c) => {
|
||||
if !c.starts_with(&self.public_dir) {
|
||||
return callback(Response::AccessDenied(query));
|
||||
return callback(Response::AccessDenied { query });
|
||||
}
|
||||
c
|
||||
}
|
||||
Err(_) => return callback(Response::NotFound(query)),
|
||||
Err(_) => return callback(Response::NotFound { query }),
|
||||
}
|
||||
};
|
||||
match fs::metadata(&p) {
|
||||
Ok(t) => match (t.is_dir(), t.is_file()) {
|
||||
(true, _) => callback(match self.list(&p) {
|
||||
Ok(list) => Response::Directory(query, list, p == self.public_dir),
|
||||
Err(e) => Response::InternalServerError(Some(query), e.to_string()),
|
||||
Ok(data) => Response::Directory {
|
||||
query,
|
||||
data,
|
||||
is_root: p == self.public_dir,
|
||||
},
|
||||
Err(e) => Response::InternalServerError {
|
||||
query: Some(query),
|
||||
error: e.to_string(),
|
||||
},
|
||||
}),
|
||||
(_, true) => match fs::File::open(p) {
|
||||
Ok(mut f) => loop {
|
||||
|
|
@ -74,24 +81,24 @@ impl Public {
|
|||
}
|
||||
}
|
||||
Err(e) => {
|
||||
return callback(Response::InternalServerError(
|
||||
Some(query),
|
||||
format!("failed to read response chunk: `{e}`"),
|
||||
));
|
||||
return callback(Response::InternalServerError {
|
||||
query: Some(query),
|
||||
error: format!("failed to read response chunk: `{e}`"),
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(e) => callback(Response::InternalServerError(
|
||||
Some(query),
|
||||
format!("failed to read response: `{e}`"),
|
||||
)),
|
||||
Err(e) => callback(Response::InternalServerError {
|
||||
query: Some(query),
|
||||
error: format!("failed to read response: `{e}`"),
|
||||
}),
|
||||
},
|
||||
_ => panic!(), // unexpected
|
||||
},
|
||||
Err(e) => callback(Response::InternalServerError(
|
||||
Some(query),
|
||||
format!("failed to read storage: `{e}`"),
|
||||
)),
|
||||
Err(e) => callback(Response::InternalServerError {
|
||||
query: Some(query),
|
||||
error: format!("failed to read storage: `{e}`"),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue