feat: serve pastes
parent
00fa4a7c8c
commit
7af4be12ff
|
@ -1,20 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.20)
|
||||
project(lander C CXX)
|
||||
|
||||
set(CMAKE_C_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
include_directories(trie/include)
|
||||
add_subdirectory(crow)
|
||||
add_subdirectory(trie)
|
||||
|
||||
if(CMAKE_BUILD_TYPE MATCHES "^Test")
|
||||
enable_testing()
|
||||
else()
|
||||
if(CMAKE_BUILD_TYPE STREQUAL Release)
|
||||
add_compile_options(-O3 -flto)
|
||||
endif()
|
||||
|
||||
add_executable(lander src/main.cpp)
|
||||
target_link_libraries(lander PUBLIC Crow::Crow trie)
|
||||
endif()
|
|
@ -28,7 +28,7 @@ bool lander_get_entry(event_loop_conn *conn) {
|
|||
http_loop_ctx *ctx = conn->ctx;
|
||||
|
||||
const char *key = &ctx->req.path[ctx->req.regex_groups[1].rm_so];
|
||||
size_t key_len =
|
||||
int key_len =
|
||||
ctx->req.regex_groups[1].rm_eo - ctx->req.regex_groups[1].rm_so;
|
||||
|
||||
Entry *entry;
|
||||
|
@ -39,6 +39,11 @@ bool lander_get_entry(event_loop_conn *conn) {
|
|||
} else if (entry->type == Redirect) {
|
||||
ctx->res.type = http_moved_permanently;
|
||||
http_loop_res_add_header(ctx, http_header_location, entry->string, false);
|
||||
} else if (entry->type == Paste) {
|
||||
char fname[8 + key_len];
|
||||
sprintf(fname, "pastes/%.*s", key_len, key);
|
||||
|
||||
http_loop_res_set_body_file(ctx, fname);
|
||||
}
|
||||
|
||||
conn->state = event_loop_conn_state_res;
|
||||
|
|
Loading…
Reference in New Issue