mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-14 13:36:29 +02:00
remove extension from asset upload task
This commit is contained in:
parent
7cc774c5f4
commit
1ece9aac26
7 changed files with 20 additions and 35 deletions
|
@ -37,15 +37,10 @@ void UploadAssetTask::run() {
|
|||
MessageID messageID;
|
||||
buffer.read(reinterpret_cast<char*>(&messageID), sizeof(messageID));
|
||||
|
||||
uint8_t extensionLength;
|
||||
buffer.read(reinterpret_cast<char*>(&extensionLength), sizeof(extensionLength));
|
||||
|
||||
QByteArray extension = buffer.read(extensionLength);
|
||||
|
||||
uint64_t fileSize;
|
||||
buffer.read(reinterpret_cast<char*>(&fileSize), sizeof(fileSize));
|
||||
|
||||
qDebug() << "UploadAssetTask reading a file of " << fileSize << "bytes and extension" << extension << "from"
|
||||
qDebug() << "UploadAssetTask reading a file of " << fileSize << "bytes from"
|
||||
<< uuidStringWithoutCurlyBraces(_senderNode->getUUID());
|
||||
|
||||
auto replyPacket = NLPacket::create(PacketType::AssetUploadReply);
|
||||
|
@ -62,7 +57,7 @@ void UploadAssetTask::run() {
|
|||
qDebug() << "Hash for uploaded file from" << uuidStringWithoutCurlyBraces(_senderNode->getUUID())
|
||||
<< "is: (" << hexHash << ") ";
|
||||
|
||||
QFile file { _resourcesDir.filePath(QString(hexHash)) + "." + QString(extension) };
|
||||
QFile file { _resourcesDir.filePath(QString(hexHash)) };
|
||||
|
||||
if (file.exists()) {
|
||||
qDebug() << "[WARNING] This file already exists: " << hexHash;
|
||||
|
|
|
@ -328,9 +328,9 @@ AssetUpload* AssetClient::createUpload(const QString& filename) {
|
|||
}
|
||||
}
|
||||
|
||||
AssetUpload* AssetClient::createUpload(const QByteArray& data, const QString& extension) {
|
||||
AssetUpload* AssetClient::createUpload(const QByteArray& data) {
|
||||
if (haveAssetServer()) {
|
||||
auto upload = new AssetUpload(data, extension);
|
||||
auto upload = new AssetUpload(data);
|
||||
|
||||
upload->moveToThread(thread());
|
||||
|
||||
|
@ -579,7 +579,7 @@ bool AssetClient::setAssetMapping(const QString& path, const AssetHash& hash, Ma
|
|||
return false;
|
||||
}
|
||||
|
||||
bool AssetClient::uploadAsset(const QByteArray& data, const QString& extension, UploadResultCallback callback) {
|
||||
bool AssetClient::uploadAsset(const QByteArray& data, UploadResultCallback callback) {
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer);
|
||||
|
||||
|
@ -589,9 +589,6 @@ bool AssetClient::uploadAsset(const QByteArray& data, const QString& extension,
|
|||
auto messageID = ++_currentID;
|
||||
packetList->writePrimitive(messageID);
|
||||
|
||||
packetList->writePrimitive(static_cast<uint8_t>(extension.length()));
|
||||
packetList->write(extension.toLatin1().constData(), extension.length());
|
||||
|
||||
uint64_t size = data.length();
|
||||
packetList->writePrimitive(size);
|
||||
packetList->write(data.constData(), size);
|
||||
|
@ -692,17 +689,17 @@ void AssetClient::handleNodeKilled(SharedNodePointer node) {
|
|||
_mappingCache.clear();
|
||||
}
|
||||
|
||||
void AssetScriptingInterface::uploadData(QString data, QString extension, QScriptValue callback) {
|
||||
void AssetScriptingInterface::uploadData(QString data, QScriptValue callback) {
|
||||
QByteArray dataByteArray = data.toUtf8();
|
||||
auto upload = DependencyManager::get<AssetClient>()->createUpload(dataByteArray, extension);
|
||||
auto upload = DependencyManager::get<AssetClient>()->createUpload(dataByteArray);
|
||||
if (!upload) {
|
||||
qCWarning(asset_client) << "Error uploading file to asset server";
|
||||
return;
|
||||
}
|
||||
|
||||
QObject::connect(upload, &AssetUpload::finished, this, [this, callback, extension](AssetUpload* upload, const QString& hash) mutable {
|
||||
QObject::connect(upload, &AssetUpload::finished, this, [this, callback](AssetUpload* upload, const QString& hash) mutable {
|
||||
if (callback.isFunction()) {
|
||||
QString url = "atp://" + hash + "." + extension;
|
||||
QString url = "atp://" + hash;
|
||||
QScriptValueList args { url };
|
||||
callback.call(_engine->currentContext()->thisObject(), args);
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ public:
|
|||
Q_INVOKABLE SetMappingRequest* createSetMappingRequest(const AssetPath& path, const AssetHash& hash);
|
||||
Q_INVOKABLE AssetRequest* createRequest(const AssetHash& hash);
|
||||
Q_INVOKABLE AssetUpload* createUpload(const QString& filename);
|
||||
Q_INVOKABLE AssetUpload* createUpload(const QByteArray& data, const QString& extension);
|
||||
Q_INVOKABLE AssetUpload* createUpload(const QByteArray& data);
|
||||
|
||||
public slots:
|
||||
void init();
|
||||
|
@ -165,7 +165,7 @@ private:
|
|||
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);
|
||||
bool uploadAsset(const QByteArray& data, UploadResultCallback callback);
|
||||
|
||||
struct GetAssetCallbacks {
|
||||
ReceivedAssetCallback completeCallback;
|
||||
|
@ -194,7 +194,7 @@ class AssetScriptingInterface : public QObject {
|
|||
public:
|
||||
AssetScriptingInterface(QScriptEngine* engine);
|
||||
|
||||
Q_INVOKABLE void uploadData(QString data, QString extension, QScriptValue callback);
|
||||
Q_INVOKABLE void uploadData(QString data, QScriptValue callback);
|
||||
Q_INVOKABLE void downloadData(QString url, QScriptValue downloadComplete);
|
||||
Q_INVOKABLE void setMapping(QString path, QString hash, QScriptValue callback);
|
||||
Q_INVOKABLE void getMapping(QString path, QScriptValue callback);
|
||||
|
|
|
@ -19,9 +19,8 @@
|
|||
|
||||
const QString AssetUpload::PERMISSION_DENIED_ERROR = "You do not have permission to upload content to this asset-server.";
|
||||
|
||||
AssetUpload::AssetUpload(const QByteArray& data, const QString& extension) :
|
||||
_data(data),
|
||||
_extension(extension)
|
||||
AssetUpload::AssetUpload(const QByteArray& data) :
|
||||
_data(data)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -59,12 +58,7 @@ void AssetUpload::start() {
|
|||
// try to open the file at the given filename
|
||||
QFile file { _filename };
|
||||
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
|
||||
// file opened, read the data and grab the extension
|
||||
_extension = QFileInfo(_filename).suffix();
|
||||
_extension = _extension.toLower();
|
||||
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
_data = file.readAll();
|
||||
} else {
|
||||
// we couldn't open the file - set the error result
|
||||
|
@ -82,7 +76,7 @@ void AssetUpload::start() {
|
|||
qCDebug(asset_client) << "Attempting to upload" << _filename << "to asset-server.";
|
||||
}
|
||||
|
||||
assetClient->uploadAsset(_data, _extension, [this](bool responseReceived, AssetServerError error, const QString& hash){
|
||||
assetClient->uploadAsset(_data, [this](bool responseReceived, AssetServerError error, const QString& hash){
|
||||
if (!responseReceived) {
|
||||
_error = NetworkError;
|
||||
} else {
|
||||
|
|
|
@ -38,12 +38,11 @@ public:
|
|||
static const QString PERMISSION_DENIED_ERROR;
|
||||
|
||||
AssetUpload(const QString& filename);
|
||||
AssetUpload(const QByteArray& data, const QString& extension);
|
||||
AssetUpload(const QByteArray& data);
|
||||
|
||||
Q_INVOKABLE void start();
|
||||
|
||||
const QString& getFilename() const { return _filename; }
|
||||
const QString& getExtension() const { return _extension; }
|
||||
const Error& getError() const { return _error; }
|
||||
QString getErrorString() const;
|
||||
|
||||
|
@ -54,7 +53,6 @@ signals:
|
|||
private:
|
||||
QString _filename;
|
||||
QByteArray _data;
|
||||
QString _extension;
|
||||
Error _error;
|
||||
};
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ PacketVersion versionForPacketType(PacketType packetType) {
|
|||
return 18; // ICE Server Heartbeat signing
|
||||
case PacketType::AssetGetInfo:
|
||||
case PacketType::AssetGet:
|
||||
case PacketType::AssetUpload:
|
||||
// Removal of extension from Asset requests
|
||||
return 18;
|
||||
default:
|
||||
|
|
|
@ -198,13 +198,13 @@ bool RecordingScriptingInterface::saveRecordingToAsset(QScriptValue getClipAtpUr
|
|||
return false;
|
||||
}
|
||||
|
||||
if (auto upload = DependencyManager::get<AssetClient>()->createUpload(recording::Clip::toBuffer(_lastClip), HFR_EXTENSION)) {
|
||||
if (auto upload = DependencyManager::get<AssetClient>()->createUpload(recording::Clip::toBuffer(_lastClip))) {
|
||||
QObject::connect(upload, &AssetUpload::finished, this, [=](AssetUpload* upload, const QString& hash) mutable {
|
||||
QString clip_atp_url = "";
|
||||
|
||||
if (upload->getError() == AssetUpload::NoError) {
|
||||
|
||||
clip_atp_url = QString("%1:%2.%3").arg(URL_SCHEME_ATP, hash, upload->getExtension());
|
||||
clip_atp_url = QString("%1:%2").arg(URL_SCHEME_ATP, hash);
|
||||
upload->deleteLater();
|
||||
} else {
|
||||
qCWarning(scriptengine) << "Error during the Asset upload.";
|
||||
|
|
Loading…
Reference in a new issue