From 70643a9e4821bd11c3f363f1708fe420965467d1 Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Fri, 28 Aug 2026 22:17:10 +0200 Subject: Format again --- server/src/srv.cppm | 94 ++++++++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 48 deletions(-) (limited to 'server/src/srv.cppm') diff --git a/server/src/srv.cppm b/server/src/srv.cppm index d9ff880..5763bc5 100644 --- a/server/src/srv.cppm +++ b/server/src/srv.cppm @@ -63,17 +63,17 @@ public: auto unwrap() -> gpx::file&& { return std::visit( - util::overloaded{ - [](std::exception_ptr ex) -> gpx::file&& - { - if (ex) - std::rethrow_exception(ex); - else - throw std::runtime_error{"no GPX file parse result available"}; - }, - [](gpx::file&& f) -> gpx::file&& { return std::move(f); }, + util::overloaded{ + [](std::exception_ptr ex) -> gpx::file&& + { + if (ex) + std::rethrow_exception(ex); + else + throw std::runtime_error{"no GPX file parse result available"}; }, - std::move(res_)); + [](gpx::file&& f) -> gpx::file&& { return std::move(f); }, + }, + std::move(res_)); } }; @@ -100,7 +100,7 @@ struct readable_gpx_body auto init(boost::optional /* n */, beast::error_code& ec) noexcept - -> void + -> void { try { @@ -114,9 +114,9 @@ struct readable_gpx_body } } - auto - put(beast::concepts::const_buffer_sequence auto b, - beast::error_code& ec) noexcept -> std::size_t + auto put( + beast::concepts::const_buffer_sequence auto b, + beast::error_code& ec) noexcept -> std::size_t { auto total = 0uz; try @@ -125,9 +125,7 @@ struct readable_gpx_body it != net::buffer_sequence_end(b); it++) { r_.put( - std::string_view{ - static_cast(it->data()), it->size() - }); + std::string_view{static_cast(it->data()), it->size()}); total += it->size(); } ec = {}; @@ -168,25 +166,25 @@ public: private: auto handle_process_gpx(l0_ctx ctx, http::readable_request r) - -> net::awaitable + -> net::awaitable { auto gpx_file = gpx::file{}; try { auto req = - co_await http::read_request(ctx, std::move(r)); + co_await http::read_request(ctx, std::move(r)); gpx_file = std::move(req->body().unwrap()); } catch (std::exception& ex) { // TODO: more detailed problem reporting auto tpl = problem::tpl{ - .status = bhttp::status::bad_request, - .title = translate("Failed to parse GPX file"), - .type_uri = "https://routemon.fautchen.eu/problems/gpx-parse-failed", + .status = bhttp::status::bad_request, + .title = translate("Failed to parse GPX file"), + .type_uri = "https://routemon.fautchen.eu/problems/gpx-parse-failed", }; co_return http::problem_rsp( - ctx, tpl.instantiate(), http::keep_alive{false}); + ctx, tpl.instantiate(), http::keep_alive{false}); } // TODO: catch handler exceptions and return 500 when raised? @@ -195,17 +193,17 @@ private: if (!mres) { auto tpl = problem::tpl{ - .status = bhttp::status::internal_server_error, - .title = translate("Internal server error"), - .type_uri = "https://routemon.fautchen.eu/problems/" - "internal-server-error", + .status = bhttp::status::internal_server_error, + .title = translate("Internal server error"), + .type_uri = "https://routemon.fautchen.eu/problems/" + "internal-server-error", }; co_return http::problem_rsp( - ctx, tpl.instantiate(), http::keep_alive{true}); + ctx, tpl.instantiate(), http::keep_alive{true}); } auto rsp = http::make_rsp( - bhttp::status::ok, http::keep_alive{true}); + bhttp::status::ok, http::keep_alive{true}); rsp.set(bhttp::field::content_type, "application/json"); rsp.body() = json::serialize(json::value_from(*mres)); rsp.prepare_payload(); @@ -213,14 +211,14 @@ private: } auto handle_sysinfo(l0_ctx ctx, http::readable_request r) - -> net::awaitable + -> net::awaitable { auto req = - co_await http::read_request(ctx, std::move(r)); + co_await http::read_request(ctx, std::move(r)); auto info = inner_.sysinfo(); auto rsp = http::make_rsp( - bhttp::status::ok, http::keep_alive{true}); + bhttp::status::ok, http::keep_alive{true}); rsp.set(bhttp::field::content_type, "application/json"); rsp.body() = json::serialize(json::value_from(info)); rsp.prepare_payload(); @@ -236,17 +234,17 @@ public: { return std::bind_front(member, this); }; return http::dtree>{}.named_subtrees({ - {"gpx", - http::dtree{ - { - .post = handler(&handler::handle_process_gpx), - } - }.no_subtrees()}, - {"sysinfo", http::dtree{ - { - .get = handler(&handler::handle_sysinfo), - } - }.no_subtrees()}, + {"gpx", + http::dtree{ + { + .post = handler(&handler::handle_process_gpx), + } + }.no_subtrees()}, + {"sysinfo", http::dtree{ + { + .get = handler(&handler::handle_sysinfo), + } + }.no_subtrees()}, }); } }; @@ -257,13 +255,13 @@ export class server http::server srv_; static auto make_global_middleware() - -> http::middleware_t + -> http::middleware_t { return http::middleware_compose< - http::base_ctx, http::trace_id_ctx, - http::trace_id_ctx>( - http::trace_id_middleware, - http::lax_cors_middleware>); + http::base_ctx, http::trace_id_ctx, + http::trace_id_ctx>( + http::trace_id_middleware, + http::lax_cors_middleware>); } public: -- cgit v1.3