mirror of
https://github.com/JulianGro/overte.git
synced 2025-08-16 14:52:22 +02:00
remove client side handling of extension for ATP hash URLs
This commit is contained in:
parent
19cd352a77
commit
267ed3af82
10 changed files with 57 additions and 67 deletions
|
@ -173,7 +173,7 @@ void ATPAssetMigrator::assetUploadFinished(AssetUpload *upload, const QString& h
|
|||
auto values = _pendingReplacements.values(modelURL);
|
||||
|
||||
|
||||
QString atpURL = getATPUrl(hash, upload->getExtension()).toString();
|
||||
QString atpURL = getATPUrl(hash).toString();
|
||||
|
||||
for (auto value : values) {
|
||||
// replace the modelURL in this QJsonValueRef with the hash
|
||||
|
|
|
@ -184,14 +184,14 @@ SetMappingRequest* AssetClient::createSetMappingRequest(const AssetPath& path, c
|
|||
return new SetMappingRequest(path, hash);
|
||||
}
|
||||
|
||||
AssetRequest* AssetClient::createRequest(const AssetHash& hash, const QString& extension) {
|
||||
AssetRequest* AssetClient::createRequest(const AssetHash& hash) {
|
||||
if (hash.length() != SHA256_HASH_HEX_LENGTH) {
|
||||
qCWarning(asset_client) << "Invalid hash size";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (haveAssetServer()) {
|
||||
auto request = new AssetRequest(hash, extension);
|
||||
auto request = new AssetRequest(hash);
|
||||
|
||||
// Move to the AssetClient thread in case we are not currently on that thread (which will usually be the case)
|
||||
request->moveToThread(thread());
|
||||
|
@ -227,36 +227,7 @@ AssetUpload* AssetClient::createUpload(const QByteArray& data, const QString& ex
|
|||
}
|
||||
}
|
||||
|
||||
//bool AssetClient::setAssetMapping(const QString& path, MappingOperationCallback callback) {
|
||||
// auto nodeList = DependencyManager::get<NodeList>();
|
||||
// SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer);
|
||||
//
|
||||
// if (assetServer) {
|
||||
// auto messageID = ++_currentID;
|
||||
//
|
||||
// auto payload = path.toLatin1();
|
||||
// auto payloadSize = sizeof(messageID) + payload.size();
|
||||
// auto packet = NLPacket::create(PacketType::AssetMappingOperation, payloadSize, true);
|
||||
//
|
||||
// qCDebug(asset_client) << "Requesting mapping for" << path << "from asset-server.";
|
||||
//
|
||||
// packet->writePrimitive(messageID);
|
||||
//
|
||||
// auto bytesWritten = packet->write(payload);
|
||||
// Q_ASSERT(bytesWritten == payload.size());
|
||||
//
|
||||
// nodeList->sendPacket(std::move(packet), *assetServer);
|
||||
//
|
||||
// _pendingMappingRequests[assetServer][messageID] = callback;
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
//}
|
||||
//
|
||||
|
||||
bool AssetClient::getAsset(const QString& hash, const QString& extension, DataOffset start, DataOffset end,
|
||||
bool AssetClient::getAsset(const QString& hash, DataOffset start, DataOffset end,
|
||||
ReceivedAssetCallback callback, ProgressCallback progressCallback) {
|
||||
if (hash.length() != SHA256_HASH_HEX_LENGTH) {
|
||||
qCWarning(asset_client) << "Invalid hash size";
|
||||
|
@ -270,8 +241,7 @@ bool AssetClient::getAsset(const QString& hash, const QString& extension, DataOf
|
|||
|
||||
auto messageID = ++_currentID;
|
||||
|
||||
auto payloadSize = sizeof(messageID) + SHA256_HASH_LENGTH + sizeof(uint8_t) + extension.length()
|
||||
+ sizeof(start) + sizeof(end);
|
||||
auto payloadSize = sizeof(messageID) + SHA256_HASH_LENGTH + sizeof(start) + sizeof(end);
|
||||
auto packet = NLPacket::create(PacketType::AssetGet, payloadSize, true);
|
||||
|
||||
qCDebug(asset_client) << "Requesting data from" << start << "to" << end << "of" << hash << "from asset-server.";
|
||||
|
@ -280,9 +250,6 @@ bool AssetClient::getAsset(const QString& hash, const QString& extension, DataOf
|
|||
|
||||
packet->write(QByteArray::fromHex(hash.toLatin1()));
|
||||
|
||||
packet->writePrimitive(uint8_t(extension.length()));
|
||||
packet->write(extension.toLatin1());
|
||||
|
||||
packet->writePrimitive(start);
|
||||
packet->writePrimitive(end);
|
||||
|
||||
|
@ -296,20 +263,18 @@ bool AssetClient::getAsset(const QString& hash, const QString& extension, DataOf
|
|||
return false;
|
||||
}
|
||||
|
||||
bool AssetClient::getAssetInfo(const QString& hash, const QString& extension, GetInfoCallback callback) {
|
||||
bool AssetClient::getAssetInfo(const QString& hash, GetInfoCallback callback) {
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer);
|
||||
|
||||
if (assetServer) {
|
||||
auto messageID = ++_currentID;
|
||||
|
||||
auto payloadSize = sizeof(messageID) + SHA256_HASH_LENGTH + sizeof(uint8_t) + extension.length();
|
||||
auto payloadSize = sizeof(messageID) + SHA256_HASH_LENGTH;
|
||||
auto packet = NLPacket::create(PacketType::AssetGetInfo, payloadSize, true);
|
||||
|
||||
packet->writePrimitive(messageID);
|
||||
packet->write(QByteArray::fromHex(hash.toLatin1()));
|
||||
packet->writePrimitive(uint8_t(extension.length()));
|
||||
packet->write(extension.toLatin1());
|
||||
|
||||
nodeList->sendPacket(std::move(packet), *assetServer);
|
||||
|
||||
|
@ -590,14 +555,13 @@ void AssetScriptingInterface::downloadData(QString urlString, QScriptValue callb
|
|||
auto path = urlString.right(urlString.length() - ATP_SCHEME.length());
|
||||
auto parts = path.split(".", QString::SkipEmptyParts);
|
||||
auto hash = parts.length() > 0 ? parts[0] : "";
|
||||
auto extension = parts.length() > 1 ? parts[1] : "";
|
||||
|
||||
if (hash.length() != SHA256_HASH_HEX_LENGTH) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto assetClient = DependencyManager::get<AssetClient>();
|
||||
auto assetRequest = assetClient->createRequest(hash, extension);
|
||||
auto assetRequest = assetClient->createRequest(hash);
|
||||
|
||||
if (!assetRequest) {
|
||||
return;
|
||||
|
|
|
@ -89,7 +89,7 @@ public:
|
|||
|
||||
Q_INVOKABLE GetMappingRequest* createGetMappingRequest(const AssetPath& path);
|
||||
Q_INVOKABLE SetMappingRequest* createSetMappingRequest(const AssetPath& path, const AssetHash& hash);
|
||||
Q_INVOKABLE AssetRequest* createRequest(const AssetHash& hash, const QString& extension);
|
||||
Q_INVOKABLE AssetRequest* createRequest(const AssetHash& hash);
|
||||
Q_INVOKABLE AssetUpload* createUpload(const QString& filename);
|
||||
Q_INVOKABLE AssetUpload* createUpload(const QByteArray& data, const QString& extension);
|
||||
|
||||
|
@ -112,8 +112,8 @@ private:
|
|||
bool setAssetMapping(const QString& path, const AssetHash& hash, MappingOperationCallback callback);
|
||||
bool deleteAssetMapping(const AssetHash& hash, MappingOperationCallback callback);
|
||||
|
||||
bool getAssetInfo(const QString& hash, const QString& extension, GetInfoCallback callback);
|
||||
bool getAsset(const QString& hash, const QString& extension, DataOffset start, DataOffset end,
|
||||
bool getAssetInfo(const QString& hash, GetInfoCallback callback);
|
||||
bool getAsset(const QString& hash, DataOffset start, DataOffset end,
|
||||
ReceivedAssetCallback callback, ProgressCallback progressCallback);
|
||||
bool uploadAsset(const QByteArray& data, const QString& extension, UploadResultCallback callback);
|
||||
|
||||
|
|
|
@ -20,9 +20,8 @@
|
|||
#include "NodeList.h"
|
||||
#include "ResourceCache.h"
|
||||
|
||||
AssetRequest::AssetRequest(const QString& hash, const QString& extension) :
|
||||
_hash(hash),
|
||||
_extension(extension)
|
||||
AssetRequest::AssetRequest(const QString& hash) :
|
||||
_hash(hash)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -52,7 +51,7 @@ void AssetRequest::start() {
|
|||
_state = WaitingForInfo;
|
||||
|
||||
auto assetClient = DependencyManager::get<AssetClient>();
|
||||
assetClient->getAssetInfo(_hash, _extension, [this](bool responseReceived, AssetServerError serverError, AssetInfo info) {
|
||||
assetClient->getAssetInfo(_hash, [this](bool responseReceived, AssetServerError serverError, AssetInfo info) {
|
||||
_info = info;
|
||||
|
||||
if (!responseReceived) {
|
||||
|
@ -84,7 +83,7 @@ void AssetRequest::start() {
|
|||
int start = 0, end = _info.size;
|
||||
|
||||
auto assetClient = DependencyManager::get<AssetClient>();
|
||||
assetClient->getAsset(_hash, _extension, start, end, [this, start, end](bool responseReceived, AssetServerError serverError,
|
||||
assetClient->getAsset(_hash, start, end, [this, start, end](bool responseReceived, AssetServerError serverError,
|
||||
const QByteArray& data) {
|
||||
if (!responseReceived) {
|
||||
_error = NetworkError;
|
||||
|
|
|
@ -39,14 +39,14 @@ public:
|
|||
UnknownError
|
||||
};
|
||||
|
||||
AssetRequest(const QString& hash, const QString& extension);
|
||||
AssetRequest(const QString& hash);
|
||||
|
||||
Q_INVOKABLE void start();
|
||||
|
||||
const QByteArray& getData() const { return _data; }
|
||||
const State& getState() const { return _state; }
|
||||
const Error& getError() const { return _error; }
|
||||
QUrl getUrl() const { return ::getATPUrl(_hash, _extension); }
|
||||
QUrl getUrl() const { return ::getATPUrl(_hash); }
|
||||
|
||||
signals:
|
||||
void finished(AssetRequest* thisRequest);
|
||||
|
@ -61,7 +61,6 @@ private:
|
|||
AssetInfo _info;
|
||||
uint64_t _totalReceived { 0 };
|
||||
QString _hash;
|
||||
QString _extension;
|
||||
QByteArray _data;
|
||||
int _numPendingRequests { 0 };
|
||||
};
|
||||
|
|
|
@ -20,14 +20,42 @@ AssetResourceRequest::~AssetResourceRequest() {
|
|||
}
|
||||
}
|
||||
|
||||
bool AssetResourceRequest::urlIsAssetPath() const {
|
||||
static const QString ATP_HASH_REGEX_STRING = "^atp:([A-Fa-f0-9]{64})(\\.[\\w]+)?$";
|
||||
|
||||
QRegExp hashRegex { ATP_HASH_REGEX_STRING };
|
||||
return !hashRegex.exactMatch(_url.toString());
|
||||
}
|
||||
|
||||
void AssetResourceRequest::doSend() {
|
||||
auto parts = _url.path().split(".", QString::SkipEmptyParts);
|
||||
auto hash = parts.length() > 0 ? parts[0] : "";
|
||||
auto extension = parts.length() > 1 ? parts[1] : "";
|
||||
|
||||
if (hash.length() != SHA256_HASH_HEX_LENGTH) {
|
||||
_result = InvalidURL;
|
||||
_state = Finished;
|
||||
// We'll either have a hash or an ATP path to a file (that maps to a hash)
|
||||
|
||||
if (urlIsAssetPath()) {
|
||||
// This is an ATP path, we'll need to figure out what the mapping is.
|
||||
// This may incur a roundtrip to the asset-server, or it may return immediately from the cache in AssetClient.
|
||||
|
||||
qDebug() << "Detected an asset path! URL is" << _url;
|
||||
} else {
|
||||
|
||||
qDebug() << "ATP URL was not an asset path - url is" << _url.toString();
|
||||
|
||||
// We've detected that this is a hash - simply use AssetClient to request that asset
|
||||
auto parts = _url.path().split(".", QString::SkipEmptyParts);
|
||||
auto hash = parts.length() > 0 ? parts[0] : "";
|
||||
auto extension = parts.length() > 1 ? parts[1] : "";
|
||||
|
||||
// in case we haven't parsed a valid hash, return an error now
|
||||
if (hash.length() != SHA256_HASH_HEX_LENGTH) {
|
||||
_result = InvalidURL;
|
||||
_state = Finished;
|
||||
|
||||
emit finished();
|
||||
return;
|
||||
}
|
||||
|
||||
emit finished();
|
||||
return;
|
||||
|
@ -35,7 +63,7 @@ void AssetResourceRequest::doSend() {
|
|||
|
||||
// Make request to atp
|
||||
auto assetClient = DependencyManager::get<AssetClient>();
|
||||
_assetRequest = assetClient->createRequest(hash, extension);
|
||||
_assetRequest = assetClient->createRequest(hash);
|
||||
|
||||
if (!_assetRequest) {
|
||||
_result = ServerUnavailable;
|
||||
|
|
|
@ -103,7 +103,7 @@ void AssetUpload::start() {
|
|||
}
|
||||
|
||||
if (_error == NoError && hash == hashData(_data).toHex()) {
|
||||
saveToCache(getATPUrl(hash, _extension), _data);
|
||||
saveToCache(getATPUrl(hash), _data);
|
||||
}
|
||||
|
||||
emit finished(this, hash);
|
||||
|
|
|
@ -19,12 +19,8 @@
|
|||
|
||||
#include "ResourceManager.h"
|
||||
|
||||
QUrl getATPUrl(const QString& hash, const QString& extension) {
|
||||
if (!extension.isEmpty()) {
|
||||
return QUrl(QString("%1:%2.%3").arg(URL_SCHEME_ATP, hash, extension));
|
||||
} else {
|
||||
return QUrl(QString("%1:%2").arg(URL_SCHEME_ATP, hash));
|
||||
}
|
||||
QUrl getATPUrl(const QString& hash) {
|
||||
return QUrl(QString("%1:%2").arg(URL_SCHEME_ATP, hash));
|
||||
}
|
||||
|
||||
QByteArray hashData(const QByteArray& data) {
|
||||
|
|
|
@ -41,7 +41,7 @@ enum AssetMappingOperationType : uint8_t {
|
|||
Delete
|
||||
};
|
||||
|
||||
QUrl getATPUrl(const QString& hash, const QString& extension = QString());
|
||||
QUrl getATPUrl(const QString& hash);
|
||||
|
||||
QByteArray hashData(const QByteArray& data);
|
||||
|
||||
|
|
|
@ -53,6 +53,10 @@ PacketVersion versionForPacketType(PacketType packetType) {
|
|||
return static_cast<PacketVersion>(AvatarMixerPacketVersion::SoftAttachmentSupport);
|
||||
case PacketType::ICEServerHeartbeat:
|
||||
return 18; // ICE Server Heartbeat signing
|
||||
case PacketType::AssetGetInfo:
|
||||
case PacketType::AssetGet:
|
||||
// Introduction of ATP Mappings
|
||||
return 18;
|
||||
default:
|
||||
return 17;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue