mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 15:49:24 +02:00
Update DS to use promises for backup APIs
This commit is contained in:
parent
8b07e7e28f
commit
dd398da2e0
3 changed files with 48 additions and 37 deletions
|
@ -212,54 +212,58 @@ bool DomainContentBackupManager::getMostRecentBackup(const QString& format,
|
||||||
return bestBackupFound;
|
return bestBackupFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DomainContentBackupManager::deleteBackup(const QString& backupName) {
|
void DomainContentBackupManager::deleteBackup(MiniPromise::Promise promise, const QString& backupName) {
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
bool result{ false };
|
QMetaObject::invokeMethod(this, "deleteBackup", Q_ARG(MiniPromise::Promise, promise),
|
||||||
BLOCKING_INVOKE_METHOD(this, "deleteBackup",
|
Q_ARG(const QString&, backupName));
|
||||||
Q_RETURN_ARG(bool, result),
|
return;
|
||||||
Q_ARG(const QString&, backupName));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool success { false };
|
||||||
QDir backupDir { _backupDirectory };
|
QDir backupDir { _backupDirectory };
|
||||||
QFile backupFile { backupDir.filePath(backupName) };
|
QFile backupFile { backupDir.filePath(backupName) };
|
||||||
if (backupFile.remove()) {
|
if (backupFile.remove()) {
|
||||||
return true;
|
success = true;
|
||||||
}
|
}
|
||||||
return false;
|
promise->resolve({
|
||||||
|
{ "success", success }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DomainContentBackupManager::recoverFromBackup(const QString& backupName) {
|
void DomainContentBackupManager::recoverFromBackup(MiniPromise::Promise promise, const QString& backupName) {
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
bool result{ false };
|
QMetaObject::invokeMethod(this, "recoverFromBackup", Q_ARG(MiniPromise::Promise, promise),
|
||||||
BLOCKING_INVOKE_METHOD(this, "recoverFromBackup",
|
Q_ARG(const QString&, backupName));
|
||||||
Q_RETURN_ARG(bool, result),
|
return;
|
||||||
Q_ARG(const QString&, backupName));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Recoving from" << backupName;
|
qDebug() << "Recoving from" << backupName;
|
||||||
|
|
||||||
|
bool success { false };
|
||||||
QDir backupDir { _backupDirectory };
|
QDir backupDir { _backupDirectory };
|
||||||
QFile backupFile { backupDir.filePath(backupName) };
|
QFile backupFile { backupDir.filePath(backupName) };
|
||||||
if (backupFile.open(QIODevice::ReadOnly)) {
|
if (backupFile.open(QIODevice::ReadOnly)) {
|
||||||
QuaZip zip { &backupFile };
|
QuaZip zip { &backupFile };
|
||||||
if (!zip.open(QuaZip::Mode::mdUnzip)) {
|
if (!zip.open(QuaZip::Mode::mdUnzip)) {
|
||||||
qWarning() << "Failed to unzip file: " << backupName;
|
qWarning() << "Failed to unzip file: " << backupName;
|
||||||
backupFile.close();
|
success = false;
|
||||||
|
} else {
|
||||||
|
for (auto& handler : _backupHandlers) {
|
||||||
|
handler.recoverBackup(zip);
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "Successfully recovered from " << backupName;
|
||||||
|
success = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& handler : _backupHandlers) {
|
|
||||||
handler.recoverBackup(zip);
|
|
||||||
}
|
|
||||||
|
|
||||||
backupFile.close();
|
backupFile.close();
|
||||||
qDebug() << "Successfully recovered from " << backupName;
|
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
|
success = false;
|
||||||
qWarning() << "Invalid id: " << backupName;
|
qWarning() << "Invalid id: " << backupName;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
promise->resolve({
|
||||||
|
{ "success", success }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<BackupItemInfo> DomainContentBackupManager::getAllBackups() {
|
std::vector<BackupItemInfo> DomainContentBackupManager::getAllBackups() {
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
#include "BackupHandler.h"
|
#include "BackupHandler.h"
|
||||||
|
|
||||||
|
#include <shared/MiniPromises.h>
|
||||||
|
|
||||||
struct BackupItemInfo {
|
struct BackupItemInfo {
|
||||||
QString id;
|
QString id;
|
||||||
QString name;
|
QString name;
|
||||||
|
@ -59,8 +61,8 @@ public:
|
||||||
void createManualBackup(const QString& name);
|
void createManualBackup(const QString& name);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool recoverFromBackup(const QString& backupName);
|
void recoverFromBackup(MiniPromise::Promise promise, const QString& backupName);
|
||||||
bool deleteBackup(const QString& backupName);
|
void deleteBackup(MiniPromise::Promise promise, const QString& backupName);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void loadCompleted();
|
void loadCompleted();
|
||||||
|
|
|
@ -2124,11 +2124,14 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
return true;
|
return true;
|
||||||
} 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());
|
||||||
_contentManager->recoverFromBackup(id);
|
auto deferred = makePromise("recoverFromBackup");
|
||||||
QJsonObject rootJSON;
|
deferred->then([connection, JSON_MIME_TYPE](QString error, QVariantMap result) {
|
||||||
rootJSON["success"] = true;
|
QJsonObject rootJSON;
|
||||||
QJsonDocument docJSON(rootJSON);
|
rootJSON["success"] = result["success"].toBool();
|
||||||
connection->respond(HTTPConnection::StatusCode200, docJSON.toJson(), JSON_MIME_TYPE.toUtf8());
|
QJsonDocument docJSON(rootJSON);
|
||||||
|
connection->respond(HTTPConnection::StatusCode200, docJSON.toJson(), JSON_MIME_TYPE.toUtf8());
|
||||||
|
});
|
||||||
|
_contentManager->recoverFromBackup(deferred, id);
|
||||||
return true;
|
return true;
|
||||||
} else if (url.path() == URI_API_BACKUPS) {
|
} else if (url.path() == URI_API_BACKUPS) {
|
||||||
QJsonObject rootJSON;
|
QJsonObject rootJSON;
|
||||||
|
@ -2368,11 +2371,15 @@ 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 success = _contentManager->deleteBackup(id);
|
auto deferred = makePromise("deleteBackup");
|
||||||
QJsonObject rootJSON;
|
deferred->then([connection, JSON_MIME_TYPE](QString error, QVariantMap result) {
|
||||||
rootJSON["success"] = success;
|
QJsonObject rootJSON;
|
||||||
QJsonDocument docJSON(rootJSON);
|
rootJSON["success"] = result["success"].toBool();
|
||||||
connection->respond(HTTPConnection::StatusCode200, docJSON.toJson(), JSON_MIME_TYPE.toUtf8());
|
QJsonDocument docJSON(rootJSON);
|
||||||
|
connection->respond(HTTPConnection::StatusCode200, docJSON.toJson(), JSON_MIME_TYPE.toUtf8());
|
||||||
|
});
|
||||||
|
_contentManager->deleteBackup(deferred, id);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if (nodeDeleteRegex.indexIn(url.path()) != -1) {
|
} else if (nodeDeleteRegex.indexIn(url.path()) != -1) {
|
||||||
|
@ -3310,8 +3317,6 @@ void DomainServer::maybeHandleReplacementEntityFile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainServer::handleOctreeFileReplacement(QByteArray octreeFile) {
|
void DomainServer::handleOctreeFileReplacement(QByteArray octreeFile) {
|
||||||
// enumerate the nodes and find any octree type servers with active sockets
|
|
||||||
|
|
||||||
//Assume we have compressed data
|
//Assume we have compressed data
|
||||||
auto compressedOctree = octreeFile;
|
auto compressedOctree = octreeFile;
|
||||||
QByteArray jsonOctree;
|
QByteArray jsonOctree;
|
||||||
|
|
Loading…
Reference in a new issue