Skip to content

Commit

Permalink
refactor: improve mediator routes
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Prazak <ondrej.prazak@absa.africa>
  • Loading branch information
Ondrej Prazak committed Apr 9, 2024
1 parent 7eb7faf commit da41d0f
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 36 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion aries/agents/mediator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ axum-macros = "0.3.8"
diddoc_legacy = { path = "../../misc/legacy/diddoc_legacy" }
dotenvy = "0.15"
env_logger = "0.10.0"
fast_qr = { version = "0.10.2", features = ["svg"] }
futures = "0.3.28"
log = "0.4.20"
messages = { path = "../../messages" }
Expand Down
29 changes: 1 addition & 28 deletions aries/agents/mediator/src/http_routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,6 @@ use crate::{
persistence::MediatorPersistence,
};

pub async fn oob_invite_qr(
headers: HeaderMap,
State(agent): State<ArcAgent<impl BaseWallet, impl MediatorPersistence>>,
) -> Response {
let Json(oob_json) = oob_invite_json(State(agent)).await;
match detect_mime_type(&headers) {
"application/json" => Json(oob_json).into_response(),
_ => {
let oob_string = serde_json::to_string_pretty(&oob_json).unwrap();
let qr = fast_qr::QRBuilder::new(oob_string.clone()).build().unwrap();
let oob_qr_svg = fast_qr::convert::svg::SvgBuilder::default().to_str(&qr);
Html(format!(
"<style>
svg {{
width: 50%;
height: 50%;
}}
</style>
{oob_qr_svg} <br>
<pre>{oob_string}</pre>"
))
.into_response()
}
}
}

fn detect_mime_type(headers: &HeaderMap) -> &str {
headers
.get(ACCEPT)
Expand Down Expand Up @@ -89,8 +63,7 @@ pub async fn build_router(
) -> Router {
Router::default()
.route("/", get(readme))
.route("/register", get(oob_invite_qr))
.route("/register.json", get(oob_invite_json))
.route("/invitation", get(oob_invite_json))
.route("/didcomm", get(handle_didcomm).post(handle_didcomm))
.layer(tower_http::catch_panic::CatchPanicLayer::new())
.with_state(Arc::new(agent))
Expand Down

0 comments on commit da41d0f

Please sign in to comment.