Fix urlschemehandle to adapt to new kiwix-lib.

New kiwix-lib forbid to create a "empty" `kiwix::Entry`.
This commit is contained in:
Matthieu Gautier 2020-12-07 12:17:48 +01:00
parent bd54ad9d79
commit f240ea78a1

View File

@ -30,35 +30,25 @@ UrlSchemeHandler::handleContentRequest(QWebEngineUrlRequestJob *request)
request->fail(QWebEngineUrlRequestJob::UrlNotFound); request->fail(QWebEngineUrlRequestJob::UrlNotFound);
return; return;
} }
kiwix::Entry entry;
try { try {
entry = reader->getEntryFromPath(url); kiwix::Entry entry = reader->getEntryFromPath(url);
} catch (kiwix::NoEntry&) { if (entry.isRedirect()) {
url = "A/" + url;
try {
entry = reader->getEntryFromPath(url);
} catch (kiwix::NoEntry&) {
request->fail(QWebEngineUrlRequestJob::UrlNotFound);
return;
}
}
if (entry.isRedirect()) {
try {
entry = entry.getFinalEntry(); entry = entry.getFinalEntry();
} catch (kiwix::NoEntry&) { auto path = QString("/") + QString::fromStdString(entry.getPath());
request->fail(QWebEngineUrlRequestJob::UrlNotFound); qurl.setPath(path);
request->redirect(qurl);
return; return;
} }
auto path = QString("/") + QString::fromStdString(entry.getPath());
qurl.setPath(path); BlobBuffer* buffer = new BlobBuffer(entry.getBlob());
request->redirect(qurl); auto mimeType = QByteArray::fromStdString(entry.getMimetype());
return; mimeType = mimeType.split(';')[0];
connect(request, &QObject::destroyed, buffer, &QObject::deleteLater);
request->reply(mimeType, buffer);
} catch (kiwix::NoEntry&) {
request->fail(QWebEngineUrlRequestJob::UrlNotFound);
} }
BlobBuffer* buffer = new BlobBuffer(entry.getBlob());
auto mimeType = QByteArray::fromStdString(entry.getMimetype());
mimeType = mimeType.split(';')[0];
connect(request, &QObject::destroyed, buffer, &QObject::deleteLater);
request->reply(mimeType, buffer);
} }
void void