mirror of
https://github.com/overte-org/overte.git
synced 2025-07-24 01:03:58 +02:00
Merge pull request #2698 from Atlante45/master
ModelUploader update to handle new behaviour
This commit is contained in:
commit
d0c10475d5
2 changed files with 63 additions and 6 deletions
|
@ -34,6 +34,7 @@ static const QString TEXDIR_FIELD = "texdir";
|
||||||
static const QString LOD_FIELD = "lod";
|
static const QString LOD_FIELD = "lod";
|
||||||
|
|
||||||
static const QString S3_URL = "http://highfidelity-public.s3-us-west-1.amazonaws.com";
|
static const QString S3_URL = "http://highfidelity-public.s3-us-west-1.amazonaws.com";
|
||||||
|
static const QString DATA_SERVER_URL = "https://data-web.highfidelity.io";
|
||||||
static const QString MODEL_URL = "/api/v1/models";
|
static const QString MODEL_URL = "/api/v1/models";
|
||||||
|
|
||||||
static const QString SETTING_NAME = "LastModelUploadLocation";
|
static const QString SETTING_NAME = "LastModelUploadLocation";
|
||||||
|
@ -201,14 +202,14 @@ void ModelUploader::send() {
|
||||||
|
|
||||||
JSONCallbackParameters callbackParams;
|
JSONCallbackParameters callbackParams;
|
||||||
callbackParams.jsonCallbackReceiver = this;
|
callbackParams.jsonCallbackReceiver = this;
|
||||||
callbackParams.jsonCallbackMethod = "uploadSuccess";
|
callbackParams.jsonCallbackMethod = "checkJSON";
|
||||||
callbackParams.errorCallbackReceiver = this;
|
callbackParams.errorCallbackReceiver = this;
|
||||||
callbackParams.errorCallbackMethod = "uploadFailed";
|
callbackParams.errorCallbackMethod = "uploadFailed";
|
||||||
callbackParams.updateReciever = this;
|
|
||||||
callbackParams.updateSlot = SLOT(uploadUpdate(qint64, qint64));
|
|
||||||
|
|
||||||
AccountManager::getInstance().authenticatedRequest(MODEL_URL, QNetworkAccessManager::PostOperation, callbackParams, QByteArray(), _dataMultiPart);
|
AccountManager::getInstance().authenticatedRequest(MODEL_URL + "/" + QFileInfo(_url).baseName(),
|
||||||
_dataMultiPart = NULL;
|
QNetworkAccessManager::GetOperation,
|
||||||
|
callbackParams);
|
||||||
|
|
||||||
qDebug() << "Sending model...";
|
qDebug() << "Sending model...";
|
||||||
_progressDialog = new QDialog();
|
_progressDialog = new QDialog();
|
||||||
_progressBar = new QProgressBar(_progressDialog);
|
_progressBar = new QProgressBar(_progressDialog);
|
||||||
|
@ -226,6 +227,61 @@ void ModelUploader::send() {
|
||||||
_progressBar = NULL;
|
_progressBar = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModelUploader::checkJSON(const QJsonObject& jsonResponse) {
|
||||||
|
if (jsonResponse.contains("status") && jsonResponse.value("status").toString() == "success") {
|
||||||
|
qDebug() << "status : success";
|
||||||
|
JSONCallbackParameters callbackParams;
|
||||||
|
callbackParams.jsonCallbackReceiver = this;
|
||||||
|
callbackParams.jsonCallbackMethod = "uploadSuccess";
|
||||||
|
callbackParams.errorCallbackReceiver = this;
|
||||||
|
callbackParams.errorCallbackMethod = "uploadFailed";
|
||||||
|
callbackParams.updateReciever = this;
|
||||||
|
callbackParams.updateSlot = SLOT(uploadUpdate(qint64, qint64));
|
||||||
|
|
||||||
|
if (jsonResponse.contains("exists") && jsonResponse.value("exists").toBool()) {
|
||||||
|
qDebug() << "exists : true";
|
||||||
|
if (jsonResponse.contains("can_update") && jsonResponse.value("can_update").toBool()) {
|
||||||
|
qDebug() << "can_update : true";
|
||||||
|
|
||||||
|
AccountManager::getInstance().authenticatedRequest(MODEL_URL + "/" + QFileInfo(_url).baseName(),
|
||||||
|
QNetworkAccessManager::PutOperation,
|
||||||
|
callbackParams,
|
||||||
|
QByteArray(),
|
||||||
|
_dataMultiPart);
|
||||||
|
_dataMultiPart = NULL;
|
||||||
|
} else {
|
||||||
|
qDebug() << "can_update : false";
|
||||||
|
if (_progressDialog) {
|
||||||
|
_progressDialog->reject();
|
||||||
|
}
|
||||||
|
QMessageBox::warning(NULL,
|
||||||
|
QString("ModelUploader::checkJSON()"),
|
||||||
|
QString("This model already exist and is own by someone else."),
|
||||||
|
QMessageBox::Ok);
|
||||||
|
deleteLater();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qDebug() << "exists : false";
|
||||||
|
AccountManager::getInstance().authenticatedRequest(MODEL_URL,
|
||||||
|
QNetworkAccessManager::PostOperation,
|
||||||
|
callbackParams,
|
||||||
|
QByteArray(),
|
||||||
|
_dataMultiPart);
|
||||||
|
_dataMultiPart = NULL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qDebug() << "status : failed";
|
||||||
|
if (_progressDialog) {
|
||||||
|
_progressDialog->reject();
|
||||||
|
}
|
||||||
|
QMessageBox::warning(NULL,
|
||||||
|
QString("ModelUploader::checkJSON()"),
|
||||||
|
QString("Something went wrong with the data-server."),
|
||||||
|
QMessageBox::Ok);
|
||||||
|
deleteLater();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ModelUploader::uploadUpdate(qint64 bytesSent, qint64 bytesTotal) {
|
void ModelUploader::uploadUpdate(qint64 bytesSent, qint64 bytesTotal) {
|
||||||
if (_progressDialog) {
|
if (_progressDialog) {
|
||||||
_progressBar->setRange(0, bytesTotal);
|
_progressBar->setRange(0, bytesTotal);
|
||||||
|
@ -249,11 +305,11 @@ void ModelUploader::uploadFailed(QNetworkReply::NetworkError errorCode, const QS
|
||||||
if (_progressDialog) {
|
if (_progressDialog) {
|
||||||
_progressDialog->reject();
|
_progressDialog->reject();
|
||||||
}
|
}
|
||||||
|
qDebug() << "Model upload failed (" << errorCode << "): " << errorString;
|
||||||
QMessageBox::warning(NULL,
|
QMessageBox::warning(NULL,
|
||||||
QString("ModelUploader::uploadFailed()"),
|
QString("ModelUploader::uploadFailed()"),
|
||||||
QString("There was a problem with your upload, please try again later."),
|
QString("There was a problem with your upload, please try again later."),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
qDebug() << "Model upload failed (" << errorCode << "): " << errorString;
|
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ public slots:
|
||||||
void send();
|
void send();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void checkJSON(const QJsonObject& jsonResponse);
|
||||||
void uploadUpdate(qint64 bytesSent, qint64 bytesTotal);
|
void uploadUpdate(qint64 bytesSent, qint64 bytesTotal);
|
||||||
void uploadSuccess(const QJsonObject& jsonResponse);
|
void uploadSuccess(const QJsonObject& jsonResponse);
|
||||||
void uploadFailed(QNetworkReply::NetworkError errorCode, const QString& errorString);
|
void uploadFailed(QNetworkReply::NetworkError errorCode, const QString& errorString);
|
||||||
|
|
Loading…
Reference in a new issue