From 6c5b2d92ac0a8c1fb4a09f498c1f3589e65e82e5 Mon Sep 17 00:00:00 2001 From: amass Date: Wed, 27 Nov 2024 20:23:02 +0800 Subject: [PATCH] readd url filter. --- Server/Application.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/Server/Application.cpp b/Server/Application.cpp index f9115e3..bacea44 100644 --- a/Server/Application.cpp +++ b/Server/Application.cpp @@ -15,6 +15,16 @@ constexpr auto IpcUrl = "ipc:///tmp/nng_ipc_server"; +static std::vector urlFilter = { + "/", + "/search", + "/LoginPage", + "/MessageBoard", + "/我的笔记", + "/我的笔记/", + "/我的博客", +}; + Application::Application(const std::string &path) : ApplicationSettings(path), m_router{std::make_shared>()} { @@ -149,7 +159,8 @@ Application::Application(const std::string &path) url = root["url"].as_string(); } auto database = Database::session(); - if (std::filesystem::exists("amass_blog" + url) && url.find("/我的博客/page") != 0) { + // if (std::filesystem::exists("amass_blog" + url) && url.find("/我的博客/page") != 0) { + { Wt::Dbo::Transaction transaction(*database); auto record = std::make_unique(); record->time = std::chrono::system_clock::now(); @@ -196,13 +207,17 @@ Application::Application(const std::string &path) } auto database = Database::session(); Wt::Dbo::Transaction transaction(*database); - Wt::Dbo::collection> query = database->query>("SELECT url, COUNT(*) as count FROM visitor_record GROUP BY url ORDER BY count DESC LIMIT ?").bind(size); + Wt::Dbo::collection> query = database->query>("SELECT url, COUNT(*) as count FROM visitor_record GROUP BY url ORDER BY count DESC LIMIT ?").bind(static_cast (size+urlFilter.size())); boost::json::array reply; + int index = 0; for (auto &[url, count] : query) { + if (std::find(urlFilter.cbegin(), urlFilter.cend(),url) != urlFilter.cend()) continue; boost::json::object object; object["url"] = url; object["count"] = count; reply.push_back(std::move(object)); + index++; + if(index>=size)break; } http::response s{boost::beast::http::status::ok, request.version()}; s.set(http::field::server, BOOST_BEAST_VERSION_STRING); @@ -232,13 +247,17 @@ Application::Application(const std::string &path) auto database = Database::session(); Wt::Dbo::Transaction transaction(*database); using Reslut = std::tuple; - Wt::Dbo::collection query = database->query("SELECT url, MAX(time) FROM visitor_record GROUP BY url ORDER BY MAX(time) DESC LIMIT ?").bind(size); + Wt::Dbo::collection query = database->query("SELECT url, MAX(time) FROM visitor_record GROUP BY url ORDER BY MAX(time) DESC LIMIT ?").bind(static_cast (size+urlFilter.size())); boost::json::array reply; + int index=0; for (auto &[url, time] : query) { + if (std::find(urlFilter.cbegin(), urlFilter.cend(),url) != urlFilter.cend()) continue; boost::json::object object; object["url"] = url; object["time"] = duration_cast(time.time_since_epoch()).count(); reply.push_back(std::move(object)); + index++; + if(index>=size)break; } http::response s{boost::beast::http::status::ok, request.version()}; s.set(http::field::server, BOOST_BEAST_VERSION_STRING);