History

Merge branch 'master' into Leopoly_Phase1_003_Asset-Request

humbletim committed 8 years ago

Commit 49bb9422 parents 0953476 8f22c71503 files · +12274 −6090Browse files

Showing the changes to libraries/script-engine/src/AssetScriptingInterface.cpp (1 of 503 files). Show all

Unified · Split

libraries/script-engine/src/AssetScriptingInterface.cpp+21−1
@@ -19,7 +19,6 @@ · 18 unmodified lines
19#include <AssetUpload.h>19#include <AssetUpload.h>
20#include <AssetUtils.h>20#include <AssetUtils.h>
21#include <MappingRequest.h>21#include <MappingRequest.h>
22#include <NetworkLogging.h>
23#include <NodeList.h>22#include <NodeList.h>
24 23
25#include <RegisteredMetaTypes.h>24#include <RegisteredMetaTypes.h>
@@ -79,6 +78,27 @@ void AssetScriptingInterface::setMapping(QString path, QString hash, QScriptValu · 53 unmodified lines
79 setMappingRequest->start();78 setMappingRequest->start();
80}79}
81 80
81void AssetScriptingInterface::getMapping(QString path, QScriptValue callback) {
82 auto request = DependencyManager::get<AssetClient>()->createGetMappingRequest(path);
83 QObject::connect(request, &GetMappingRequest::finished, this, [=](GetMappingRequest* request) mutable {
84 auto result = request->getError();
85 if (callback.isFunction()) {
86 if (result == GetMappingRequest::NotFound) {
87 QScriptValueList args { "", true };
88 callback.call(_engine->currentContext()->thisObject(), args);
89 } else if (result == GetMappingRequest::NoError) {
90 QScriptValueList args { request->getHash(), true };
91 callback.call(_engine->currentContext()->thisObject(), args);
92 } else {
93 qCDebug(scriptengine) << "error -- " << request->getError() << " -- " << request->getErrorString();
94 QScriptValueList args { "", false };
95 callback.call(_engine->currentContext()->thisObject(), args);
96 }
97 request->deleteLater();
98 }
99 });
100 request->start();
101}
82 102
83void AssetScriptingInterface::downloadData(QString urlString, QScriptValue callback) {103void AssetScriptingInterface::downloadData(QString urlString, QScriptValue callback) {
84 // FIXME: historically this API method failed silently when given a non-atp prefixed104 // FIXME: historically this API method failed silently when given a non-atp prefixed