mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-25 11:51:06 +02:00
handle entity file upload from new content upload
This commit is contained in:
parent
2d9f2ebf81
commit
b019895fce
4 changed files with 111 additions and 32 deletions
|
@ -7,17 +7,67 @@ $(document).ready(function(){
|
||||||
// construct the HTML needed for the settings backup panel
|
// construct the HTML needed for the settings backup panel
|
||||||
var html = "<div class='form-group'>";
|
var html = "<div class='form-group'>";
|
||||||
|
|
||||||
html += "<span class='help-block'>Upload a Content Backup to replace the content of this domain";
|
html += "<span class='help-block'>Upload a Content Archive (.zip) or entity file (.json, .json.gz) to replace the content of this domain.";
|
||||||
html += "<br/>Note: Your domain's content will be replaced by the content you upload, but the existing backup files of your domain's content will not immediately be changed.</span>";
|
html += "<br/>Note: Your domain content will be replaced by the content you upload, but the existing backup files of your domain's content will not immediately be changed.</span>";
|
||||||
|
|
||||||
html += "<input id='restore-settings-file' name='restore-settings' type='file'>";
|
html += "<input id='restore-settings-file' name='restore-settings' type='file'>";
|
||||||
html += "<button type='button' id='" + RESTORE_SETTINGS_UPLOAD_ID + "' disabled='true' class='btn btn-primary'>Upload Domain Settings</button>";
|
html += "<button type='button' id='" + RESTORE_SETTINGS_UPLOAD_ID + "' disabled='true' class='btn btn-primary'>Upload Content</button>";
|
||||||
|
|
||||||
html += "</div>";
|
html += "</div>";
|
||||||
|
|
||||||
$('#' + Settings.UPLOAD_CONTENT_BACKUP_PANEL_ID + ' .panel-body').html(html);
|
$('#' + Settings.UPLOAD_CONTENT_BACKUP_PANEL_ID + ' .panel-body').html(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle content archive or entity file upload
|
||||||
|
|
||||||
|
// when the selected file is changed, enable the button if there's a selected file
|
||||||
|
$('body').on('change', '#' + RESTORE_SETTINGS_FILE_ID, function() {
|
||||||
|
if ($(this).val()) {
|
||||||
|
$('#' + RESTORE_SETTINGS_UPLOAD_ID).attr('disabled', false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// when the upload button is clicked, send the file to the DS
|
||||||
|
// and reload the page if restore was successful or
|
||||||
|
// show an error if not
|
||||||
|
$('body').on('click', '#' + RESTORE_SETTINGS_UPLOAD_ID, function(e){
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
swal({
|
||||||
|
title: "Are you sure?",
|
||||||
|
text: "Your domain content will be replaced by the uploaded Content Archive or entity file",
|
||||||
|
type: "warning",
|
||||||
|
showCancelButton: true,
|
||||||
|
closeOnConfirm: false
|
||||||
|
},
|
||||||
|
function () {
|
||||||
|
var files = $('#' + RESTORE_SETTINGS_FILE_ID).prop('files');
|
||||||
|
|
||||||
|
var fileFormData = new FormData();
|
||||||
|
fileFormData.append('restore-file', files[0]);
|
||||||
|
|
||||||
|
showSpinnerAlert("Restoring Content");
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/content/upload',
|
||||||
|
type: 'POST',
|
||||||
|
cache: false,
|
||||||
|
processData: false,
|
||||||
|
contentType: false,
|
||||||
|
data: fileFormData
|
||||||
|
}).done(function(data, textStatus, jqXHR) {
|
||||||
|
swal.close();
|
||||||
|
showRestartModal();
|
||||||
|
}).fail(function(jqXHR, textStatus, errorThrown) {
|
||||||
|
showErrorMessage(
|
||||||
|
"Error",
|
||||||
|
"There was a problem restoring domain content.\n"
|
||||||
|
+ "Please ensure that the content archive or entity file is valid and try again."
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
var GENERATE_ARCHIVE_BUTTON_ID = 'generate-archive-button';
|
var GENERATE_ARCHIVE_BUTTON_ID = 'generate-archive-button';
|
||||||
var AUTOMATIC_ARCHIVES_TABLE_ID = 'automatic-archives-table';
|
var AUTOMATIC_ARCHIVES_TABLE_ID = 'automatic-archives-table';
|
||||||
var AUTOMATIC_ARCHIVES_TBODY_ID = 'automatic-archives-tbody';
|
var AUTOMATIC_ARCHIVES_TBODY_ID = 'automatic-archives-tbody';
|
||||||
|
@ -136,7 +186,7 @@ $(document).ready(function(){
|
||||||
text: "You have pending changes to content settings that have not been saved. They will be lost if you leave the page to manage automatic content archive intervals.",
|
text: "You have pending changes to content settings that have not been saved. They will be lost if you leave the page to manage automatic content archive intervals.",
|
||||||
type: "warning",
|
type: "warning",
|
||||||
showCancelButton: true,
|
showCancelButton: true,
|
||||||
confirmButtonText: "Leave and Lose Pending Changes",
|
confirmButtonText: "Proceed without Saving",
|
||||||
closeOnConfirm: true
|
closeOnConfirm: true
|
||||||
},
|
},
|
||||||
function () {
|
function () {
|
||||||
|
|
|
@ -79,7 +79,7 @@ $(document).ready(function(){
|
||||||
Settings.extraDomainGroupsAtEnd = [
|
Settings.extraDomainGroupsAtEnd = [
|
||||||
{
|
{
|
||||||
html_id: 'settings_backup',
|
html_id: 'settings_backup',
|
||||||
label: 'Settings Backup'
|
label: 'Settings Backup / Restore'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -1033,6 +1033,14 @@ $(document).ready(function(){
|
||||||
$('body').on('click', '#' + RESTORE_SETTINGS_UPLOAD_ID, function(e){
|
$('body').on('click', '#' + RESTORE_SETTINGS_UPLOAD_ID, function(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
swal({
|
||||||
|
title: "Are you sure?",
|
||||||
|
text: "Your domain settings will be replaced by the uploaded settings",
|
||||||
|
type: "warning",
|
||||||
|
showCancelButton: true,
|
||||||
|
closeOnConfirm: false
|
||||||
|
},
|
||||||
|
function() {
|
||||||
var files = $('#' + RESTORE_SETTINGS_FILE_ID).prop('files');
|
var files = $('#' + RESTORE_SETTINGS_FILE_ID).prop('files');
|
||||||
|
|
||||||
var fileFormData = new FormData();
|
var fileFormData = new FormData();
|
||||||
|
@ -1060,6 +1068,7 @@ $(document).ready(function(){
|
||||||
reloadSettings();
|
reloadSettings();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
$('body').on('change', '#' + RESTORE_SETTINGS_FILE_ID, function() {
|
$('body').on('change', '#' + RESTORE_SETTINGS_FILE_ID, function() {
|
||||||
if ($(this).val()) {
|
if ($(this).val()) {
|
||||||
|
@ -1079,7 +1088,7 @@ $(document).ready(function(){
|
||||||
html += "<div class='form-group'>";
|
html += "<div class='form-group'>";
|
||||||
html += "<label class='control-label'>Upload a Settings Configuration</label>";
|
html += "<label class='control-label'>Upload a Settings Configuration</label>";
|
||||||
html += "<span class='help-block'>Upload a settings configuration to quickly configure this domain";
|
html += "<span class='help-block'>Upload a settings configuration to quickly configure this domain";
|
||||||
html += "<br/>Note: Your domain's settings will be replaced by the settings you upload</span>";
|
html += "<br/>Note: Your domain settings will be replaced by the settings you upload</span>";
|
||||||
|
|
||||||
html += "<input id='restore-settings-file' name='restore-settings' type='file'>";
|
html += "<input id='restore-settings-file' name='restore-settings' type='file'>";
|
||||||
html += "<button type='button' id='" + RESTORE_SETTINGS_UPLOAD_ID + "' disabled='true' class='btn btn-primary'>Upload Domain Settings</button>";
|
html += "<button type='button' id='" + RESTORE_SETTINGS_UPLOAD_ID + "' disabled='true' class='btn btn-primary'>Upload Domain Settings</button>";
|
||||||
|
|
|
@ -2256,12 +2256,32 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
QList<FormData> formData = connection->parseFormData();
|
QList<FormData> formData = connection->parseFormData();
|
||||||
|
|
||||||
if (formData.size() > 0 && formData[0].second.size() > 0) {
|
if (formData.size() > 0 && formData[0].second.size() > 0) {
|
||||||
|
auto& firstFormData = formData[0];
|
||||||
|
|
||||||
|
// check the file extension to see what kind of file this is
|
||||||
|
// to match sure we handle this filetype for a content restore
|
||||||
|
auto dispositionValue = QString(firstFormData.first.value("Content-Disposition"));
|
||||||
|
auto formDataFilenameRegex = QRegExp("filename=\"(\\S+)\"");
|
||||||
|
auto matchIndex = formDataFilenameRegex.indexIn(dispositionValue);
|
||||||
|
|
||||||
|
QString uploadedFilename = "";
|
||||||
|
if (matchIndex != -1) {
|
||||||
|
uploadedFilename = formDataFilenameRegex.cap(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
// 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, formData[0].second));
|
Qt::QueuedConnection, Q_ARG(QByteArray, formData[0].second));
|
||||||
|
|
||||||
// respond with a 200 for success
|
// respond with a 200 for success
|
||||||
connection->respond(HTTPConnection::StatusCode200);
|
connection->respond(HTTPConnection::StatusCode200);
|
||||||
|
} else {
|
||||||
|
// we don't have handling for this filetype, send back a 400 for failure
|
||||||
|
connection->respond(HTTPConnection::StatusCode400);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// respond with a 400 for failure
|
// respond with a 400 for failure
|
||||||
connection->respond(HTTPConnection::StatusCode400);
|
connection->respond(HTTPConnection::StatusCode400);
|
||||||
|
|
Loading…
Reference in a new issue