diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a6f120..2cc398a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ if(NOT userver_FOUND) # Fallback to subdirectory usage if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/userver) message(STATUS "Using userver framework from third_party/userver") - add_subdirectory(third_party/userver) + add_subdirectory(third_party/userver EXCLUDE_FROM_ALL) else() message(FATAL_ERROR "Either install the userver or provide a path to it") endif() diff --git a/Makefile b/Makefile index 077aeef..1787685 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,7 @@ PROJECT_NAME = upastebin NPROCS ?= $(shell nproc) CLANG_FORMAT ?= clang-format -DOCKER_IMAGE ?= ghcr.io/userver-framework/ubuntu-24.04-userver:latest CMAKE_OPTS ?= -# If we're under TTY, pass "-it" to "docker run" -DOCKER_ARGS = $(shell /bin/test -t 0 && /bin/echo -it || echo) PRESETS ?= debug release debug-custom release-custom .PHONY: all @@ -68,11 +65,4 @@ format: # and still able to access the results. .PHONY: $(addprefix docker-cmake-, $(PRESETS)) $(addprefix docker-build-, $(PRESETS)) $(addprefix docker-test-, $(PRESETS)) $(addprefix docker-clean-, $(PRESETS)) $(addprefix docker-cmake-, $(PRESETS)) $(addprefix docker-build-, $(PRESETS)) $(addprefix docker-test-, $(PRESETS)) $(addprefix docker-clean-, $(PRESETS)): docker-%: - docker run $(DOCKER_ARGS) \ - --network=host \ - -v $$PWD:$$PWD \ - -w $$PWD \ - $(DOCKER_IMAGE) \ - env CCACHE_DIR=$$PWD/.ccache \ - HOME=$$HOME \ - $$PWD/run_as_user.sh $(shell /bin/id -u) $(shell /bin/id -g) make $* + docker compose run --rm upastebin-container make $* diff --git a/docker-compose.yml b/docker-compose.yml index 66aa8fb..2d6a464 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ version: "2.3" services: postgres: container_name: service-postgres - image: postgres:12 + image: postgres:18 environment: &db_env POSTGRES_DB: upastebin_db_1 POSTGRES_USER: user @@ -17,12 +17,13 @@ services: - postgres upastebin-container: - image: ghcr.io/userver-framework/ubuntu-22.04-userver-pg:latest + image: ghcr.io/userver-framework/ubuntu-24.04-userver:latest privileged: true environment: <<: *db_env PREFIX: ${PREFIX:-~/.local} CCACHE_DIR: /upastebin/.ccache + UV_CACHE_DIR: /upastebin/.uv-cache CORES_DIR: /cores volumes: - .:/upastebin:rw diff --git a/src/resources.cpp b/src/resources.cpp index 83a7e6d..880e08d 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace upastebin { @@ -39,11 +40,19 @@ std::string ResourcesHandler::HandleRequestThrow( auto file_ptr = fs_client_.TryGetFile("/" + subpath); auto& response = request.GetHttpResponse(); if (file_ptr) { - response.SetContentType(GetContentType(file_ptr->extension)); - response.SetHeader(USERVER_NAMESPACE::http::headers::kExpires, "600"); - return file_ptr->data; + return userver::utils::Visit( + file_ptr->data_or_path, + [&](const std::string& data) { + response.SetContentType(GetContentType(file_ptr->extension)); + response.SetHeader(USERVER_NAMESPACE::http::headers::kExpires, "600"); + return data; + }, + [&](const auto& path) { + response.SetStatus(userver::server::http::HttpStatus::kPayloadTooLarge); + return std::string{}; + } + ); } else { - auto& response = request.GetHttpResponse(); response.SetStatus(userver::server::http::HttpStatus::kNotFound); return {}; } diff --git a/src/text.cpp b/src/text.cpp index c30e824..5691559 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -2,6 +2,7 @@ #include #include +#include namespace upastebin { @@ -23,7 +24,14 @@ std::string TextHandler::HandleRequestThrow( auto& response = request.GetHttpResponse(); response.SetContentType("text/html; charset=UTF-8"); - return file_ptr->data; + return userver::utils::Visit( + file_ptr->data_or_path, + [](const std::string& data) { return data; }, + [&response](const auto& path) { + response.SetStatus(userver::server::http::HttpStatus::kPayloadTooLarge); + return std::string{}; + } + ); } } // namespace upastebin