Fixed fetching of favicons from debug server

When using a debug server (enabled by the environment variables
KIWIX_CATALOG_HOST and KIWIX_CATALOG_PORT) the URLs of the favicons
must be composed correspondingly.
This commit is contained in:
Veloman Yunkan 2024-02-06 18:45:14 +04:00
parent 4914bb86eb
commit 535675afdb
2 changed files with 17 additions and 3 deletions

View File

@ -679,12 +679,26 @@ void ContentManager::updateLibrary() {
} catch (std::runtime_error&) {} } 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 ContentManager::updateRemoteLibrary(const QString& content) {
QtConcurrent::run([=]() { QtConcurrent::run([=]() {
QMutexLocker locker(&remoteLibraryLocker); QMutexLocker locker(&remoteLibraryLocker);
mp_remoteLibrary = kiwix::Library::create(); mp_remoteLibrary = kiwix::Library::create();
kiwix::Manager manager(mp_remoteLibrary); kiwix::Manager manager(mp_remoteLibrary);
const auto catalogUrl = m_remoteLibraryManager.getCatalogHost(); 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(), catalogUrl.toStdString());
emit(this->booksChanged()); emit(this->booksChanged());
emit(this->pendingRequest(false)); emit(this->pendingRequest(false));

View File

@ -112,7 +112,7 @@ void ContentManagerModel::setBooksData(const BookInfoList& data)
std::shared_ptr<RowNode> ContentManagerModel::createNode(BookInfo bookItem, QMap<QString, QByteArray> iconMap) const std::shared_ptr<RowNode> ContentManagerModel::createNode(BookInfo bookItem, QMap<QString, QByteArray> iconMap) const
{ {
auto faviconUrl = "https://" + bookItem["faviconUrl"].toString(); const auto faviconUrl = bookItem["faviconUrl"].toString();
QString id = bookItem["id"].toString(); QString id = bookItem["id"].toString();
QByteArray bookIcon; QByteArray bookIcon;
try { try {
@ -168,7 +168,7 @@ void ContentManagerModel::refreshIcons()
for (auto i = 0; i < rowCount() && i < m_data.size(); i++) { for (auto i = 0; i < rowCount() && i < m_data.size(); i++) {
auto bookItem = m_data[i]; auto bookItem = m_data[i];
auto id = bookItem["id"].toString(); auto id = bookItem["id"].toString();
auto faviconUrl = "https://" + bookItem["faviconUrl"].toString(); const auto faviconUrl = bookItem["faviconUrl"].toString();
auto app = KiwixApp::instance(); auto app = KiwixApp::instance();
try { try {
auto book = app->getLibrary()->getBookById(id); auto book = app->getLibrary()->getBookById(id);