mirror of
https://github.com/JulianGro/overte.git
synced 2025-06-04 05:21:33 +02:00
Merge pull request #6426 from ZappoMan/entitiesFileDownload
implement support to download the persist file from entity server status page
This commit is contained in:
commit
98073de0b8
7 changed files with 59 additions and 1 deletions
|
@ -317,6 +317,7 @@ bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool showStats = false;
|
bool showStats = false;
|
||||||
|
QString persistFile = "/" + getPersistFilename();
|
||||||
|
|
||||||
if (connection->requestOperation() == QNetworkAccessManager::GetOperation) {
|
if (connection->requestOperation() == QNetworkAccessManager::GetOperation) {
|
||||||
if (url.path() == "/") {
|
if (url.path() == "/") {
|
||||||
|
@ -326,6 +327,18 @@ bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
_tree->resetEditStats();
|
_tree->resetEditStats();
|
||||||
resetSendingStats();
|
resetSendingStats();
|
||||||
showStats = true;
|
showStats = true;
|
||||||
|
} else if ((url.path() == persistFile) || (url.path() == persistFile + "/")) {
|
||||||
|
if (_persistFileDownload) {
|
||||||
|
QByteArray persistFileContents = getPersistFileContents();
|
||||||
|
if (persistFileContents.length() > 0) {
|
||||||
|
connection->respond(HTTPConnection::StatusCode200, persistFileContents, qPrintable(getPersistFileMimeType()));
|
||||||
|
} else {
|
||||||
|
connection->respond(HTTPConnection::StatusCode500, HTTPConnection::StatusCode500);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
connection->respond(HTTPConnection::StatusCode403, HTTPConnection::StatusCode403); // not allowed
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,6 +380,12 @@ bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
statsString += getFileLoadTime();
|
statsString += getFileLoadTime();
|
||||||
statsString += "\r\n";
|
statsString += "\r\n";
|
||||||
|
|
||||||
|
if (_persistFileDownload) {
|
||||||
|
statsString += QString("Persist file: <a href='%1'>%1</a>\r\n").arg(persistFile);
|
||||||
|
} else {
|
||||||
|
statsString += QString("Persist file: %1\r\n").arg(persistFile);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
statsString += "Octree file not yet loaded...\r\n";
|
statsString += "Octree file not yet loaded...\r\n";
|
||||||
}
|
}
|
||||||
|
@ -1026,7 +1045,8 @@ bool OctreeServer::readConfiguration() {
|
||||||
_wantBackup = !noBackup;
|
_wantBackup = !noBackup;
|
||||||
qDebug() << "wantBackup=" << _wantBackup;
|
qDebug() << "wantBackup=" << _wantBackup;
|
||||||
|
|
||||||
//qDebug() << "settingsSectionObject:" << settingsSectionObject;
|
readOptionBool(QString("persistFileDownload"), settingsSectionObject, _persistFileDownload);
|
||||||
|
qDebug() << "persistFileDownload=" << _persistFileDownload;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qDebug("persistFilename= DISABLED");
|
qDebug("persistFilename= DISABLED");
|
||||||
|
|
|
@ -59,6 +59,9 @@ public:
|
||||||
bool isInitialLoadComplete() const { return (_persistThread) ? _persistThread->isInitialLoadComplete() : true; }
|
bool isInitialLoadComplete() const { return (_persistThread) ? _persistThread->isInitialLoadComplete() : true; }
|
||||||
bool isPersistEnabled() const { return (_persistThread) ? true : false; }
|
bool isPersistEnabled() const { return (_persistThread) ? true : false; }
|
||||||
quint64 getLoadElapsedTime() const { return (_persistThread) ? _persistThread->getLoadElapsedTime() : 0; }
|
quint64 getLoadElapsedTime() const { return (_persistThread) ? _persistThread->getLoadElapsedTime() : 0; }
|
||||||
|
QString getPersistFilename() const { return (_persistThread) ? _persistThread->getPersistFilename() : ""; }
|
||||||
|
QString getPersistFileMimeType() const { return (_persistThread) ? _persistThread->getPersistFileMimeType() : "text/plain"; }
|
||||||
|
QByteArray getPersistFileContents() const { return (_persistThread) ? _persistThread->getPersistFileContents() : QByteArray(); }
|
||||||
|
|
||||||
// Subclasses must implement these methods
|
// Subclasses must implement these methods
|
||||||
virtual OctreeQueryNode* createOctreeQueryNode() = 0;
|
virtual OctreeQueryNode* createOctreeQueryNode() = 0;
|
||||||
|
@ -173,6 +176,7 @@ protected:
|
||||||
|
|
||||||
int _persistInterval;
|
int _persistInterval;
|
||||||
bool _wantBackup;
|
bool _wantBackup;
|
||||||
|
bool _persistFileDownload;
|
||||||
QString _backupExtensionFormat;
|
QString _backupExtensionFormat;
|
||||||
int _backupInterval;
|
int _backupInterval;
|
||||||
int _maxBackupVersions;
|
int _maxBackupVersions;
|
||||||
|
|
|
@ -476,6 +476,14 @@
|
||||||
"default": "",
|
"default": "",
|
||||||
"advanced": true
|
"advanced": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "persistFileDownload",
|
||||||
|
"type": "checkbox",
|
||||||
|
"label": "Persist File Download",
|
||||||
|
"help": "Includes a download link to the persist file in the server status page.",
|
||||||
|
"default": false,
|
||||||
|
"advanced": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "wantEditLogging",
|
"name": "wantEditLogging",
|
||||||
"type": "checkbox",
|
"type": "checkbox",
|
||||||
|
|
|
@ -23,7 +23,9 @@ const char* HTTPConnection::StatusCode301 = "301 Moved Permanently";
|
||||||
const char* HTTPConnection::StatusCode302 = "302 Found";
|
const char* HTTPConnection::StatusCode302 = "302 Found";
|
||||||
const char* HTTPConnection::StatusCode400 = "400 Bad Request";
|
const char* HTTPConnection::StatusCode400 = "400 Bad Request";
|
||||||
const char* HTTPConnection::StatusCode401 = "401 Unauthorized";
|
const char* HTTPConnection::StatusCode401 = "401 Unauthorized";
|
||||||
|
const char* HTTPConnection::StatusCode403 = "403 Forbidden";
|
||||||
const char* HTTPConnection::StatusCode404 = "404 Not Found";
|
const char* HTTPConnection::StatusCode404 = "404 Not Found";
|
||||||
|
const char* HTTPConnection::StatusCode500 = "500 Internal server error";
|
||||||
const char* HTTPConnection::DefaultContentType = "text/plain; charset=ISO-8859-1";
|
const char* HTTPConnection::DefaultContentType = "text/plain; charset=ISO-8859-1";
|
||||||
|
|
||||||
HTTPConnection::HTTPConnection (QTcpSocket* socket, HTTPManager* parentManager) :
|
HTTPConnection::HTTPConnection (QTcpSocket* socket, HTTPManager* parentManager) :
|
||||||
|
|
|
@ -47,7 +47,9 @@ public:
|
||||||
static const char* StatusCode302;
|
static const char* StatusCode302;
|
||||||
static const char* StatusCode400;
|
static const char* StatusCode400;
|
||||||
static const char* StatusCode401;
|
static const char* StatusCode401;
|
||||||
|
static const char* StatusCode403;
|
||||||
static const char* StatusCode404;
|
static const char* StatusCode404;
|
||||||
|
static const char* StatusCode500;
|
||||||
static const char* DefaultContentType;
|
static const char* DefaultContentType;
|
||||||
|
|
||||||
/// WebSocket close status codes.
|
/// WebSocket close status codes.
|
||||||
|
|
|
@ -52,6 +52,15 @@ OctreePersistThread::OctreePersistThread(OctreePointer tree, const QString& file
|
||||||
_filename = sansExt + "." + _persistAsFileType;
|
_filename = sansExt + "." + _persistAsFileType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString OctreePersistThread::getPersistFileMimeType() const {
|
||||||
|
if (_persistAsFileType == "json") {
|
||||||
|
return "application/json";
|
||||||
|
} if (_persistAsFileType == "json.gz") {
|
||||||
|
return "application/zip";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
void OctreePersistThread::parseSettings(const QJsonObject& settings) {
|
void OctreePersistThread::parseSettings(const QJsonObject& settings) {
|
||||||
if (settings["backups"].isArray()) {
|
if (settings["backups"].isArray()) {
|
||||||
const QJsonArray& backupRules = settings["backups"].toArray();
|
const QJsonArray& backupRules = settings["backups"].toArray();
|
||||||
|
@ -229,6 +238,15 @@ void OctreePersistThread::aboutToFinish() {
|
||||||
_stopThread = true;
|
_stopThread = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray OctreePersistThread::getPersistFileContents() const {
|
||||||
|
QByteArray fileContents;
|
||||||
|
QFile file(_filename);
|
||||||
|
if (file.open(QIODevice::ReadOnly)) {
|
||||||
|
fileContents = file.readAll();
|
||||||
|
}
|
||||||
|
return fileContents;
|
||||||
|
}
|
||||||
|
|
||||||
void OctreePersistThread::persist() {
|
void OctreePersistThread::persist() {
|
||||||
if (_tree->isDirty()) {
|
if (_tree->isDirty()) {
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,10 @@ public:
|
||||||
|
|
||||||
void aboutToFinish(); /// call this to inform the persist thread that the owner is about to finish to support final persist
|
void aboutToFinish(); /// call this to inform the persist thread that the owner is about to finish to support final persist
|
||||||
|
|
||||||
|
QString getPersistFilename() const { return _filename; }
|
||||||
|
QString getPersistFileMimeType() const;
|
||||||
|
QByteArray getPersistFileContents() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void loadCompleted();
|
void loadCompleted();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue