add sample web html
This commit is contained in:
parent
4311a7fb92
commit
e81c06be61
@ -9,6 +9,8 @@
|
||||
<file>text/COPYING_GNU_LGPL_21</file>
|
||||
<file>text/COPYING_QT</file>
|
||||
|
||||
<file>scripts/web_ui/rssguard.html</file>
|
||||
|
||||
<file>sounds/boing.wav</file>
|
||||
<file>sounds/rooster.wav</file>
|
||||
<file>sounds/sheep.wav</file>
|
||||
|
216
resources/scripts/web_ui/rssguard.html
Normal file
216
resources/scripts/web_ui/rssguard.html
Normal file
File diff suppressed because one or more lines are too long
@ -1202,7 +1202,7 @@ QList<Message> DatabaseQueries::getArticlesSlice(const QSqlDatabase& db,
|
||||
q.bindValue(QSL(":account_id"), account_id);
|
||||
q.bindValue(QSL(":row_limit"), row_limit);
|
||||
q.bindValue(QSL(":row_offset"), row_offset);
|
||||
q.bindValue(QSL(":feed"), QSL("feed"));
|
||||
q.bindValue(QSL(":feed"), feed_custom_id);
|
||||
|
||||
if (unread_only) {
|
||||
q.bindValue(QSL(":is_read"), 0);
|
||||
|
@ -356,6 +356,9 @@
|
||||
#define APP_SQL_PATH QSL(":/sql")
|
||||
#define APP_INFO_PATH QSL(":/text")
|
||||
|
||||
#define WEB_UI_FOLDER QSL(":/scripts/web_ui")
|
||||
#define WEB_UI_FILE QSL("rssguard.html")
|
||||
|
||||
#define APP_ICON_PATH QSL(":/graphics/rssguard.png")
|
||||
#define APP_ICON_PLAIN_PATH QSL(":/graphics/rssguard_plain.png")
|
||||
|
||||
|
@ -19,6 +19,9 @@ void ApiServer::answerClient(QTcpSocket* socket, const HttpRequest& request) {
|
||||
if (request.m_method == HttpRequest::Method::Options) {
|
||||
reply_message = processCorsPreflight();
|
||||
}
|
||||
else if (request.m_url.path().contains("rssguard")) {
|
||||
reply_message = processHtmlPage();
|
||||
}
|
||||
else {
|
||||
QJsonParseError json_err;
|
||||
QByteArray json_data;
|
||||
@ -74,6 +77,31 @@ QByteArray ApiServer::processCorsPreflight() const {
|
||||
return answer.toLocal8Bit();
|
||||
}
|
||||
|
||||
QByteArray ApiServer::processHtmlPage() const {
|
||||
QByteArray page;
|
||||
QString runtime_page_path = QCoreApplication::applicationDirPath() + QDir::separator() + WEB_UI_FILE;
|
||||
|
||||
if (QFile::exists(runtime_page_path)) {
|
||||
page = IOFactory::readFile(runtime_page_path);
|
||||
}
|
||||
else {
|
||||
page = IOFactory::readFile(WEB_UI_FOLDER + QL1C('/') + WEB_UI_FILE);
|
||||
}
|
||||
|
||||
QString answer = QSL("HTTP/1.0 200 OK\r\n"
|
||||
"Access-Control-Allow-Origin: *\r\n"
|
||||
"Access-Control-Allow-Headers: *\r\n"
|
||||
"Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE\r\n"
|
||||
"Content-Type: text/html; charset=\"utf-8\"\r\n"
|
||||
"Content-Length: %1\r\n"
|
||||
"\r\n")
|
||||
.arg(QString::number(page.size()));
|
||||
|
||||
QByteArray data = answer.toLocal8Bit();
|
||||
|
||||
return data + page;
|
||||
}
|
||||
|
||||
ApiResponse ApiServer::processRequest(const ApiRequest& req) const {
|
||||
switch (req.m_method) {
|
||||
case ApiRequest::Method::AppVersion:
|
||||
@ -102,6 +130,11 @@ ApiResponse ApiServer::processArticlesFromFeed(const QJsonValue& req) const {
|
||||
int row_offset = data.value(QSL("row_offset")).toInt();
|
||||
int row_limit = data.value(QSL("row_limit")).toInt();
|
||||
|
||||
// NOTE: Fixup arguments.
|
||||
if (feed_id == QSL("0")) {
|
||||
feed_id = QString();
|
||||
}
|
||||
|
||||
QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className());
|
||||
QList<Message> msgs =
|
||||
DatabaseQueries::getArticlesSlice(database, feed_id, account_id, newest_first, unread_only, row_offset, row_limit);
|
||||
|
@ -55,6 +55,8 @@ class ApiServer : public HttpServer {
|
||||
|
||||
private:
|
||||
QByteArray processCorsPreflight() const;
|
||||
QByteArray processHtmlPage() const;
|
||||
|
||||
ApiResponse processRequest(const ApiRequest& req) const;
|
||||
ApiResponse processAppVersion() const;
|
||||
ApiResponse processArticlesFromFeed(const QJsonValue& req) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user