mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-24 04:20:56 -04:00
Added a random article button for server mode
This commit is contained in:
parent
5ef0a6e852
commit
f26f60e3d7
@ -158,13 +158,14 @@ static int accessHandlerCallback(void *cls,
|
|||||||
std::string httpRedirection;
|
std::string httpRedirection;
|
||||||
unsigned int contentLength = 0;
|
unsigned int contentLength = 0;
|
||||||
bool found = true;
|
bool found = true;
|
||||||
|
bool cacheEnabled = true;
|
||||||
int httpResponseCode = MHD_HTTP_OK;
|
int httpResponseCode = MHD_HTTP_OK;
|
||||||
std::string urlStr = string(url);
|
std::string urlStr = string(url);
|
||||||
|
|
||||||
/* Get searcher and reader */
|
/* Get searcher and reader */
|
||||||
std::string humanReadableBookId = "";
|
std::string humanReadableBookId = "";
|
||||||
if (!(urlStr.size() > 5 && urlStr.substr(0, 6) == "/skin/")) {
|
if (!(urlStr.size() > 5 && urlStr.substr(0, 6) == "/skin/")) {
|
||||||
if (!strcmp(url, "/search") || !strcmp(url, "/suggest")) {
|
if (!strcmp(url, "/search") || !strcmp(url, "/suggest") || !strcmp(url, "/random")) {
|
||||||
const char* tmpGetValue = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "content");
|
const char* tmpGetValue = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "content");
|
||||||
humanReadableBookId = (tmpGetValue != NULL ? string(tmpGetValue) : "");
|
humanReadableBookId = (tmpGetValue != NULL ? string(tmpGetValue) : "");
|
||||||
} else {
|
} else {
|
||||||
@ -270,6 +271,18 @@ static int accessHandlerCallback(void *cls,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Display a random article */
|
||||||
|
else if (!strcmp(url, "/random")) {
|
||||||
|
cacheEnabled = false;
|
||||||
|
std::string randomUrl;
|
||||||
|
if (reader != NULL) {
|
||||||
|
pthread_mutex_lock(&readerLock);
|
||||||
|
randomUrl = reader->getRandomPageUrl();
|
||||||
|
pthread_mutex_unlock(&readerLock);
|
||||||
|
httpRedirection="/" + humanReadableBookId + "/" + randomUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Display the content of a ZIM article */
|
/* Display the content of a ZIM article */
|
||||||
else if (reader != NULL) {
|
else if (reader != NULL) {
|
||||||
pthread_mutex_lock(&readerLock);
|
pthread_mutex_lock(&readerLock);
|
||||||
@ -387,8 +400,16 @@ static int accessHandlerCallback(void *cls,
|
|||||||
/* Force to close the connection - cf. 100% CPU usage with v. 4.4 (in Lucid) */
|
/* Force to close the connection - cf. 100% CPU usage with v. 4.4 (in Lucid) */
|
||||||
MHD_add_response_header(response, MHD_HTTP_HEADER_CONNECTION, "close");
|
MHD_add_response_header(response, MHD_HTTP_HEADER_CONNECTION, "close");
|
||||||
|
|
||||||
/* Force cache */
|
if(cacheEnabled)
|
||||||
MHD_add_response_header(response, MHD_HTTP_HEADER_CACHE_CONTROL, "max-age=87840, must-revalidate");
|
{
|
||||||
|
/* Force cache */
|
||||||
|
MHD_add_response_header(response, MHD_HTTP_HEADER_CACHE_CONTROL, "max-age=87840, must-revalidate");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Prevent cache (for random page) */
|
||||||
|
MHD_add_response_header(response, MHD_HTTP_HEADER_CACHE_CONTROL, "no-cache, no-store, must-revalidate");
|
||||||
|
}
|
||||||
|
|
||||||
/* Queue the response */
|
/* Queue the response */
|
||||||
int ret = MHD_queue_response(connection,
|
int ret = MHD_queue_response(connection,
|
||||||
|
@ -19,6 +19,11 @@
|
|||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#kiwixrandom {
|
||||||
|
margin: 0px;
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
|
||||||
#kiwixsearchbox {
|
#kiwixsearchbox {
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
float: right;
|
float: right;
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
<span id="kiwixtoolbar" class="ui-widget-header ui-corner-all">
|
<span id="kiwixtoolbar" class="ui-widget-header ui-corner-all">
|
||||||
<form action="/" method="GET"><input type="submit" value="Library" id="kiwixlibrary" /></form>
|
<form action="/" method="GET"><input type="submit" value="Library" id="kiwixlibrary" /></form>
|
||||||
<form action="/__CONTENT__/" method="GET"><input type="submit" value="Home" id="kiwixhome" /></form>
|
<form action="/__CONTENT__/" method="GET"><input type="submit" value="Home" id="kiwixhome" /></form>
|
||||||
|
<form action="/random" method="GET"><input type="submit" value="Random" id="kiwixrandom" /><input type="hidden" name="content" value="__CONTENT__" /></form>
|
||||||
<form method="GET" action="/search" id="kiwixsearchform"><input type="hidden" name="content" value="__CONTENT__" /><input type="submit" id="kiwixsearch" value="Search" /><input type="text" id="kiwixsearchbox" name="pattern" /></form>
|
<form method="GET" action="/search" id="kiwixsearchform"><input type="hidden" name="content" value="__CONTENT__" /><input type="submit" id="kiwixsearch" value="Search" /><input type="text" id="kiwixsearchbox" name="pattern" /></form>
|
||||||
</span>
|
</span>
|
||||||
<div style="display: block; height: 45px;"></div>
|
<div style="display: block; height: 45px;"></div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user