mirror of
https://github.com/YACReader/yacreader
synced 2025-05-27 19:00:29 -04:00
YACReaderLibrary Server: Add webui status page
This commit is contained in:
parent
a07ac4a956
commit
62ef567280
@ -15,6 +15,9 @@ Version counting is based on semantic versioning (Major.Feature.Patch)
|
||||
* UI gets updated when YACReaderLibrary gets updates from YACReader or YACReader for iOS.
|
||||
* Linux: Add fallback for dynamically loading libqrencode on distros that don't provide unversioned library symlinks
|
||||
|
||||
### Server
|
||||
* Add webui status page (reachable by navigating to server::port/webui)
|
||||
|
||||
## 9.9.2
|
||||
|
||||
### General
|
||||
|
@ -0,0 +1,84 @@
|
||||
#include "statuspagecontroller.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "yacreader_global.h"
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
#include "QsLog.h"
|
||||
|
||||
#include <QSysInfo>
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
using stefanfrings::HttpResponse;
|
||||
//using stefanfrings::HttpSession;
|
||||
using stefanfrings::Template;
|
||||
|
||||
StatusPageController::StatusPageController() {}
|
||||
|
||||
void StatusPageController::service(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
response.setHeader("Content-Type", "text/html; charset=utf-8");
|
||||
response.setHeader("Connection", "close");
|
||||
|
||||
Template StatusPage = Template(QStringLiteral(
|
||||
"<!DOCTYPE html>\n"
|
||||
"<html>\n"
|
||||
"<head>\n"
|
||||
"<title>YACReaderLibrary Server</title>\n"
|
||||
"</head>\n"
|
||||
"<body>\n\n"
|
||||
"<center>\n"
|
||||
"<img src='/images/webui/YACLibraryServer.svg' width=15%>\n"
|
||||
"<h1>YACReaderLibraryServer is up and running.</h1>\n"
|
||||
"<p>YACReader {yr.version}<p>\n"
|
||||
"<p>Server {server.version}<p>\n"
|
||||
"<p>OS:\t{os.name} {os.version}</p>\n"
|
||||
"<p>Port:\t{os.port}</p>\n"
|
||||
"<table>\n"
|
||||
"<thead>\n"
|
||||
"<tr>\n"
|
||||
"<th>Library</th>\n"
|
||||
"<th>Path</th>\n"
|
||||
"</tr>\n"
|
||||
"</thead>\n"
|
||||
"{loop Library}"
|
||||
"<tr>\n"
|
||||
"<td>{Library.Name}</td>\n"
|
||||
"<td>{Library.Path}</td>\n"
|
||||
"<tr>\n"
|
||||
"{end Library}"
|
||||
"</p>\n"
|
||||
"</center>\n"
|
||||
"</body>\n"
|
||||
"</html>\n"
|
||||
),
|
||||
|
||||
"StatusPage"
|
||||
);
|
||||
|
||||
StatusPage.enableWarnings();
|
||||
|
||||
// Set template variables
|
||||
StatusPage.setVariable("os.name", QSysInfo::prettyProductName());
|
||||
StatusPage.setVariable("os.version", QSysInfo::productVersion());
|
||||
// Getting the port from the request is basically a hack, but should do the trick
|
||||
StatusPage.setVariable("os.port", QString(request.getHeader("host")).split(":")[1]);
|
||||
|
||||
StatusPage.setVariable("server.version", SERVER_VERSION_NUMBER);
|
||||
StatusPage.setVariable("yr.version", VERSION);
|
||||
|
||||
// Get library info
|
||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||
QList<QString> library_names = libraries.getNames();
|
||||
size_t num_libs = libraries.getNames().size();
|
||||
|
||||
// Fill template
|
||||
StatusPage.loop("Library", num_libs);
|
||||
for (size_t i = 0; i < num_libs; i++)
|
||||
{
|
||||
StatusPage.setVariable(QString("Library%1.Name").arg(i), library_names.at(i));
|
||||
StatusPage.setVariable(QString("Library%1.Path").arg(i), libraries.getPath(library_names.at(i)));
|
||||
}
|
||||
|
||||
response.write(StatusPage.toUtf8(), true);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
#ifndef STATUSPAGE_CONTROLLER
|
||||
#define STATUSPAGE_CONTROLLER
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class StatusPageController : public stefanfrings::HttpRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(StatusPageController);
|
||||
|
||||
public:
|
||||
StatusPageController();
|
||||
|
||||
void service(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response) override;
|
||||
};
|
||||
|
||||
#endif // STATUSPAGE_CONTROLLER
|
@ -41,6 +41,8 @@
|
||||
#include "controllers/v2/comicfullinfocontroller_v2.h"
|
||||
#include "controllers/v2/comiccontrollerinreadinglist_v2.h"
|
||||
|
||||
#include "controllers/webui/statuspagecontroller.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
@ -157,13 +159,22 @@ void RequestMapper::service(HttpRequest &request, HttpResponse &response)
|
||||
QLOG_TRACE() << "RequestMapper: path=" << path.data();
|
||||
QLOG_TRACE() << "X-Request-Id: " << request.getHeader("x-request-id");
|
||||
|
||||
if (path.startsWith("/v2")) {
|
||||
// Browsers ask for text/html
|
||||
if (path.startsWith("/webui"))
|
||||
{
|
||||
serviceWebUI(request, response);
|
||||
} else if (path.startsWith("/v2")) {
|
||||
serviceV2(request, response);
|
||||
} else {
|
||||
serviceV1(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
void RequestMapper::serviceWebUI(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
StatusPageController().service(request, response);
|
||||
}
|
||||
|
||||
void RequestMapper::serviceV1(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
QByteArray path = request.getPath();
|
||||
|
@ -27,6 +27,7 @@ signals:
|
||||
private:
|
||||
void serviceV1(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response);
|
||||
void serviceV2(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response);
|
||||
void serviceWebUI(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response);
|
||||
|
||||
static QMutex mutex;
|
||||
};
|
||||
|
@ -47,7 +47,9 @@ HEADERS += \
|
||||
$$PWD/controllers/v2/comicfullinfocontroller_v2.h \
|
||||
$$PWD/controllers/v2/readinglistinfocontroller_v2.h \
|
||||
$$PWD/controllers/v2/taginfocontroller_v2.h \
|
||||
$$PWD/controllers/v2/comiccontrollerinreadinglist_v2.h
|
||||
$$PWD/controllers/v2/comiccontrollerinreadinglist_v2.h\
|
||||
#Browser
|
||||
$$PWD/controllers/webui/statuspagecontroller.h
|
||||
|
||||
|
||||
SOURCES += \
|
||||
@ -89,7 +91,9 @@ SOURCES += \
|
||||
$$PWD/controllers/v2/comicfullinfocontroller_v2.cpp \
|
||||
$$PWD/controllers/v2/readinglistinfocontroller_v2.cpp \
|
||||
$$PWD/controllers/v2/taginfocontroller_v2.cpp \
|
||||
$$PWD/controllers/v2/comiccontrollerinreadinglist_v2.cpp
|
||||
$$PWD/controllers/v2/comiccontrollerinreadinglist_v2.cpp \
|
||||
#WebUI
|
||||
$$PWD/controllers/webui/statuspagecontroller.cpp
|
||||
|
||||
include(../../third_party/QtWebApp/httpserver/httpserver.pri)
|
||||
include(../../third_party/QtWebApp/templateengine/templateengine.pri)
|
||||
|
Loading…
Reference in New Issue
Block a user