mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-23 12:07:00 -04:00
Use last kiwix-lib API.
This commit is contained in:
parent
7c8d475d24
commit
1231e2fcdb
@ -17,26 +17,37 @@ KiwixSchemeHandler::requestStarted(QWebEngineUrlRequestJob *request)
|
|||||||
{
|
{
|
||||||
std::cout << "Handling request " << request->requestUrl().toString().toUtf8().constData() << std::endl;
|
std::cout << "Handling request " << request->requestUrl().toString().toUtf8().constData() << std::endl;
|
||||||
std::string url = request->requestUrl().path().toUtf8().constData();
|
std::string url = request->requestUrl().path().toUtf8().constData();
|
||||||
zim::Article art;
|
|
||||||
std::cout << "Url is " << url << std::endl;
|
std::cout << "Url is " << url << std::endl;
|
||||||
|
if (url[0] == '/')
|
||||||
|
url = url.substr(1);
|
||||||
auto reader = static_cast<KiwixApp*>(KiwixApp::instance())->getReader();
|
auto reader = static_cast<KiwixApp*>(KiwixApp::instance())->getReader();
|
||||||
if ( reader == nullptr) {
|
if ( reader == nullptr) {
|
||||||
request->fail(QWebEngineUrlRequestJob::UrlNotFound);
|
request->fail(QWebEngineUrlRequestJob::UrlNotFound);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( !reader->getArticleObjectByDecodedUrl(url, art))
|
kiwix::Entry entry;
|
||||||
{
|
try {
|
||||||
|
entry = reader->getEntryFromPath(url);
|
||||||
|
} catch (kiwix::NoEntry& e) {
|
||||||
url = "A/" + url;
|
url = "A/" + url;
|
||||||
if (!reader->getArticleObjectByDecodedUrl(url, art))
|
std::cout << "Url is " << url << std::endl;
|
||||||
{
|
try {
|
||||||
|
entry = reader->getEntryFromPath(url);
|
||||||
|
} catch (kiwix::NoEntry& e) {
|
||||||
request->fail(QWebEngineUrlRequestJob::UrlNotFound);
|
request->fail(QWebEngineUrlRequestJob::UrlNotFound);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
entry = entry.getFinalEntry();
|
||||||
|
} catch (kiwix::NoEntry& e) {
|
||||||
|
request->fail(QWebEngineUrlRequestJob::UrlNotFound);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
BlobBuffer* buffer = new BlobBuffer(art.getData());
|
BlobBuffer* buffer = new BlobBuffer(entry.getBlob());
|
||||||
std::cout << " mimetype : " << art.getMimeType() << std::endl;
|
std::cout << " mimetype : " << entry.getMimetype() << std::endl;
|
||||||
auto mimeType = QByteArray::fromRawData(art.getMimeType().data(), art.getMimeType().size());
|
auto mimeType = QByteArray::fromRawData(entry.getMimetype().data(), entry.getMimetype().size());
|
||||||
connect(buffer, &QIODevice::aboutToClose, buffer, &QObject::deleteLater);
|
connect(buffer, &QIODevice::aboutToClose, buffer, &QObject::deleteLater);
|
||||||
request->reply(mimeType, buffer);
|
request->reply(mimeType, buffer);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user