mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 18:50:00 +02:00
add consistent error handling for asset request and upload
This commit is contained in:
parent
fccad7dca4
commit
9d19bf85b1
6 changed files with 63 additions and 91 deletions
|
@ -143,25 +143,17 @@ void ATPAssetMigrator::migrateResource(ResourceRequest* request) {
|
||||||
QFileInfo assetInfo { request->getUrl().fileName() };
|
QFileInfo assetInfo { request->getUrl().fileName() };
|
||||||
|
|
||||||
auto upload = assetClient->createUpload(request->getData());
|
auto upload = assetClient->createUpload(request->getData());
|
||||||
|
|
||||||
if (upload) {
|
// add this URL to our hash of AssetUpload to original URL
|
||||||
// add this URL to our hash of AssetUpload to original URL
|
_originalURLs.insert(upload, request->getUrl());
|
||||||
_originalURLs.insert(upload, request->getUrl());
|
|
||||||
|
qCDebug(asset_migrator) << "Starting upload of asset from" << request->getUrl();
|
||||||
qCDebug(asset_migrator) << "Starting upload of asset from" << request->getUrl();
|
|
||||||
|
// connect to the finished signal so we know when the AssetUpload is done
|
||||||
// connect to the finished signal so we know when the AssetUpload is done
|
QObject::connect(upload, &AssetUpload::finished, this, &ATPAssetMigrator::assetUploadFinished);
|
||||||
QObject::connect(upload, &AssetUpload::finished, this, &ATPAssetMigrator::assetUploadFinished);
|
|
||||||
|
// start the upload now
|
||||||
// start the upload now
|
upload->start();
|
||||||
upload->start();
|
|
||||||
} else {
|
|
||||||
// show a QMessageBox to say that there is no local asset server
|
|
||||||
QString messageBoxText = QString("Could not upload \n\n%1\n\nbecause you are currently not connected" \
|
|
||||||
" to a local asset-server.").arg(assetInfo.fileName());
|
|
||||||
|
|
||||||
QMessageBox::information(_dialogParent, "Failed to Upload", messageBoxText);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATPAssetMigrator::assetUploadFinished(AssetUpload *upload, const QString& hash) {
|
void ATPAssetMigrator::assetUploadFinished(AssetUpload *upload, const QString& hash) {
|
||||||
|
|
|
@ -44,20 +44,12 @@ void AssetUploadDialogFactory::showDialog() {
|
||||||
|
|
||||||
auto assetClient = DependencyManager::get<AssetClient>();
|
auto assetClient = DependencyManager::get<AssetClient>();
|
||||||
auto upload = assetClient->createUpload(filename);
|
auto upload = assetClient->createUpload(filename);
|
||||||
|
|
||||||
if (upload) {
|
// connect to the finished signal so we know when the AssetUpload is done
|
||||||
// connect to the finished signal so we know when the AssetUpload is done
|
QObject::connect(upload, &AssetUpload::finished, this, &AssetUploadDialogFactory::handleUploadFinished);
|
||||||
QObject::connect(upload, &AssetUpload::finished, this, &AssetUploadDialogFactory::handleUploadFinished);
|
|
||||||
|
// start the upload now
|
||||||
// start the upload now
|
upload->start();
|
||||||
upload->start();
|
|
||||||
} else {
|
|
||||||
// show a QMessageBox to say that there is no local asset server
|
|
||||||
QString messageBoxText = QString("Could not upload \n\n%1\n\nbecause you are currently not connected" \
|
|
||||||
" to a local asset-server.").arg(QFileInfo(filename).fileName());
|
|
||||||
|
|
||||||
QMessageBox::information(_dialogParent, "Failed to Upload", messageBoxText);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// we don't have permission to upload to asset server in this domain - show the permission denied error
|
// we don't have permission to upload to asset server in this domain - show the permission denied error
|
||||||
|
|
|
@ -144,62 +144,60 @@ GetMappingRequest* AssetClient::createGetMappingRequest(const AssetPath& path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
GetAllMappingsRequest* AssetClient::createGetAllMappingsRequest() {
|
GetAllMappingsRequest* AssetClient::createGetAllMappingsRequest() {
|
||||||
return new GetAllMappingsRequest();
|
auto request = new GetAllMappingsRequest();
|
||||||
|
|
||||||
|
request->moveToThread(thread());
|
||||||
|
|
||||||
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeleteMappingsRequest* AssetClient::createDeleteMappingsRequest(const AssetPathList& paths) {
|
DeleteMappingsRequest* AssetClient::createDeleteMappingsRequest(const AssetPathList& paths) {
|
||||||
return new DeleteMappingsRequest(paths);
|
auto request = new DeleteMappingsRequest(paths);
|
||||||
|
|
||||||
|
request->moveToThread(thread());
|
||||||
|
|
||||||
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetMappingRequest* AssetClient::createSetMappingRequest(const AssetPath& path, const AssetHash& hash) {
|
SetMappingRequest* AssetClient::createSetMappingRequest(const AssetPath& path, const AssetHash& hash) {
|
||||||
return new SetMappingRequest(path, hash);
|
auto request = new SetMappingRequest(path, hash);
|
||||||
|
|
||||||
|
request->moveToThread(thread());
|
||||||
|
|
||||||
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenameMappingRequest* AssetClient::createRenameMappingRequest(const AssetPath& oldPath, const AssetPath& newPath) {
|
RenameMappingRequest* AssetClient::createRenameMappingRequest(const AssetPath& oldPath, const AssetPath& newPath) {
|
||||||
return new RenameMappingRequest(oldPath, newPath);
|
auto request = new RenameMappingRequest(oldPath, newPath);
|
||||||
|
|
||||||
|
request->moveToThread(thread());
|
||||||
|
|
||||||
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetRequest* AssetClient::createRequest(const AssetHash& hash) {
|
AssetRequest* AssetClient::createRequest(const AssetHash& hash) {
|
||||||
if (isValidHash(hash)) {
|
auto request = new AssetRequest(hash);
|
||||||
qCWarning(asset_client) << "Invalid hash";
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (haveAssetServer()) {
|
// Move to the AssetClient thread in case we are not currently on that thread (which will usually be the case)
|
||||||
auto request = new AssetRequest(hash);
|
request->moveToThread(thread());
|
||||||
|
|
||||||
// Move to the AssetClient thread in case we are not currently on that thread (which will usually be the case)
|
return request;
|
||||||
request->moveToThread(thread());
|
|
||||||
|
|
||||||
return request;
|
|
||||||
} else {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetUpload* AssetClient::createUpload(const QString& filename) {
|
AssetUpload* AssetClient::createUpload(const QString& filename) {
|
||||||
|
auto upload = new AssetUpload(filename);
|
||||||
if (haveAssetServer()) {
|
|
||||||
auto upload = new AssetUpload(filename);
|
upload->moveToThread(thread());
|
||||||
|
|
||||||
upload->moveToThread(thread());
|
return upload;
|
||||||
|
|
||||||
return upload;
|
|
||||||
} else {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetUpload* AssetClient::createUpload(const QByteArray& data) {
|
AssetUpload* AssetClient::createUpload(const QByteArray& data) {
|
||||||
if (haveAssetServer()) {
|
auto upload = new AssetUpload(data);
|
||||||
auto upload = new AssetUpload(data);
|
|
||||||
|
upload->moveToThread(thread());
|
||||||
upload->moveToThread(thread());
|
|
||||||
|
return upload;
|
||||||
return upload;
|
|
||||||
} else {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AssetClient::getAsset(const QString& hash, DataOffset start, DataOffset end,
|
bool AssetClient::getAsset(const QString& hash, DataOffset start, DataOffset end,
|
||||||
|
@ -233,9 +231,12 @@ bool AssetClient::getAsset(const QString& hash, DataOffset start, DataOffset end
|
||||||
_pendingRequests[assetServer][messageID] = { callback, progressCallback };
|
_pendingRequests[assetServer][messageID] = { callback, progressCallback };
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
callback(false, AssetServerError::NoError, QByteArray());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AssetClient::getAssetInfo(const QString& hash, GetInfoCallback callback) {
|
bool AssetClient::getAssetInfo(const QString& hash, GetInfoCallback callback) {
|
||||||
|
@ -256,9 +257,10 @@ bool AssetClient::getAssetInfo(const QString& hash, GetInfoCallback callback) {
|
||||||
_pendingInfoRequests[assetServer][messageID] = callback;
|
_pendingInfoRequests[assetServer][messageID] = callback;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
callback(false, AssetServerError::NoError, { "", 0 });
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetClient::handleAssetGetInfoReply(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode) {
|
void AssetClient::handleAssetGetInfoReply(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode) {
|
||||||
|
@ -495,8 +497,10 @@ bool AssetClient::uploadAsset(const QByteArray& data, UploadResultCallback callb
|
||||||
_pendingUploads[assetServer][messageID] = callback;
|
_pendingUploads[assetServer][messageID] = callback;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
callback(false, AssetServerError::NoError, QString());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetClient::handleAssetUploadReply(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode) {
|
void AssetClient::handleAssetUploadReply(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode) {
|
||||||
|
|
|
@ -122,14 +122,6 @@ void AssetResourceRequest::requestHash(const AssetHash& hash) {
|
||||||
auto assetClient = DependencyManager::get<AssetClient>();
|
auto assetClient = DependencyManager::get<AssetClient>();
|
||||||
_assetRequest = assetClient->createRequest(hash);
|
_assetRequest = assetClient->createRequest(hash);
|
||||||
|
|
||||||
if (!_assetRequest) {
|
|
||||||
_result = ServerUnavailable;
|
|
||||||
_state = Finished;
|
|
||||||
|
|
||||||
emit finished();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(_assetRequest, &AssetRequest::progress, this, &AssetResourceRequest::progress);
|
connect(_assetRequest, &AssetRequest::progress, this, &AssetResourceRequest::progress);
|
||||||
connect(_assetRequest, &AssetRequest::finished, this, [this](AssetRequest* req) {
|
connect(_assetRequest, &AssetRequest::finished, this, [this](AssetRequest* req) {
|
||||||
Q_ASSERT(_state == InProgress);
|
Q_ASSERT(_state == InProgress);
|
||||||
|
|
|
@ -41,7 +41,7 @@ QString AssetUpload::getErrorString() const {
|
||||||
case AssetUpload::FileOpenError:
|
case AssetUpload::FileOpenError:
|
||||||
return "The file could not be opened. Please check your permissions and try again.";
|
return "The file could not be opened. Please check your permissions and try again.";
|
||||||
case AssetUpload::NetworkError:
|
case AssetUpload::NetworkError:
|
||||||
return "The file could not be opened. Please check your network connectivity.";
|
return "There was a problem reaching your Asset Server. Please check your network connectivity.";
|
||||||
default:
|
default:
|
||||||
// not handled, do not show a message box
|
// not handled, do not show a message box
|
||||||
return QString();
|
return QString();
|
||||||
|
|
|
@ -27,10 +27,6 @@ AssetScriptingInterface::AssetScriptingInterface(QScriptEngine* engine) :
|
||||||
void AssetScriptingInterface::uploadData(QString data, QScriptValue callback) {
|
void AssetScriptingInterface::uploadData(QString data, QScriptValue callback) {
|
||||||
QByteArray dataByteArray = data.toUtf8();
|
QByteArray dataByteArray = data.toUtf8();
|
||||||
auto upload = DependencyManager::get<AssetClient>()->createUpload(dataByteArray);
|
auto upload = DependencyManager::get<AssetClient>()->createUpload(dataByteArray);
|
||||||
if (!upload) {
|
|
||||||
qCWarning(asset_client) << "Error uploading file to asset server";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QObject::connect(upload, &AssetUpload::finished, this, [this, callback](AssetUpload* upload, const QString& hash) mutable {
|
QObject::connect(upload, &AssetUpload::finished, this, [this, callback](AssetUpload* upload, const QString& hash) mutable {
|
||||||
if (callback.isFunction()) {
|
if (callback.isFunction()) {
|
||||||
|
@ -61,10 +57,6 @@ void AssetScriptingInterface::downloadData(QString urlString, QScriptValue callb
|
||||||
auto assetClient = DependencyManager::get<AssetClient>();
|
auto assetClient = DependencyManager::get<AssetClient>();
|
||||||
auto assetRequest = assetClient->createRequest(hash);
|
auto assetRequest = assetClient->createRequest(hash);
|
||||||
|
|
||||||
if (!assetRequest) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_pendingRequests << assetRequest;
|
_pendingRequests << assetRequest;
|
||||||
|
|
||||||
connect(assetRequest, &AssetRequest::finished, this, [this, callback](AssetRequest* request) mutable {
|
connect(assetRequest, &AssetRequest::finished, this, [this, callback](AssetRequest* request) mutable {
|
||||||
|
|
Loading…
Reference in a new issue