From 6b8d6232f03d4f64ca0052e755ebb72fc79f9e0d Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sun, 9 Oct 2022 22:25:21 +0400 Subject: [PATCH] InternalServer::getLibraryId() --- src/server/internalServer.cpp | 12 ++++++++---- src/server/internalServer.h | 3 ++- src/server/internalServer_catalog_v2.cpp | 19 ++++++++++--------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index 50606db4c..c28306a82 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -461,7 +461,6 @@ bool InternalServer::start() { } auto server_start_time = std::chrono::system_clock::now().time_since_epoch(); m_server_id = kiwix::to_string(server_start_time.count()); - m_library_id = m_server_id; return true; } @@ -532,7 +531,7 @@ MHD_Result InternalServer::handlerCallback(struct MHD_Connection* connection, if (response->getReturnCode() == MHD_HTTP_OK && response->get_kind() == Response::DYNAMIC_CONTENT && !etag_not_needed(request)) - response->set_etag_body(m_server_id); + response->set_etag_body(getLibraryId()); auto ret = response->send(request, connection); auto end_time = std::chrono::steady_clock::now(); @@ -554,6 +553,11 @@ bool isEndpointUrl(const std::string& url, const std::string& endpoint) } // unnamed namespace +std::string InternalServer::getLibraryId() const +{ + return m_server_id + "." + kiwix::to_string(mp_library->getRevision()); +} + std::unique_ptr InternalServer::handle_request(const RequestContext& request) { try { @@ -562,7 +566,7 @@ std::unique_ptr InternalServer::handle_request(const RequestContext& r + urlNotFoundMsg; } - const ETag etag = get_matching_if_none_match_etag(request, m_server_id); + const ETag etag = get_matching_if_none_match_etag(request, getLibraryId()); if ( etag ) return Response::build_304(*this, etag); @@ -968,7 +972,7 @@ std::unique_ptr InternalServer::handle_catalog(const RequestContext& r zim::Uuid uuid; kiwix::OPDSDumper opdsDumper(mp_library); opdsDumper.setRootLocation(m_root); - opdsDumper.setLibraryId(m_library_id); + opdsDumper.setLibraryId(getLibraryId()); std::vector bookIdsToDump; if (url == "root.xml") { uuid = zim::Uuid::generate(host); diff --git a/src/server/internalServer.h b/src/server/internalServer.h index f6b7c3116..02360443a 100644 --- a/src/server/internalServer.h +++ b/src/server/internalServer.h @@ -152,6 +152,8 @@ class InternalServer { bool isLocallyCustomizedResource(const std::string& url) const; + std::string getLibraryId() const; + private: // types class LockableSuggestionSearcher; typedef ConcurrentCache> SearchCache; @@ -178,7 +180,6 @@ class InternalServer { SuggestionSearcherCache suggestionSearcherCache; std::string m_server_id; - std::string m_library_id; class CustomizedResources; std::unique_ptr m_customizedResources; diff --git a/src/server/internalServer_catalog_v2.cpp b/src/server/internalServer_catalog_v2.cpp index b082dd1c1..802d81cda 100644 --- a/src/server/internalServer_catalog_v2.cpp +++ b/src/server/internalServer_catalog_v2.cpp @@ -77,17 +77,18 @@ std::unique_ptr InternalServer::handle_catalog_v2(const RequestContext std::unique_ptr InternalServer::handle_catalog_v2_root(const RequestContext& request) { + const std::string libraryId = getLibraryId(); return ContentResponse::build( *this, RESOURCE::templates::catalog_v2_root_xml, kainjow::mustache::object{ {"date", gen_date_str()}, {"endpoint_root", m_root + "/catalog/v2"}, - {"feed_id", gen_uuid(m_library_id)}, - {"all_entries_feed_id", gen_uuid(m_library_id + "/entries")}, - {"partial_entries_feed_id", gen_uuid(m_library_id + "/partial_entries")}, - {"category_list_feed_id", gen_uuid(m_library_id + "/categories")}, - {"language_list_feed_id", gen_uuid(m_library_id + "/languages")} + {"feed_id", gen_uuid(libraryId)}, + {"all_entries_feed_id", gen_uuid(libraryId + "/entries")}, + {"partial_entries_feed_id", gen_uuid(libraryId + "/partial_entries")}, + {"category_list_feed_id", gen_uuid(libraryId + "/categories")}, + {"language_list_feed_id", gen_uuid(libraryId + "/languages")} }, "application/atom+xml;profile=opds-catalog;kind=navigation" ); @@ -97,7 +98,7 @@ std::unique_ptr InternalServer::handle_catalog_v2_entries(const Reques { OPDSDumper opdsDumper(mp_library); opdsDumper.setRootLocation(m_root); - opdsDumper.setLibraryId(m_library_id); + opdsDumper.setLibraryId(getLibraryId()); const auto bookIds = search_catalog(request, opdsDumper); const auto opdsFeed = opdsDumper.dumpOPDSFeedV2(bookIds, request.get_query(), partial); return ContentResponse::build( @@ -118,7 +119,7 @@ std::unique_ptr InternalServer::handle_catalog_v2_complete_entry(const OPDSDumper opdsDumper(mp_library); opdsDumper.setRootLocation(m_root); - opdsDumper.setLibraryId(m_library_id); + opdsDumper.setLibraryId(getLibraryId()); const auto opdsFeed = opdsDumper.dumpOPDSCompleteEntry(entryId); return ContentResponse::build( *this, @@ -131,7 +132,7 @@ std::unique_ptr InternalServer::handle_catalog_v2_categories(const Req { OPDSDumper opdsDumper(mp_library); opdsDumper.setRootLocation(m_root); - opdsDumper.setLibraryId(m_library_id); + opdsDumper.setLibraryId(getLibraryId()); return ContentResponse::build( *this, opdsDumper.categoriesOPDSFeed(), @@ -143,7 +144,7 @@ std::unique_ptr InternalServer::handle_catalog_v2_languages(const Requ { OPDSDumper opdsDumper(mp_library); opdsDumper.setRootLocation(m_root); - opdsDumper.setLibraryId(m_library_id); + opdsDumper.setLibraryId(getLibraryId()); return ContentResponse::build( *this, opdsDumper.languagesOPDSFeed(),