mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 15:49:24 +02:00
CR feedback
This commit is contained in:
parent
7e9190d0e1
commit
f1badc017b
2 changed files with 15 additions and 25 deletions
|
@ -369,18 +369,19 @@ void AssetClient::handleNodeKilled(SharedNodePointer node) {
|
||||||
void AssetScriptingInterface::uploadData(QString data, QString extension, QScriptValue callback) {
|
void AssetScriptingInterface::uploadData(QString data, QString extension, QScriptValue callback) {
|
||||||
QByteArray dataByteArray = data.toUtf8();
|
QByteArray dataByteArray = data.toUtf8();
|
||||||
auto upload = DependencyManager::get<AssetClient>()->createUpload(dataByteArray, extension);
|
auto upload = DependencyManager::get<AssetClient>()->createUpload(dataByteArray, extension);
|
||||||
if (upload) {
|
if (!upload) {
|
||||||
QObject::connect(upload, &AssetUpload::finished, this, [callback, extension](AssetUpload* upload, const QString& hash) mutable {
|
qCWarning(asset_client) << "Error uploading file to asset server";
|
||||||
if (callback.isFunction()) {
|
return;
|
||||||
QString url = "atp://" + hash + "." + extension;
|
|
||||||
QScriptValueList args { url };
|
|
||||||
callback.call(QScriptValue(), args);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// start the upload now
|
|
||||||
upload->start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QObject::connect(upload, &AssetUpload::finished, this, [callback, extension](AssetUpload* upload, const QString& hash) mutable {
|
||||||
|
if (callback.isFunction()) {
|
||||||
|
QString url = "atp://" + hash + "." + extension;
|
||||||
|
QScriptValueList args { url };
|
||||||
|
callback.call(QScriptValue(), args);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
upload->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetScriptingInterface::downloadData(QString urlString, QScriptValue callback) {
|
void AssetScriptingInterface::downloadData(QString urlString, QScriptValue callback) {
|
||||||
|
@ -407,10 +408,7 @@ void AssetScriptingInterface::downloadData(QString urlString, QScriptValue callb
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
_pendingRequests << assetRequest;
|
||||||
QWriteLocker locker(&_lock);
|
|
||||||
_pendingRequests << assetRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(assetRequest, &AssetRequest::finished, [this, callback](AssetRequest* request) mutable {
|
connect(assetRequest, &AssetRequest::finished, [this, callback](AssetRequest* request) mutable {
|
||||||
Q_ASSERT(request->getState() == AssetRequest::Finished);
|
Q_ASSERT(request->getState() == AssetRequest::Finished);
|
||||||
|
@ -424,15 +422,8 @@ void AssetScriptingInterface::downloadData(QString urlString, QScriptValue callb
|
||||||
}
|
}
|
||||||
|
|
||||||
request->deleteLater();
|
request->deleteLater();
|
||||||
|
_pendingRequests.remove(request);
|
||||||
{
|
|
||||||
QWriteLocker locker(&_lock);
|
|
||||||
_pendingRequests.remove(request);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assetRequest->start();
|
assetRequest->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,6 @@ public:
|
||||||
Q_INVOKABLE void uploadData(QString data, QString extension, QScriptValue callback);
|
Q_INVOKABLE void uploadData(QString data, QString extension, QScriptValue callback);
|
||||||
Q_INVOKABLE void downloadData(QString url, QScriptValue downloadComplete);
|
Q_INVOKABLE void downloadData(QString url, QScriptValue downloadComplete);
|
||||||
protected:
|
protected:
|
||||||
mutable QReadWriteLock _lock;
|
|
||||||
QSet<AssetRequest*> _pendingRequests;
|
QSet<AssetRequest*> _pendingRequests;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue