mirror of
https://github.com/overte-org/overte.git
synced 2025-06-22 04:40:22 +02:00
Chunked content upload - working proof-of-concept
This commit is contained in:
parent
298c5efe69
commit
bb60324335
3 changed files with 54 additions and 29 deletions
|
@ -44,7 +44,7 @@ $(document).ready(function(){
|
||||||
var fileSize = file.size;
|
var fileSize = file.size;
|
||||||
var filename = file.name;
|
var filename = file.name;
|
||||||
|
|
||||||
var CHUNK_SIZE = 16384;
|
var CHUNK_SIZE = 65536;
|
||||||
if (offset == undefined) {
|
if (offset == undefined) {
|
||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
|
@ -58,9 +58,10 @@ $(document).ready(function(){
|
||||||
var ajaxParams = {
|
var ajaxParams = {
|
||||||
url: '/content/upload',
|
url: '/content/upload',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
timeout: 30000,
|
timeout: 30000, // 30 s
|
||||||
cache: false,
|
cache: false,
|
||||||
processData: false,
|
processData: false,
|
||||||
|
contentType: false,
|
||||||
data: chunkFormData
|
data: chunkFormData
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2258,20 +2258,37 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
// check the file extension to see what kind of file this is
|
// check the file extension to see what kind of file this is
|
||||||
// to make sure we handle this filetype for a content restore
|
// to make sure we handle this filetype for a content restore
|
||||||
auto dispositionValue = QString(firstFormData.first.value("Content-Disposition"));
|
auto dispositionValue = QString(firstFormData.first.value("Content-Disposition"));
|
||||||
auto formDataFilenameRegex = QRegExp("filename=\"(.+)\"");
|
QRegExp formDataFieldsRegex(R":(name="(restore-file.*)".*filename="(.+)"):");
|
||||||
auto matchIndex = formDataFilenameRegex.indexIn(dispositionValue);
|
auto matchIndex = formDataFieldsRegex.indexIn(dispositionValue);
|
||||||
|
|
||||||
|
QString formItemName = "";
|
||||||
QString uploadedFilename = "";
|
QString uploadedFilename = "";
|
||||||
if (matchIndex != -1) {
|
if (matchIndex != -1) {
|
||||||
uploadedFilename = formDataFilenameRegex.cap(1);
|
formItemName = formDataFieldsRegex.cap(1);
|
||||||
|
uploadedFilename = formDataFieldsRegex.cap(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_pendingUploadedContent += firstFormData.second;
|
||||||
|
if (formItemName == "restore-file-chunk") {
|
||||||
|
// Received another chunk
|
||||||
|
connection->respond(HTTPConnection::StatusCode200);
|
||||||
|
} else if (formItemName == "restore-file-chunk-final") {
|
||||||
|
if (uploadedFilename.endsWith(".json", Qt::CaseInsensitive)
|
||||||
|
|| uploadedFilename.endsWith(".json.gz", Qt::CaseInsensitive)) {
|
||||||
|
// invoke our method to hand the new octree file off to the octree server
|
||||||
|
QMetaObject::invokeMethod(this, "handleOctreeFileReplacement",
|
||||||
|
Qt::QueuedConnection, Q_ARG(QByteArray, _pendingUploadedContent));
|
||||||
|
_pendingUploadedContent.clear();
|
||||||
|
// respond with a 200 for success
|
||||||
|
connection->respond(HTTPConnection::StatusCode200);
|
||||||
|
} else if (formItemName == "restore-file") {
|
||||||
if (uploadedFilename.endsWith(".json", Qt::CaseInsensitive)
|
if (uploadedFilename.endsWith(".json", Qt::CaseInsensitive)
|
||||||
|| uploadedFilename.endsWith(".json.gz", Qt::CaseInsensitive)) {
|
|| uploadedFilename.endsWith(".json.gz", Qt::CaseInsensitive)) {
|
||||||
// invoke our method to hand the new octree file off to the octree server
|
// invoke our method to hand the new octree file off to the octree server
|
||||||
QMetaObject::invokeMethod(this, "handleOctreeFileReplacement",
|
QMetaObject::invokeMethod(this, "handleOctreeFileReplacement",
|
||||||
Qt::QueuedConnection, Q_ARG(QByteArray, firstFormData.second));
|
Qt::QueuedConnection, Q_ARG(QByteArray, firstFormData.second));
|
||||||
|
|
||||||
|
_pendingUploadedContent.clear();
|
||||||
// respond with a 200 for success
|
// respond with a 200 for success
|
||||||
connection->respond(HTTPConnection::StatusCode200);
|
connection->respond(HTTPConnection::StatusCode200);
|
||||||
} else if (uploadedFilename.endsWith(".zip", Qt::CaseInsensitive)) {
|
} else if (uploadedFilename.endsWith(".zip", Qt::CaseInsensitive)) {
|
||||||
|
@ -2291,8 +2308,13 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
});
|
});
|
||||||
|
|
||||||
_contentManager->recoverFromUploadedBackup(deferred, firstFormData.second);
|
_contentManager->recoverFromUploadedBackup(deferred, firstFormData.second);
|
||||||
|
_pendingUploadedContent.clear();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
connection->respond(HTTPConnection::StatusCode400);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// we don't have handling for this filetype, send back a 400 for failure
|
// we don't have handling for this filetype, send back a 400 for failure
|
||||||
connection->respond(HTTPConnection::StatusCode400);
|
connection->respond(HTTPConnection::StatusCode400);
|
||||||
|
|
|
@ -281,6 +281,8 @@ private:
|
||||||
|
|
||||||
QHash<QUuid, QPointer<HTTPSConnection>> _pendingOAuthConnections;
|
QHash<QUuid, QPointer<HTTPSConnection>> _pendingOAuthConnections;
|
||||||
|
|
||||||
|
QByteArray _pendingUploadedContent;
|
||||||
|
|
||||||
QThread _assetClientThread;
|
QThread _assetClientThread;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue