User-controllable catalog host & port

So far the details of the host serving the OPDS catalog were hardcoded.
In order to debug issues related to large downloads it helps if one
can use one's own server. Hence this enhancement.
This commit is contained in:
Veloman Yunkan 2023-12-10 16:21:44 +04:00
parent 9924570670
commit c10026a3a2
3 changed files with 26 additions and 7 deletions

View File

@ -681,13 +681,13 @@ void ContentManager::updateLibrary() {
} catch (std::runtime_error&) {}
}
#define CATALOG_URL "library.kiwix.org"
void ContentManager::updateRemoteLibrary(const QString& content) {
QtConcurrent::run([=]() {
QMutexLocker locker(&remoteLibraryLocker);
mp_remoteLibrary = kiwix::Library::create();
kiwix::Manager manager(mp_remoteLibrary);
manager.readOpds(content.toStdString(), CATALOG_URL);
const auto catalogUrl = m_remoteLibraryManager.getCatalogHost();
manager.readOpds(content.toStdString(), catalogUrl.toStdString());
emit(this->booksChanged());
emit(this->pendingRequest(false));
});

View File

@ -5,8 +5,22 @@ OpdsRequestManager::OpdsRequestManager()
{
}
#define CATALOG_HOST "library.kiwix.org"
#define CATALOG_PORT 443
QString OpdsRequestManager::getCatalogHost()
{
const char* const envVarVal = getenv("KIWIX_CATALOG_HOST");
return envVarVal
? envVarVal
: "library.kiwix.org";
}
int OpdsRequestManager::getCatalogPort()
{
const char* const envVarVal = getenv("KIWIX_CATALOG_PORT");
return envVarVal
? atoi(envVarVal)
: 443;
}
void OpdsRequestManager::doUpdate(const QString& currentLanguage, const QString& categoryFilter)
{
QUrlQuery query;
@ -36,9 +50,10 @@ void OpdsRequestManager::doUpdate(const QString& currentLanguage, const QString&
QNetworkReply* OpdsRequestManager::opdsResponseFromPath(const QString &path, const QUrlQuery &query)
{
QUrl url;
url.setScheme("https");
url.setHost(CATALOG_HOST);
url.setPort(CATALOG_PORT);
const int port = getCatalogPort();
url.setScheme(port == 443 ? "https" : "http");
url.setHost(getCatalogHost());
url.setPort(port);
url.setPath(path);
url.setQuery(query);
qInfo() << "Downloading" << url.toString(QUrl::FullyEncoded);

View File

@ -32,6 +32,10 @@ public slots:
void receiveContent(QNetworkReply*);
void receiveLanguages(QNetworkReply*);
void receiveCategories(QNetworkReply*);
public:
static QString getCatalogHost();
static int getCatalogPort();
};
#endif // OPDSREQUESTMANAGER_H