mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 19:29:47 +02:00
Prevent crash during long backup web requests
This commit is contained in:
parent
9294ae0dd2
commit
a23884d0e0
1 changed files with 40 additions and 14 deletions
|
@ -1937,6 +1937,8 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
|
|
||||||
const QString UUID_REGEX_STRING = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
const QString UUID_REGEX_STRING = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
||||||
|
|
||||||
|
QPointer<HTTPConnection> connectionPtr { connection };
|
||||||
|
|
||||||
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
||||||
|
|
||||||
auto getSetting = [this](QString keyPath, QVariant value) -> bool {
|
auto getSetting = [this](QString keyPath, QVariant value) -> bool {
|
||||||
|
@ -2120,30 +2122,38 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
return true;
|
return true;
|
||||||
} else if (url.path() == URI_API_BACKUPS) {
|
} else if (url.path() == URI_API_BACKUPS) {
|
||||||
auto deferred = makePromise("getAllBackupsAndStatus");
|
auto deferred = makePromise("getAllBackupsAndStatus");
|
||||||
deferred->then([connection, JSON_MIME_TYPE](QString error, QVariantMap result) {
|
deferred->then([connectionPtr, JSON_MIME_TYPE](QString error, QVariantMap result) {
|
||||||
|
if (!connectionPtr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonDocument docJSON(QJsonObject::fromVariantMap(result));
|
QJsonDocument docJSON(QJsonObject::fromVariantMap(result));
|
||||||
|
|
||||||
connection->respond(HTTPConnection::StatusCode200, docJSON.toJson(), JSON_MIME_TYPE.toUtf8());
|
connectionPtr->respond(HTTPConnection::StatusCode200, docJSON.toJson(), JSON_MIME_TYPE.toUtf8());
|
||||||
});
|
});
|
||||||
_contentManager->getAllBackupsAndStatus(deferred);
|
_contentManager->getAllBackupsAndStatus(deferred);
|
||||||
return true;
|
return true;
|
||||||
} else if (url.path().startsWith(URI_API_BACKUPS_ID)) {
|
} else if (url.path().startsWith(URI_API_BACKUPS_ID)) {
|
||||||
auto id = url.path().mid(QString(URI_API_BACKUPS_ID).length());
|
auto id = url.path().mid(QString(URI_API_BACKUPS_ID).length());
|
||||||
auto deferred = makePromise("consolidateBackup");
|
auto deferred = makePromise("consolidateBackup");
|
||||||
deferred->then([connection, JSON_MIME_TYPE](QString error, QVariantMap result) {
|
deferred->then([connectionPtr, JSON_MIME_TYPE](QString error, QVariantMap result) {
|
||||||
|
if (!connectionPtr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonObject rootJSON;
|
QJsonObject rootJSON;
|
||||||
auto success = result["success"].toBool();
|
auto success = result["success"].toBool();
|
||||||
if (success) {
|
if (success) {
|
||||||
auto path = result["backupFilePath"].toString();
|
auto path = result["backupFilePath"].toString();
|
||||||
auto file { std::unique_ptr<QFile>(new QFile(path)) };
|
auto file { std::unique_ptr<QFile>(new QFile(path)) };
|
||||||
if (file->open(QIODevice::ReadOnly)) {
|
if (file->open(QIODevice::ReadOnly)) {
|
||||||
connection->respond(HTTPConnection::StatusCode200, std::move(file));
|
connectionPtr->respond(HTTPConnection::StatusCode200, std::move(file));
|
||||||
} else {
|
} else {
|
||||||
qCritical(domain_server) << "Unable to load consolidated backup at:" << path << result;
|
qCritical(domain_server) << "Unable to load consolidated backup at:" << path << result;
|
||||||
connection->respond(HTTPConnection::StatusCode500, "Error opening backup");
|
connectionPtr->respond(HTTPConnection::StatusCode500, "Error opening backup");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
connection->respond(HTTPConnection::StatusCode400);
|
connectionPtr->respond(HTTPConnection::StatusCode400);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
_contentManager->consolidateBackup(deferred, id);
|
_contentManager->consolidateBackup(deferred, id);
|
||||||
|
@ -2264,12 +2274,16 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
} else if (uploadedFilename.endsWith(".zip", Qt::CaseInsensitive)) {
|
} else if (uploadedFilename.endsWith(".zip", Qt::CaseInsensitive)) {
|
||||||
auto deferred = makePromise("recoverFromUploadedBackup");
|
auto deferred = makePromise("recoverFromUploadedBackup");
|
||||||
|
|
||||||
deferred->then([connection, JSON_MIME_TYPE](QString error, QVariantMap result) {
|
deferred->then([connectionPtr, JSON_MIME_TYPE](QString error, QVariantMap result) {
|
||||||
|
if (!connectionPtr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonObject rootJSON;
|
QJsonObject rootJSON;
|
||||||
auto success = result["success"].toBool();
|
auto success = result["success"].toBool();
|
||||||
rootJSON["success"] = success;
|
rootJSON["success"] = success;
|
||||||
QJsonDocument docJSON(rootJSON);
|
QJsonDocument docJSON(rootJSON);
|
||||||
connection->respond(success ? HTTPConnection::StatusCode200 : HTTPConnection::StatusCode400, docJSON.toJson(),
|
connectionPtr->respond(success ? HTTPConnection::StatusCode200 : HTTPConnection::StatusCode400, docJSON.toJson(),
|
||||||
JSON_MIME_TYPE.toUtf8());
|
JSON_MIME_TYPE.toUtf8());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2297,12 +2311,16 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
}
|
}
|
||||||
|
|
||||||
auto deferred = makePromise("createManualBackup");
|
auto deferred = makePromise("createManualBackup");
|
||||||
deferred->then([connection, JSON_MIME_TYPE](QString error, QVariantMap result) {
|
deferred->then([connectionPtr, JSON_MIME_TYPE](QString error, QVariantMap result) {
|
||||||
|
if (!connectionPtr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonObject rootJSON;
|
QJsonObject rootJSON;
|
||||||
auto success = result["success"].toBool();
|
auto success = result["success"].toBool();
|
||||||
rootJSON["success"] = success;
|
rootJSON["success"] = success;
|
||||||
QJsonDocument docJSON(rootJSON);
|
QJsonDocument docJSON(rootJSON);
|
||||||
connection->respond(success ? HTTPConnection::StatusCode200 : HTTPConnection::StatusCode400, docJSON.toJson(),
|
connectionPtr->respond(success ? HTTPConnection::StatusCode200 : HTTPConnection::StatusCode400, docJSON.toJson(),
|
||||||
JSON_MIME_TYPE.toUtf8());
|
JSON_MIME_TYPE.toUtf8());
|
||||||
});
|
});
|
||||||
_contentManager->createManualBackup(deferred, it.value());
|
_contentManager->createManualBackup(deferred, it.value());
|
||||||
|
@ -2322,12 +2340,16 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
} else if (url.path().startsWith(URI_API_BACKUPS_RECOVER)) {
|
} else if (url.path().startsWith(URI_API_BACKUPS_RECOVER)) {
|
||||||
auto id = url.path().mid(QString(URI_API_BACKUPS_RECOVER).length());
|
auto id = url.path().mid(QString(URI_API_BACKUPS_RECOVER).length());
|
||||||
auto deferred = makePromise("recoverFromBackup");
|
auto deferred = makePromise("recoverFromBackup");
|
||||||
deferred->then([connection, JSON_MIME_TYPE](QString error, QVariantMap result) {
|
deferred->then([connectionPtr, JSON_MIME_TYPE](QString error, QVariantMap result) {
|
||||||
|
if (!connectionPtr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonObject rootJSON;
|
QJsonObject rootJSON;
|
||||||
auto success = result["success"].toBool();
|
auto success = result["success"].toBool();
|
||||||
rootJSON["success"] = success;
|
rootJSON["success"] = success;
|
||||||
QJsonDocument docJSON(rootJSON);
|
QJsonDocument docJSON(rootJSON);
|
||||||
connection->respond(success ? HTTPConnection::StatusCode200 : HTTPConnection::StatusCode400, docJSON.toJson(),
|
connectionPtr->respond(success ? HTTPConnection::StatusCode200 : HTTPConnection::StatusCode400, docJSON.toJson(),
|
||||||
JSON_MIME_TYPE.toUtf8());
|
JSON_MIME_TYPE.toUtf8());
|
||||||
});
|
});
|
||||||
_contentManager->recoverFromBackup(deferred, id);
|
_contentManager->recoverFromBackup(deferred, id);
|
||||||
|
@ -2423,12 +2445,16 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
if (url.path().startsWith(URI_API_BACKUPS_ID)) {
|
if (url.path().startsWith(URI_API_BACKUPS_ID)) {
|
||||||
auto id = url.path().mid(QString(URI_API_BACKUPS_ID).length());
|
auto id = url.path().mid(QString(URI_API_BACKUPS_ID).length());
|
||||||
auto deferred = makePromise("deleteBackup");
|
auto deferred = makePromise("deleteBackup");
|
||||||
deferred->then([connection, JSON_MIME_TYPE](QString error, QVariantMap result) {
|
deferred->then([connectionPtr, JSON_MIME_TYPE](QString error, QVariantMap result) {
|
||||||
|
if (!connectionPtr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonObject rootJSON;
|
QJsonObject rootJSON;
|
||||||
auto success = result["success"].toBool();
|
auto success = result["success"].toBool();
|
||||||
rootJSON["success"] = success;
|
rootJSON["success"] = success;
|
||||||
QJsonDocument docJSON(rootJSON);
|
QJsonDocument docJSON(rootJSON);
|
||||||
connection->respond(success ? HTTPConnection::StatusCode200 : HTTPConnection::StatusCode400, docJSON.toJson(),
|
connectionPtr->respond(success ? HTTPConnection::StatusCode200 : HTTPConnection::StatusCode400, docJSON.toJson(),
|
||||||
JSON_MIME_TYPE.toUtf8());
|
JSON_MIME_TYPE.toUtf8());
|
||||||
});
|
});
|
||||||
_contentManager->deleteBackup(deferred, id);
|
_contentManager->deleteBackup(deferred, id);
|
||||||
|
|
Loading…
Reference in a new issue