Created method to generate remote library url

Refactored existing file static function makeHttpUrl to a member function that retrieves the remote library url from the request manager. Will be used for implementing the preview functionality.
This commit is contained in:
ShaopengLin 2024-05-18 14:30:56 -04:00
parent a394efcda8
commit 3b2019bb94
2 changed files with 10 additions and 16 deletions

View File

@ -642,6 +642,14 @@ const kiwix::Book& ContentManager::getRemoteOrLocalBook(const QString &id)
}
}
QString ContentManager::getRemoteLibraryUrl() const
{
auto host = m_remoteLibraryManager.getCatalogHost();
auto port = m_remoteLibraryManager.getCatalogPort();
return port == 443 ? "https://" + host
: "http://" + host + ":" + QString::number(port);
}
std::string ContentManager::startDownload(const kiwix::Book& book)
{
auto downloadPath = getSettingsManager()->getDownloadDir();
@ -887,27 +895,12 @@ void ContentManager::updateLibrary() {
} catch (std::runtime_error&) {}
}
namespace
{
QString makeHttpUrl(QString host, int port)
{
return port == 443
? "https://" + host
: "http://" + host + ":" + QString::number(port);
}
} // unnamed namespace
void ContentManager::updateRemoteLibrary(const QString& content) {
(void) QtConcurrent::run([=]() {
QMutexLocker locker(&remoteLibraryLocker);
mp_remoteLibrary = kiwix::Library::create();
kiwix::Manager manager(mp_remoteLibrary);
const auto catalogHost = m_remoteLibraryManager.getCatalogHost();
const auto catalogPort = m_remoteLibraryManager.getCatalogPort();
const auto catalogUrl = makeHttpUrl(catalogHost, catalogPort);
manager.readOpds(content.toStdString(), catalogUrl.toStdString());
manager.readOpds(content.toStdString(), getRemoteLibraryUrl().toStdString());
emit(this->booksChanged());
emit(this->pendingRequest(false));
});

View File

@ -121,6 +121,7 @@ private: // functions
// Get the book with the specified id from
// the remote or local library (in that order).
const kiwix::Book& getRemoteOrLocalBook(const QString &id);
QString getRemoteLibraryUrl() const;
void startDownloadUpdaterThread();
std::string startDownload(const kiwix::Book& book);