Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/frontend/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,23 @@ async fn get_file(
Ok((StatusCode::OK, Body::from_stream(file_stream)))
}

#[axum_macros::debug_handler]
async fn get_file_extension(Path(name): Path<(String)>) -> Result<impl IntoResponse, AppError> {
debug!("get_file_named called with {name}");

let reencoded =
utf8_percent_encode(&percent_decode_str(&name).decode_utf8()?, FORM).to_string();

if name != reencoded {
return Err(AppError(StatusCode::BAD_REQUEST, anyhow!("Provided file name contains characters that have not been encoded. It should be: {reencoded}")));
}

let pk = Secp256k1PubKey::try_from("")?;
let file_stream = read_file(&pk, &Lookup::Name(name))?;

Ok((StatusCode::OK, StreamBody::new(file_stream)))
}

#[axum_macros::debug_handler]
async fn get_file_named(
Path((pk, name)): Path<(String, String)>,
Expand Down Expand Up @@ -178,6 +195,7 @@ pub async fn start() -> Result<()> {
.route("/remove/:pk/:blake3_hash", delete(remove_file))
.route("/store/:pk", post(post_file))
.route("/store_named/:pk/:name", post(post_file_named))
.route("/retrieve/:named", get(get_file_extension))
.route("/retrieve/:pk/:blake3_hash", get(get_file))
.route("/retrieve_named/:pk/:name", get(get_file_named))
.route("/key/:pk", get(key))
Expand Down