fix:修正编译和tss-http浏览器乱码问题。
This commit is contained in:
parent
60f52a14d2
commit
b9c7cbba3c
@ -9,6 +9,10 @@ if (MSVC)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(tss-http main.cpp)
|
add_executable(tss-http main.cpp)
|
||||||
|
if (UNIX)
|
||||||
|
target_link_libraries(tss-http PRIVATE pthread)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND uname -a
|
COMMAND uname -a
|
||||||
|
@ -51,7 +51,6 @@ std::string ansi_to_u8(const std::string& str)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 生成文件列表的HTML页面
|
|
||||||
// 生成文件列表的HTML页面
|
// 生成文件列表的HTML页面
|
||||||
std::string generate_file_list(const std::string& base_path, const std::string& current_path)
|
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();
|
uintmax_t file_size = entry.file_size();
|
||||||
double size_mb = file_size / (1024.0 * 1024.0);
|
double size_mb = file_size / (1024.0 * 1024.0);
|
||||||
char size_str[20];
|
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"(<li class="file"><a href="/download/)" + new_path + R"(">)" + filename + R"(</a><span class="size">)" +
|
html += R"(<li class="file"><a href="/download/)" + new_path + R"(">)" + filename + R"(</a><span class="size">)" +
|
||||||
size_str + R"(</span></li>)";
|
size_str + R"(</span></li>)";
|
||||||
@ -170,12 +169,13 @@ int main(int argc, char** argv)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
res.set_header("Content-Type", "text/html; charset=utf-8");
|
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) {
|
server.Get("/download/(.*)", [&base_dir](const httplib::Request& req, httplib::Response& res) {
|
||||||
std::string path = req.matches[1];
|
std::string path = req.matches[1];
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
path = u8_to_ansi(path);
|
path = u8_to_ansi(path);
|
||||||
#endif
|
#endif
|
||||||
|
@ -27,10 +27,15 @@ add_executable(encry_correct_test EncryptCorrect.cxx ${TEST_SOURCES})
|
|||||||
add_executable(encry_speed_test EncryptSpeed.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_correct_test PRIVATE tinyaes trans_util)
|
||||||
target_link_libraries(encry_speed_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})
|
add_executable(transm_cmd_test Cmd.cxx ${TRANSM_TEST_SOURCES})
|
||||||
target_link_libraries(transm_cmd_test PRIVATE trans_net trans_util)
|
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()
|
enable_testing()
|
||||||
add_test(NAME EncryCorrectTest COMMAND encry_correct_test)
|
add_test(NAME EncryCorrectTest COMMAND encry_correct_test)
|
||||||
add_test(NAME EncrySpeedTest COMMAND encry_speed_test -s)
|
add_test(NAME EncrySpeedTest COMMAND encry_speed_test -s)
|
||||||
|
@ -15,7 +15,7 @@ std::shared_ptr<ClientConfig> config;
|
|||||||
|
|
||||||
asio::io_context server_context;
|
asio::io_context server_context;
|
||||||
|
|
||||||
constexpr char* ip = "127.0.0.1";
|
constexpr auto ip = "127.0.0.1";
|
||||||
constexpr unsigned short port = 9897;
|
constexpr unsigned short port = 9897;
|
||||||
bool server_suc = false;
|
bool server_suc = false;
|
||||||
constexpr unsigned int max_wait = 3000;
|
constexpr unsigned int max_wait = 3000;
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#ifdef USE_BOOST
|
#ifdef USE_BOOST
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user