mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-15 16:19:17 +02:00
Merge pull request #12173 from sethalves/atp-get-mapping
expose GetMappingRequest to js
This commit is contained in:
commit
9b7520ddba
2 changed files with 43 additions and 2 deletions
|
@ -16,9 +16,11 @@
|
||||||
#include <AssetRequest.h>
|
#include <AssetRequest.h>
|
||||||
#include <AssetUpload.h>
|
#include <AssetUpload.h>
|
||||||
#include <MappingRequest.h>
|
#include <MappingRequest.h>
|
||||||
#include <NetworkLogging.h>
|
|
||||||
#include <NodeList.h>
|
#include <NodeList.h>
|
||||||
|
|
||||||
|
#include "ScriptEngineLogging.h"
|
||||||
|
|
||||||
|
|
||||||
AssetScriptingInterface::AssetScriptingInterface(QScriptEngine* engine) :
|
AssetScriptingInterface::AssetScriptingInterface(QScriptEngine* engine) :
|
||||||
_engine(engine)
|
_engine(engine)
|
||||||
{
|
{
|
||||||
|
@ -53,10 +55,32 @@ void AssetScriptingInterface::setMapping(QString path, QString hash, QScriptValu
|
||||||
setMappingRequest->start();
|
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 { "", true };
|
||||||
|
callback.call(_engine->currentContext()->thisObject(), args);
|
||||||
|
} else if (result == GetMappingRequest::NoError) {
|
||||||
|
QScriptValueList args { request->getHash(), true };
|
||||||
|
callback.call(_engine->currentContext()->thisObject(), args);
|
||||||
|
} else {
|
||||||
|
qCDebug(scriptengine) << "error -- " << request->getError() << " -- " << request->getErrorString();
|
||||||
|
QScriptValueList args { "", false };
|
||||||
|
callback.call(_engine->currentContext()->thisObject(), args);
|
||||||
|
}
|
||||||
|
request->deleteLater();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
request->start();
|
||||||
|
}
|
||||||
|
|
||||||
void AssetScriptingInterface::downloadData(QString urlString, QScriptValue callback) {
|
void AssetScriptingInterface::downloadData(QString urlString, QScriptValue callback) {
|
||||||
|
|
||||||
if (!urlString.startsWith(ATP_SCHEME)) {
|
if (!urlString.startsWith(ATP_SCHEME)) {
|
||||||
|
qCDebug(scriptengine) << "AssetScriptingInterface::downloadData url must be of form atp:<hash-value>";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,23 @@ public:
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE void setMapping(QString path, QString hash, QScriptValue callback);
|
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 assetID {string} hash value if found, else an empty string
|
||||||
|
* @param success {boolean} false for errors other than "not found", else true
|
||||||
|
*/
|
||||||
|
Q_INVOKABLE void getMapping(QString path, QScriptValue callback);
|
||||||
|
|
||||||
|
|
||||||
Q_INVOKABLE void setBakingEnabled(QString path, bool enabled, QScriptValue callback);
|
Q_INVOKABLE void setBakingEnabled(QString path, bool enabled, QScriptValue callback);
|
||||||
|
|
||||||
#if (PR_BUILD || DEV_BUILD)
|
#if (PR_BUILD || DEV_BUILD)
|
||||||
|
|
Loading…
Reference in a new issue