Disable timeouts for upload/download
All checks were successful
/ Build the server (push) Successful in 5m39s

This commit is contained in:
Mutzi 2024-05-21 14:51:58 +02:00
parent 430ef15f83
commit 7177146a56
Signed by: root
GPG Key ID: 2437494E09F13876
2 changed files with 12 additions and 0 deletions

View File

@ -34,6 +34,8 @@ net::awaitable<void> Server::download(tcp_stream &s, const http::request<http::s
auto node = get_node(user, node_id); auto node = get_node(user, node_id);
if (!node) { co_await send_error(s, req, "Invalid node"); co_return; } if (!node) { co_await send_error(s, req, "Invalid node"); co_return; }
s.expires_never();
beast::error_code ec; beast::error_code ec;
auto mime = get_mime_type(node->name); auto mime = get_mime_type(node->name);
auto res = create_response<http::status::ok, http::file_body, http::string_body>(req); auto res = create_response<http::status::ok, http::file_body, http::string_body>(req);
@ -42,6 +44,8 @@ net::awaitable<void> Server::download(tcp_stream &s, const http::request<http::s
res.set(http::field::content_disposition, "attachment; filename=\"" + node->name + "\""); res.set(http::field::content_disposition, "attachment; filename=\"" + node->name + "\"");
res.body().open((user->user_dir / std::to_string(node->id)).c_str(), beast::file_mode::read, ec); res.body().open((user->user_dir / std::to_string(node->id)).c_str(), beast::file_mode::read, ec);
co_await http::async_write(s, res, net::use_awaitable); co_await http::async_write(s, res, net::use_awaitable);
s.expires_after(std::chrono::seconds(30));
} }
struct Zip : public ZipArchive { struct Zip : public ZipArchive {
@ -113,6 +117,8 @@ net::awaitable<void> Server::download_multi(tcp_stream &s, const http::request<h
res.body().data = nullptr; res.body().data = nullptr;
res.body().more = true; res.body().more = true;
s.expires_never();
http::response_serializer<http::buffer_body> sr{res}; http::response_serializer<http::buffer_body> sr{res};
co_await http::async_write_header(s, sr, net::use_awaitable); co_await http::async_write_header(s, sr, net::use_awaitable);
@ -145,4 +151,6 @@ net::awaitable<void> Server::download_multi(tcp_stream &s, const http::request<h
res.body().data = nullptr; res.body().data = nullptr;
res.body().more = false; res.body().more = false;
co_await http::async_write(s, sr, net::use_awaitable); co_await http::async_write(s, sr, net::use_awaitable);
s.expires_after(std::chrono::seconds(30));
} }

View File

@ -67,6 +67,8 @@ net::awaitable<void> Server::upload(tcp_stream &s, tcp_buffer &buf, http::reques
std::filesystem::remove(path.replace_extension("png")); std::filesystem::remove(path.replace_extension("png"));
} }
s.expires_never();
std::exception_ptr ex_ptr; std::exception_ptr ex_ptr;
beast::error_code ec; beast::error_code ec;
body.body().open(path.c_str(), beast::file_mode::write, ec); body.body().open(path.c_str(), beast::file_mode::write, ec);
@ -92,6 +94,8 @@ net::awaitable<void> Server::upload(tcp_stream &s, tcp_buffer &buf, http::reques
res.keep_alive(false); res.keep_alive(false);
co_await http::async_write(s, res, net::use_awaitable); co_await http::async_write(s, res, net::use_awaitable);
s.expires_after(std::chrono::seconds(30));
if (ex_ptr) if (ex_ptr)
rethrow_exception(ex_ptr); rethrow_exception(ex_ptr);
} }