mirror of https://github.com/kiwix/libkiwix.git
InternalServer::getLibraryId()
This commit is contained in:
parent
c91df1cb26
commit
6b8d6232f0
|
@ -461,7 +461,6 @@ bool InternalServer::start() {
|
||||||
}
|
}
|
||||||
auto server_start_time = std::chrono::system_clock::now().time_since_epoch();
|
auto server_start_time = std::chrono::system_clock::now().time_since_epoch();
|
||||||
m_server_id = kiwix::to_string(server_start_time.count());
|
m_server_id = kiwix::to_string(server_start_time.count());
|
||||||
m_library_id = m_server_id;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,7 +531,7 @@ MHD_Result InternalServer::handlerCallback(struct MHD_Connection* connection,
|
||||||
if (response->getReturnCode() == MHD_HTTP_OK
|
if (response->getReturnCode() == MHD_HTTP_OK
|
||||||
&& response->get_kind() == Response::DYNAMIC_CONTENT
|
&& response->get_kind() == Response::DYNAMIC_CONTENT
|
||||||
&& !etag_not_needed(request))
|
&& !etag_not_needed(request))
|
||||||
response->set_etag_body(m_server_id);
|
response->set_etag_body(getLibraryId());
|
||||||
|
|
||||||
auto ret = response->send(request, connection);
|
auto ret = response->send(request, connection);
|
||||||
auto end_time = std::chrono::steady_clock::now();
|
auto end_time = std::chrono::steady_clock::now();
|
||||||
|
@ -554,6 +553,11 @@ bool isEndpointUrl(const std::string& url, const std::string& endpoint)
|
||||||
|
|
||||||
} // unnamed namespace
|
} // unnamed namespace
|
||||||
|
|
||||||
|
std::string InternalServer::getLibraryId() const
|
||||||
|
{
|
||||||
|
return m_server_id + "." + kiwix::to_string(mp_library->getRevision());
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<Response> InternalServer::handle_request(const RequestContext& request)
|
std::unique_ptr<Response> InternalServer::handle_request(const RequestContext& request)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
@ -562,7 +566,7 @@ std::unique_ptr<Response> InternalServer::handle_request(const RequestContext& r
|
||||||
+ urlNotFoundMsg;
|
+ 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 )
|
if ( etag )
|
||||||
return Response::build_304(*this, etag);
|
return Response::build_304(*this, etag);
|
||||||
|
|
||||||
|
@ -968,7 +972,7 @@ std::unique_ptr<Response> InternalServer::handle_catalog(const RequestContext& r
|
||||||
zim::Uuid uuid;
|
zim::Uuid uuid;
|
||||||
kiwix::OPDSDumper opdsDumper(mp_library);
|
kiwix::OPDSDumper opdsDumper(mp_library);
|
||||||
opdsDumper.setRootLocation(m_root);
|
opdsDumper.setRootLocation(m_root);
|
||||||
opdsDumper.setLibraryId(m_library_id);
|
opdsDumper.setLibraryId(getLibraryId());
|
||||||
std::vector<std::string> bookIdsToDump;
|
std::vector<std::string> bookIdsToDump;
|
||||||
if (url == "root.xml") {
|
if (url == "root.xml") {
|
||||||
uuid = zim::Uuid::generate(host);
|
uuid = zim::Uuid::generate(host);
|
||||||
|
|
|
@ -152,6 +152,8 @@ class InternalServer {
|
||||||
|
|
||||||
bool isLocallyCustomizedResource(const std::string& url) const;
|
bool isLocallyCustomizedResource(const std::string& url) const;
|
||||||
|
|
||||||
|
std::string getLibraryId() const;
|
||||||
|
|
||||||
private: // types
|
private: // types
|
||||||
class LockableSuggestionSearcher;
|
class LockableSuggestionSearcher;
|
||||||
typedef ConcurrentCache<SearchInfo, std::shared_ptr<zim::Search>> SearchCache;
|
typedef ConcurrentCache<SearchInfo, std::shared_ptr<zim::Search>> SearchCache;
|
||||||
|
@ -178,7 +180,6 @@ class InternalServer {
|
||||||
SuggestionSearcherCache suggestionSearcherCache;
|
SuggestionSearcherCache suggestionSearcherCache;
|
||||||
|
|
||||||
std::string m_server_id;
|
std::string m_server_id;
|
||||||
std::string m_library_id;
|
|
||||||
|
|
||||||
class CustomizedResources;
|
class CustomizedResources;
|
||||||
std::unique_ptr<CustomizedResources> m_customizedResources;
|
std::unique_ptr<CustomizedResources> m_customizedResources;
|
||||||
|
|
|
@ -77,17 +77,18 @@ std::unique_ptr<Response> InternalServer::handle_catalog_v2(const RequestContext
|
||||||
|
|
||||||
std::unique_ptr<Response> InternalServer::handle_catalog_v2_root(const RequestContext& request)
|
std::unique_ptr<Response> InternalServer::handle_catalog_v2_root(const RequestContext& request)
|
||||||
{
|
{
|
||||||
|
const std::string libraryId = getLibraryId();
|
||||||
return ContentResponse::build(
|
return ContentResponse::build(
|
||||||
*this,
|
*this,
|
||||||
RESOURCE::templates::catalog_v2_root_xml,
|
RESOURCE::templates::catalog_v2_root_xml,
|
||||||
kainjow::mustache::object{
|
kainjow::mustache::object{
|
||||||
{"date", gen_date_str()},
|
{"date", gen_date_str()},
|
||||||
{"endpoint_root", m_root + "/catalog/v2"},
|
{"endpoint_root", m_root + "/catalog/v2"},
|
||||||
{"feed_id", gen_uuid(m_library_id)},
|
{"feed_id", gen_uuid(libraryId)},
|
||||||
{"all_entries_feed_id", gen_uuid(m_library_id + "/entries")},
|
{"all_entries_feed_id", gen_uuid(libraryId + "/entries")},
|
||||||
{"partial_entries_feed_id", gen_uuid(m_library_id + "/partial_entries")},
|
{"partial_entries_feed_id", gen_uuid(libraryId + "/partial_entries")},
|
||||||
{"category_list_feed_id", gen_uuid(m_library_id + "/categories")},
|
{"category_list_feed_id", gen_uuid(libraryId + "/categories")},
|
||||||
{"language_list_feed_id", gen_uuid(m_library_id + "/languages")}
|
{"language_list_feed_id", gen_uuid(libraryId + "/languages")}
|
||||||
},
|
},
|
||||||
"application/atom+xml;profile=opds-catalog;kind=navigation"
|
"application/atom+xml;profile=opds-catalog;kind=navigation"
|
||||||
);
|
);
|
||||||
|
@ -97,7 +98,7 @@ std::unique_ptr<Response> InternalServer::handle_catalog_v2_entries(const Reques
|
||||||
{
|
{
|
||||||
OPDSDumper opdsDumper(mp_library);
|
OPDSDumper opdsDumper(mp_library);
|
||||||
opdsDumper.setRootLocation(m_root);
|
opdsDumper.setRootLocation(m_root);
|
||||||
opdsDumper.setLibraryId(m_library_id);
|
opdsDumper.setLibraryId(getLibraryId());
|
||||||
const auto bookIds = search_catalog(request, opdsDumper);
|
const auto bookIds = search_catalog(request, opdsDumper);
|
||||||
const auto opdsFeed = opdsDumper.dumpOPDSFeedV2(bookIds, request.get_query(), partial);
|
const auto opdsFeed = opdsDumper.dumpOPDSFeedV2(bookIds, request.get_query(), partial);
|
||||||
return ContentResponse::build(
|
return ContentResponse::build(
|
||||||
|
@ -118,7 +119,7 @@ std::unique_ptr<Response> InternalServer::handle_catalog_v2_complete_entry(const
|
||||||
|
|
||||||
OPDSDumper opdsDumper(mp_library);
|
OPDSDumper opdsDumper(mp_library);
|
||||||
opdsDumper.setRootLocation(m_root);
|
opdsDumper.setRootLocation(m_root);
|
||||||
opdsDumper.setLibraryId(m_library_id);
|
opdsDumper.setLibraryId(getLibraryId());
|
||||||
const auto opdsFeed = opdsDumper.dumpOPDSCompleteEntry(entryId);
|
const auto opdsFeed = opdsDumper.dumpOPDSCompleteEntry(entryId);
|
||||||
return ContentResponse::build(
|
return ContentResponse::build(
|
||||||
*this,
|
*this,
|
||||||
|
@ -131,7 +132,7 @@ std::unique_ptr<Response> InternalServer::handle_catalog_v2_categories(const Req
|
||||||
{
|
{
|
||||||
OPDSDumper opdsDumper(mp_library);
|
OPDSDumper opdsDumper(mp_library);
|
||||||
opdsDumper.setRootLocation(m_root);
|
opdsDumper.setRootLocation(m_root);
|
||||||
opdsDumper.setLibraryId(m_library_id);
|
opdsDumper.setLibraryId(getLibraryId());
|
||||||
return ContentResponse::build(
|
return ContentResponse::build(
|
||||||
*this,
|
*this,
|
||||||
opdsDumper.categoriesOPDSFeed(),
|
opdsDumper.categoriesOPDSFeed(),
|
||||||
|
@ -143,7 +144,7 @@ std::unique_ptr<Response> InternalServer::handle_catalog_v2_languages(const Requ
|
||||||
{
|
{
|
||||||
OPDSDumper opdsDumper(mp_library);
|
OPDSDumper opdsDumper(mp_library);
|
||||||
opdsDumper.setRootLocation(m_root);
|
opdsDumper.setRootLocation(m_root);
|
||||||
opdsDumper.setLibraryId(m_library_id);
|
opdsDumper.setLibraryId(getLibraryId());
|
||||||
return ContentResponse::build(
|
return ContentResponse::build(
|
||||||
*this,
|
*this,
|
||||||
opdsDumper.languagesOPDSFeed(),
|
opdsDumper.languagesOPDSFeed(),
|
||||||
|
|
Loading…
Reference in New Issue