Merge pull request #19 from druiz17/serverless-domains

allow json to use /~/ for file paths
This commit is contained in:
Seth Alves 2018-02-20 16:28:50 -08:00 committed by GitHub
commit b58530fc57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 9 deletions

View file

@ -310,9 +310,7 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl, LookupTrigger trigger) {
} else if (lookupUrl.scheme() == "http" || lookupUrl.scheme() == "https" || lookupUrl.scheme() == "file") {
qDebug() << "QQQQ file or http before serverless domain" << lookupUrl.toString();
_previousLookup.clear();
QUrl domainUrl = lookupUrl;
const QString path = PathUtils::expandToAppAbsolutePath(lookupUrl.path());
domainUrl.setPath(path);
QUrl domainUrl = PathUtils::expandToAppAbsolutePath(lookupUrl);
emit setServersEnabled(false);
setDomainInfo(domainUrl, QString(), 0, trigger);
DependencyManager::get<NodeList>()->getDomainHandler().setIsConnected(true);

View file

@ -17,6 +17,7 @@
#include <StatTracker.h>
#include <shared/FileUtils.h>
#include <pathUtils.h>
#include "ResourceManager.h"
@ -28,7 +29,7 @@ void FileResourceRequest::doSend() {
if (_url.scheme() == URL_SCHEME_QRC) {
filename = ":/" + _url.path();
} else {
filename = _url.toLocalFile();
filename = PathUtils::expandToAppAbsolutePath(_url).toLocalFile();
// sometimes on windows, we see the toLocalFile() return null,
// in this case we will attempt to simply use the url as a string
if (filename.isEmpty()) {

View file

@ -133,12 +133,16 @@ QUrl PathUtils::resourcesUrl(const QString& relativeUrl) {
return QUrl(resourcesUrl() + relativeUrl);
}
QString PathUtils::expandToAppAbsolutePath(const QString& filePath) {
QString path = filePath;
QUrl PathUtils::expandToAppAbsolutePath(const QUrl& fileUrl) {
QUrl url = fileUrl;
QString path = fileUrl.path();
if (path.startsWith("/~/")) {
path.replace(1, 2, applicationAbsolutePath());
QString absolutePath = applicationAbsolutePath();
path.replace(0, 3, absolutePath);
url = QUrl("file:///" + path);
qDebug() << "QQQ expanded URL " << url;
}
return path;
return url;
}
const QString& PathUtils::qmlBaseUrl() {
static const QString staticResourcePath = resourcesUrl() + "qml/";

View file

@ -37,7 +37,7 @@ public:
static QUrl resourcesUrl(const QString& relative);
static const QString& resourcesPath();
static const QString& qmlBaseUrl();
static QString expandToAppAbsolutePath(const QString& filePath);
static QUrl expandToAppAbsolutePath(const QUrl& fileUrl);
static QUrl qmlUrl(const QString& relative);
#ifdef DEV_BUILD
static const QString& projectRootPath();