From 1cb1c632286ae3395a5388cfea0dab1d9aae5b96 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 23 Sep 2020 23:08:02 +1200 Subject: [PATCH] Tidying --- interface/src/Application.cpp | 5 -- libraries/networking/src/ExternalResource.cpp | 35 ++++++------ libraries/networking/src/ExternalResource.h | 56 +++---------------- 3 files changed, 24 insertions(+), 72 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 2c5e09ed62..4e6ed35d2c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3295,7 +3295,6 @@ void Application::initializeUi() { qmlRegisterType("Hifi", 1, 0, "ResourceImageItem"); qmlRegisterType("Hifi", 1, 0, "Preference"); qmlRegisterType("HifiWeb", 1, 0, "WebBrowserSuggestionsEngine"); - // qmlRegisterType("ExternalResource", 1, 0, "ExternalResource"); { auto tabletScriptingInterface = DependencyManager::get(); @@ -7569,10 +7568,6 @@ void Application::registerScriptEngineWithApplicationServices(const ScriptEngine scriptEngine->registerGlobalObject("HifiAbout", AboutUtil::getInstance()); // Deprecated. scriptEngine->registerGlobalObject("ResourceRequestObserver", DependencyManager::get().data()); - - //scriptEngine->registerGlobalObject("ExternalResource", ExternalResource::getInstance()); - // scriptEngine->registerEnum("Script.ExternalPaths", QMetaEnum::fromType()); - registerInteractiveWindowMetaType(scriptEngine.data()); auto pickScriptingInterface = DependencyManager::get(); diff --git a/libraries/networking/src/ExternalResource.cpp b/libraries/networking/src/ExternalResource.cpp index d3aef1171b..e2b6a40682 100644 --- a/libraries/networking/src/ExternalResource.cpp +++ b/libraries/networking/src/ExternalResource.cpp @@ -4,7 +4,7 @@ // Created by Dale Glass on 6 Sep 2020 // Copyright 2020 Vircadia contributors. // -// Flexible management for external resources (eg, on S3) +// Flexible management for external resources (e.g., on S3). // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -23,25 +23,24 @@ ExternalResource* ExternalResource::getInstance() { return &instance; } -QUrl ExternalResource::getQUrl(Bucket bucket, const QUrl& relative_path) { - qCDebug(external_resource) << "Requested URL for bucket " << bucket << ", path " << relative_path; +QUrl ExternalResource::getQUrl(Bucket bucket, const QUrl& path) { + qCDebug(external_resource) << "Requested URL for bucket " << bucket << ", path " << path; if (!_bucketBases.contains(bucket)) { - qCCritical(external_resource) << "External resource " << relative_path << " was requested from unrecognized bucket " - << bucket; + qCCritical(external_resource) << "External resource " << path << " was requested from unrecognized bucket " << bucket; return QUrl(); } - if (!relative_path.isValid()) { - qCCritical(external_resource) << "External resource " << relative_path << " was requested from bucket " << bucket - << " with an invalid path. Error: " << relative_path.errorString(); + if (!path.isValid()) { + qCCritical(external_resource) << "External resource " << path << " was requested from bucket " << bucket + << " with an invalid path. Error: " << path.errorString(); return QUrl(); } - if (!relative_path.isRelative()) { - qCWarning(external_resource) << "External resource " << relative_path << " was requested from bucket " << bucket + if (!path.isRelative()) { + qCWarning(external_resource) << "External resource " << path << " was requested from bucket " << bucket << " without using a relative path, returning as-is."; - return relative_path; + return path; } QUrl base; @@ -50,13 +49,13 @@ QUrl ExternalResource::getQUrl(Bucket bucket, const QUrl& relative_path) { base = _bucketBases[bucket]; } - QUrl merged = base.resolved(relative_path).adjusted(QUrl::NormalizePathSegments); + QUrl merged = base.resolved(path).adjusted(QUrl::NormalizePathSegments); if ( merged.isValid() ) { qCDebug(external_resource) << "External resource resolved to " << merged; } else { - qCCritical(external_resource) << "External resource resolved to invalid URL " << merged << "; Error " << merged.errorString() - << "; base = " << base << "; relative_path = " << relative_path; + qCCritical(external_resource) << "External resource resolved to invalid URL " << merged << "; Error " + << merged.errorString() << "; base = " << base << "; path = " << path; } return merged; @@ -68,9 +67,9 @@ QString ExternalResource::getBase(Bucket bucket) { }; bool ExternalResource::setBase(Bucket bucket, const QString& url) { - QUrl new_url(url); + QUrl newURL(url); - if (!new_url.isValid() || new_url.isRelative()) { + if (!newURL.isValid() || newURL.isRelative()) { qCCritical(external_resource) << "Attempted to set bucket " << bucket << " to invalid URL " << url; return false; } @@ -80,9 +79,9 @@ bool ExternalResource::setBase(Bucket bucket, const QString& url) { return false; } - qCDebug(external_resource) << "Setting base URL for " << bucket << " to " << new_url; + qCDebug(external_resource) << "Setting base URL for " << bucket << " to " << newURL; std::lock_guard guard(_bucketMutex); - _bucketBases[bucket] = new_url; + _bucketBases[bucket] = newURL; return true; } diff --git a/libraries/networking/src/ExternalResource.h b/libraries/networking/src/ExternalResource.h index e80e1c8099..2c1e83da29 100644 --- a/libraries/networking/src/ExternalResource.h +++ b/libraries/networking/src/ExternalResource.h @@ -4,7 +4,7 @@ // Created by Dale Glass on 6 Sep 2020 // Copyright 2020 Vircadia contributors. // -// Flexible management for external resources (eg, on S3) +// Flexible management for external resources (e.g., on S3). // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -25,11 +25,11 @@ * * With the death of the original High Fidelity and the transition of the project to a community-managed * one, it became necessary to deal with that the various assets that used to be located under the - * highfidelity.com domain will disappear, and there won't be a fixed place for them afterwards. Data + * highfidelity.com domain, and there won't be a fixed place for them afterwards. Data * hosted by community members may not remain forever, reorganization may be necessary, people may want - * to run mirrors, and some might want to run without external internet access at all. + * to run mirrors, and some might want to run without external Internet access at all. * - * This class makes it possible to deal with this in a more flexible manner: rather than hardcoding URLs + * This class makes it possible to deal with this in a more flexible manner: rather than hard-coding URLs * all over the codebase, now it's possible to easily change where all those things are downloaded from. * * The term 'bucket' refers to the buckets used on Amazon S3, but there's no requirement for S3 or anything @@ -94,52 +94,10 @@ public: * @param relative_path The path of the resource within the bucket * @returns The resulting URL as a QUrl */ - QUrl getQUrl(Bucket bucket, const QUrl& relative_path); + QUrl getQUrl(Bucket bucket, const QUrl& path); - /** - * Returns the location of a resource as a QUrl - * - * Returns the location of the resource \p relative_path in bucket \p bucket - * - * @note The resulting path will be sanitized by condensing multiple instances of '/' to one. - * This is done for easier usage with Amazon S3 and compatible systems. - * - * @param bucket The bucket in which the resource is found - * @param relative_path The path of the resource within the bucket - * @returns The resulting URL as a QUrl - */ - QUrl getQUrl(Bucket bucket, QString path) { return getQUrl(bucket, QUrl(path)); } - - /** - * Returns the location of a resource as a QString - * - * Returns the location of the resource \p relative_path in bucket \p bucket - * - * @note The resulting path will be sanitized by condensing multiple instances of '/' to one. - * This is done for easier usage with Amazon S3 and compatible systems. - * - * @param bucket The bucket in which the resource is found - * @param relative_path The path of the resource within the bucket - * @returns The resulting URL as a QString - */ - QString getUrl(Bucket bucket, const QUrl& relative_path) { - return ExternalResource::getQUrl(bucket, relative_path).toString(); - }; - - /** - * Returns the location of a resource as a QString - * - * Returns the location of the resource \p relative_path in bucket \p bucket - * - * @note The resulting path will be sanitized by condensing multiple instances of '/' to one. - * This is done for easier usage with Amazon S3 and compatible systems. - * - * @param bucket The bucket in which the resource is found - * @param relative_path The path of the resource within the bucket - * @returns The resulting URL as a QString - */ - Q_INVOKABLE QString getUrl(Bucket bucket, const QString& relative_path) { - return ExternalResource::getQUrl(bucket, QUrl(relative_path)).toString(); + QString getUrl(Bucket bucket, const QString& path) { + return ExternalResource::getQUrl(bucket, QUrl(path)).toString(); }; /**