From b9c7cbba3c75bb8ffd8459e04a09e3910cdb2165 Mon Sep 17 00:00:00 2001 From: taynpg Date: Tue, 29 Apr 2025 12:49:47 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E6=AD=A3=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E5=92=8Ctss-http=E6=B5=8F=E8=A7=88=E5=99=A8=E4=B9=B1?= =?UTF-8?q?=E7=A0=81=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- http-server/CMakeLists.txt | 4 ++++ http-server/main.cpp | 6 +++--- test/CMakeLists.txt | 7 ++++++- test/Cmd.cxx | 2 +- test/assistant.h | 1 + 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/http-server/CMakeLists.txt b/http-server/CMakeLists.txt index 80d2873..c94a47d 100644 --- a/http-server/CMakeLists.txt +++ b/http-server/CMakeLists.txt @@ -9,6 +9,10 @@ if (MSVC) endif() add_executable(tss-http main.cpp) +if (UNIX) + target_link_libraries(tss-http PRIVATE pthread) +endif() + if(UNIX) execute_process( COMMAND uname -a diff --git a/http-server/main.cpp b/http-server/main.cpp index cb6d9fd..3710e08 100644 --- a/http-server/main.cpp +++ b/http-server/main.cpp @@ -51,7 +51,6 @@ std::string ansi_to_u8(const std::string& str) } #endif -// 生成文件列表的HTML页面 // 生成文件列表的HTML页面 std::string generate_file_list(const std::string& base_path, const std::string& current_path) { @@ -102,7 +101,7 @@ std::string generate_file_list(const std::string& base_path, const std::string& uintmax_t file_size = entry.file_size(); double size_mb = file_size / (1024.0 * 1024.0); char size_str[20]; - snprintf(size_str, sizeof(size_str), "%.2f MB", size_mb); + snprintf(size_str, sizeof(size_str), "%.4f MB", size_mb); html += R"(
  • )" + filename + R"()" + size_str + R"(
  • )"; @@ -170,12 +169,13 @@ int main(int argc, char** argv) return; } res.set_header("Content-Type", "text/html; charset=utf-8"); - res.set_content(generate_file_list(base_dir, path), "text/html"); + res.set_content(generate_file_list(base_dir, path), "text/html; charset=utf-8"); }); // 文件下载路由 server.Get("/download/(.*)", [&base_dir](const httplib::Request& req, httplib::Response& res) { std::string path = req.matches[1]; + #ifdef _WIN32 path = u8_to_ansi(path); #endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d506b55..bf393be 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -27,10 +27,15 @@ add_executable(encry_correct_test EncryptCorrect.cxx ${TEST_SOURCES}) add_executable(encry_speed_test EncryptSpeed.cxx ${TEST_SOURCES}) target_link_libraries(encry_correct_test PRIVATE tinyaes trans_util) target_link_libraries(encry_speed_test PRIVATE tinyaes trans_util) - add_executable(transm_cmd_test Cmd.cxx ${TRANSM_TEST_SOURCES}) target_link_libraries(transm_cmd_test PRIVATE trans_net trans_util) +if (UNIX) +target_link_libraries(encry_speed_test PRIVATE pthread) +target_link_libraries(encry_correct_test PRIVATE pthread) +target_link_libraries(transm_cmd_test PRIVATE pthread) +endif() + enable_testing() add_test(NAME EncryCorrectTest COMMAND encry_correct_test) add_test(NAME EncrySpeedTest COMMAND encry_speed_test -s) diff --git a/test/Cmd.cxx b/test/Cmd.cxx index 9f2d2f8..f1f9d1e 100644 --- a/test/Cmd.cxx +++ b/test/Cmd.cxx @@ -15,7 +15,7 @@ std::shared_ptr config; asio::io_context server_context; -constexpr char* ip = "127.0.0.1"; +constexpr auto ip = "127.0.0.1"; constexpr unsigned short port = 9897; bool server_suc = false; constexpr unsigned int max_wait = 3000; diff --git a/test/assistant.h b/test/assistant.h index 3c42967..99c0d7d 100644 --- a/test/assistant.h +++ b/test/assistant.h @@ -5,6 +5,7 @@ #include #include #include +#include #ifdef USE_BOOST #include