Issue/591 add assets file browsing (#3798)

* create download event topic wip

* Make topic connection thread safe & rate limit downloadeventtopic data to reduce traffic


* add LDEBUG and LERROR on donwload start/finish/failed

* Add new AssetLoadingEvent
event 
* fix pr comments
This commit is contained in:
Andreas Engberg
2025-12-01 11:14:41 +01:00
committed by GitHub
parent 4267c181c5
commit dfbc1f5090
20 changed files with 515 additions and 45 deletions

View File

@@ -26,6 +26,8 @@
#include <openspace/documentation/documentation.h>
#include <openspace/documentation/verifier.h>
#include <openspace/engine/globals.h>
#include <openspace/util/downloadeventengine.h>
#include <openspace/util/httprequest.h>
#include <ghoul/ext/assimp/contrib/zip/src/zip.h>
#include <ghoul/logging/logmanager.h>
@@ -332,9 +334,25 @@ HttpSynchronization::trySyncFromUrl(std::string url) {
_nSynchronizedBytes += sd.second.downloadedBytes;
}
DownloadEventEngine::DownloadEvent event = {
.type = DownloadEventEngine::DownloadEvent::Type::Progress,
.id = line,
.downloadedBytes = downloadedBytes,
.totalBytes = totalBytes
};
global::downloadEventEngine->publish(event);
return !_shouldCancel;
});
DownloadEventEngine::DownloadEvent event = {
.type = DownloadEventEngine::DownloadEvent::Type::Started,
.id = line,
.downloadedBytes = 0
};
global::downloadEventEngine->publish(event);
LDEBUG(std::format("Started downloading '{}'", dl->url()));
dl->start();
}
startedAllDownloads = true;
@@ -373,6 +391,12 @@ HttpSynchronization::trySyncFromUrl(std::string url) {
if (!d->hasSucceeded()) {
LERROR(std::format("Error downloading file from URL '{}'", d->url()));
failed = true;
global::downloadEventEngine->publish(
d->url(),
DownloadEventEngine::DownloadEvent::Type::Failed
);
LERROR(std::format("Failed to download '{}'", d->url()));
continue;
}
@@ -421,16 +445,38 @@ HttpSynchronization::trySyncFromUrl(std::string url) {
std::filesystem::remove(source);
}
}
if (failed) {
for (const std::unique_ptr<HttpFileDownload>& d : downloads) {
// Store all files that were synced to the ossync
for (const std::unique_ptr<HttpFileDownload>& d : downloads) {
if (failed) {
// At least one download failed, (some downloads may have succeeded)
if (d->hasSucceeded()) {
_newSyncedFiles.push_back(d->url());
global::downloadEventEngine->publish(
d->url(),
DownloadEventEngine::DownloadEvent::Type::Finished
);
LDEBUG(std::format("Finished downloading '{}'", d->url()));
}
else {
global::downloadEventEngine->publish(
d->url(),
DownloadEventEngine::DownloadEvent::Type::Failed
);
LERROR(std::format("Failed to download '{}'", d->url()));
}
}
return SynchronizationState::FileDownloadFail;
else {
// All downloads are successful
global::downloadEventEngine->publish(
d->url(),
DownloadEventEngine::DownloadEvent::Type::Finished
);
LDEBUG(std::format("Finished downloading '{}'", d->url()));
}
}
return SynchronizationState::Success;
return failed ? SynchronizationState::FileDownloadFail : SynchronizationState::Success;
}
} // namespace openspace