mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 18:13:29 +02:00
Cache on upload
This commit is contained in:
parent
51acf07c15
commit
4abac35c72
2 changed files with 14 additions and 5 deletions
|
@ -23,9 +23,9 @@ AssetUpload::AssetUpload(QObject* object, const QString& filename) :
|
|||
|
||||
}
|
||||
|
||||
void AssetUpload::start() {
|
||||
void AssetUpload::start(bool cacheOnSuccess) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "start", Qt::AutoConnection);
|
||||
QMetaObject::invokeMethod(this, "start", Q_ARG(bool, cacheOnSuccess));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -37,14 +37,16 @@ void AssetUpload::start() {
|
|||
// file opened, read the data and grab the extension
|
||||
_extension = QFileInfo(_filename).suffix();
|
||||
|
||||
auto data = file.readAll();
|
||||
_data = file.readAll();
|
||||
|
||||
// ask the AssetClient to upload the asset and emit the proper signals from the passed callback
|
||||
auto assetClient = DependencyManager::get<AssetClient>();
|
||||
|
||||
qCDebug(asset_client) << "Attempting to upload" << _filename << "to asset-server.";
|
||||
|
||||
assetClient->uploadAsset(data, _extension, [this](bool responseReceived, AssetServerError error, const QString& hash){
|
||||
assetClient->uploadAsset(_data, _extension,
|
||||
[this, cacheOnSuccess](bool responseReceived, AssetServerError error,
|
||||
const QString& hash){
|
||||
if (!responseReceived) {
|
||||
_error = NetworkError;
|
||||
} else {
|
||||
|
@ -63,6 +65,12 @@ void AssetUpload::start() {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (cacheOnSuccess && _error == NoError &&
|
||||
hash == hashData(_data).toHex()) {
|
||||
saveToCache(getUrl(hash, _extension), _data);
|
||||
}
|
||||
|
||||
emit finished(this, hash);
|
||||
});
|
||||
} else {
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
|
||||
AssetUpload(QObject* parent, const QString& filename);
|
||||
|
||||
Q_INVOKABLE void start();
|
||||
Q_INVOKABLE void start(bool cacheOnSuccess = true);
|
||||
|
||||
const QString& getFilename() const { return _filename; }
|
||||
const QString& getExtension() const { return _extension; }
|
||||
|
@ -50,6 +50,7 @@ signals:
|
|||
private:
|
||||
QString _filename;
|
||||
QString _extension;
|
||||
QByteArray _data;
|
||||
Error _error;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue