Showing the changes to libraries/script-engine/src/AssetScriptingInterface.cpp (1 of 2 files). Show all
Unified · Split
| @@ -16,9 +16,11 @@ · 15 unmodified lines | ||
| 16 | 16 | #include <AssetRequest.h> |
| 17 | 17 | #include <AssetUpload.h> |
| 18 | 18 | #include <MappingRequest.h> |
| 19 | −#include <NetworkLogging.h> | |
| 20 | 19 | #include <NodeList.h> |
| 21 | 20 | |
| 21 | +#include "ScriptEngineLogging.h" | |
| 22 | + | |
| 23 | + | |
| 22 | 24 | AssetScriptingInterface::AssetScriptingInterface(QScriptEngine* engine) : |
| 23 | 25 | _engine(engine) |
| 24 | 26 | { |
| @@ -53,10 +55,30 @@ void AssetScriptingInterface::setMapping(QString path, QString hash, QScriptValu · 28 unmodified lines | ||
| 53 | 55 | setMappingRequest->start(); |
| 54 | 56 | } |
| 55 | 57 | |
| 58 | +void AssetScriptingInterface::getMapping(QString path, QScriptValue callback) { | |
| 59 | + auto request = DependencyManager::get<AssetClient>()->createGetMappingRequest(path); | |
| 60 | + QObject::connect(request, &GetMappingRequest::finished, this, [=](GetMappingRequest* request) mutable { | |
| 61 | + auto result = request->getError(); | |
| 62 | + if (callback.isFunction()) { | |
| 63 | + if (result == GetMappingRequest::NotFound) { | |
| 64 | + QScriptValueList args { "" }; | |
| 65 | + callback.call(_engine->currentContext()->thisObject(), args); | |
| 66 | + } else if (result == GetMappingRequest::NoError) { | |
| 67 | + QScriptValueList args { request->getHash() }; | |
| 68 | + callback.call(_engine->currentContext()->thisObject(), args); | |
| 69 | + } else { | |
| 70 | + qCDebug(scriptengine) << "error -- " << request->getError() << " -- " << request->getErrorString(); | |
| 71 | + } | |
| 72 | + request->deleteLater(); | |
| 73 | + } | |
| 74 | + }); | |
| 75 | + request->start(); | |
| 76 | +} | |
| 56 | 77 | |
| 57 | 78 | void AssetScriptingInterface::downloadData(QString urlString, QScriptValue callback) { |
| 58 | 79 | |
| 59 | 80 | if (!urlString.startsWith(ATP_SCHEME)) { |
| 81 | + qCDebug(scriptengine) << "AssetScriptingInterface::downloadData url must be of form atp:<hash-value>"; | |
| 60 | 82 | return; |
| 61 | 83 | } |
| 62 | 84 | |