export atp GetMappingRequest to js

This commit is contained in:
Seth Alves 2018-01-15 09:18:22 -08:00
parent 0a54241fe3
commit 3e7d303661
2 changed files with 40 additions and 2 deletions

View file

@ -16,9 +16,11 @@
#include <AssetRequest.h>
#include <AssetUpload.h>
#include <MappingRequest.h>
#include <NetworkLogging.h>
#include <NodeList.h>
#include "ScriptEngineLogging.h"
AssetScriptingInterface::AssetScriptingInterface(QScriptEngine* engine) :
_engine(engine)
{
@ -53,10 +55,30 @@ void AssetScriptingInterface::setMapping(QString path, QString hash, QScriptValu
setMappingRequest->start();
}
void AssetScriptingInterface::getMapping(QString path, QScriptValue callback) {
auto request = DependencyManager::get<AssetClient>()->createGetMappingRequest(path);
QObject::connect(request, &GetMappingRequest::finished, this, [=](GetMappingRequest* request) mutable {
auto result = request->getError();
if (callback.isFunction()) {
if (result == GetMappingRequest::NotFound) {
QScriptValueList args { "" };
callback.call(_engine->currentContext()->thisObject(), args);
} else if (result == GetMappingRequest::NoError) {
QScriptValueList args { request->getHash() };
callback.call(_engine->currentContext()->thisObject(), args);
} else {
qCDebug(scriptengine) << "error -- " << request->getError() << " -- " << request->getErrorString();
}
request->deleteLater();
}
});
request->start();
}
void AssetScriptingInterface::downloadData(QString urlString, QScriptValue callback) {
if (!urlString.startsWith(ATP_SCHEME)) {
qCDebug(scriptengine) << "AssetScriptingInterface::downloadData url must be of form atp:<hash-value>";
return;
}

View file

@ -75,7 +75,23 @@ public:
* @param {string} error
*/
Q_INVOKABLE void setMapping(QString path, QString hash, QScriptValue callback);
/**jsdoc
* Look up a path to hash mapping within the connected domain's asset server
* @function Assets.getMapping
* @static
* @param path {string}
* @param callback {Assets~getMappingCallback}
*/
/**jsdoc
* Called when getMapping is complete
* @callback Assets~getMappingCallback
* @param {string} assetID
*/
Q_INVOKABLE void getMapping(QString path, QScriptValue callback);
Q_INVOKABLE void setBakingEnabled(QString path, bool enabled, QScriptValue callback);
#if (PR_BUILD || DEV_BUILD)