diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-08-08 13:08:44 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-08-08 13:08:44 +0530 |
| commit | 8ec50e55a45af1706d40eff292db4541b6fcc261 (patch) | |
| tree | 6b4cb54d638765cc0c3178984a6ec18af4a3a7e4 /src/schemes/NullSchemeHandler.cpp | |
| parent | b955a603c27ffb3869901b1899303b936816afcf (diff) | |
| download | null-browser-8ec50e55a45af1706d40eff292db4541b6fcc261.tar.gz null-browser-8ec50e55a45af1706d40eff292db4541b6fcc261.zip | |
Embed docs as null://docs + web.help api
Diffstat (limited to '')
| -rw-r--r-- | src/schemes/NullSchemeHandler.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/schemes/NullSchemeHandler.cpp b/src/schemes/NullSchemeHandler.cpp new file mode 100644 index 0000000..203e673 --- /dev/null +++ b/src/schemes/NullSchemeHandler.cpp @@ -0,0 +1,46 @@ +#include "NullSchemeHandler.hpp" +#include <qstringview.h> +#include <qwebengineurlrequestjob.h> + +void NullSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job) { + auto url = job->requestUrl(); + + if (url.host() == "docs") { + QBuffer *buffer = new QBuffer(job); + buffer->setData(read_static_docs_file(url.path())); + buffer->open(QIODevice::ReadOnly); + job->reply(get_content_type(url.path()), buffer); + } else { + job->reply("text/html", new QBuffer(job)); + } +} + +QByteArray NullSchemeHandler::read_static_docs_file(const QString &path) { + QFile file(NULL_DOCS_DIR + path); + if (!file.exists()) + return read_index_html(); + + if (file.open(QIODevice::ReadOnly)) { + auto contents = file.readAll(); + file.close(); + return contents; + } + return QByteArray{}; +} + +QByteArray NullSchemeHandler::read_index_html() { + QFile file(NULL_DOCS_DIR + QString("/index.html")); + qDebug() << ":::" << file.exists(); + if (file.open(QIODevice::ReadOnly)) { + auto contents = file.readAll(); + file.close(); + return contents; + } + return QByteArray{}; +} + +QByteArray NullSchemeHandler::get_content_type(const QString &path) { + if (path.endsWith(".css")) + return "text/css"; + return "text/html"; +} |
