Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 1 addition & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 $*
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
17 changes: 13 additions & 4 deletions src/resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <userver/components/component_config.hpp>
#include <userver/components/component_context.hpp>
#include <userver/components/fs_cache.hpp>
#include <userver/utils/overloaded.hpp>

namespace upastebin {

Expand Down Expand Up @@ -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 {};
}
Expand Down
10 changes: 9 additions & 1 deletion src/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <userver/components/component_context.hpp>
#include <userver/components/fs_cache.hpp>
#include <userver/utils/overloaded.hpp>

namespace upastebin {

Expand All @@ -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
Loading