Fix listing of S3 prefixes not terminated by a slash #3
Loading…
Reference in New Issue
No description provided.
Delete Branch "eay/serves3:hackathon_slash_fix_erik_and_eren"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #2.
fix listing of S3 prefixes not terminated by a slashto Fix listing of S3 prefixes not terminated by a slashThank you for your contribution! Could you perform some of the requested changes? They are only minor points.
And thanks for adding a unit test!
@ -185,6 +187,7 @@ async fn s3_fileview(path: &PathBuf) -> Result<Vec<FileViewItem>, Error> {
let files = list.contents.iter().map(|obj| {
let path = obj.key.strip_prefix(&prefix);
path.map(|path| FileViewItem {
parent:s3_folder_path.clone(),
The last usage of a string can simply be moved instead of cloned to avoid a needless copy.
@ -241,0 +247,4 @@
#[cfg(test)]
mod tests {
use rstest::rstest;
// Note this useful idiom: importing names from outer (for mod tests) scope.
Remove comment
@ -241,0 +260,4 @@
#[case(u64::MIN, format!("{:.3} B",u64::MIN as f64))]
fn test_size_bytes_to_human(#[case] bytes: u64, #[case] expected: String) {
println!("{}",size_bytes_to_human(bytes));
Formatting, please run
cargo fmt
on the sources@ -45,3 +45,3 @@
{% for object in objects %}
<tr>
<td><a href="{{ object.path | urlencode }}" data-size-bytes="{{ object.size_bytes }}">{{ object.path }}</a></td>
<td><a href="/{{ object.parent | urlencode }}{{ object.path | urlencode }}" data-size-bytes="{{ object.size_bytes }}">{{ object.path }}</a></td>
This way of making paths absolutes would not work if the service was to be deployed as a subfolder instead than a virtualhost in the HTTP server configuration.
Imagine the service running via a reverse proxy at
https://some.website.com/subfolder
.Then a link of the form
/parent/object
would resolve tohttps://some.website.com/parent/object
instead ofhttps://some.website.com/subfolder/parent/object
.It is therefore better to use the uri! macro to build the path instead. Could you please move the building of the URI in the Rust portion of the code, and here just use the computed result?
Rocket can be configured then to handle this correctly (which is up to the end user).
73da6a8f5f
to4defbcec1f
@eay I refactored the code to add integration tests and a more sane structure.
However, I don't seem to be able to reproduce the original problem anymore with my tests.
Could you try on your side to see if the problem is still there, and eventually adapt the tests accordingly? Thanks!