refactor some cloud project saving. Fix #2169

pull/89/head
Michael Ball 2019-01-24 02:03:10 -08:00
rodzic 1fdded7fe5
commit a044553767
2 zmienionych plików z 17 dodań i 19 usunięć

Wyświetl plik

@ -376,7 +376,6 @@ Cloud.prototype.changePassword = function (
onError, onError,
'Could not change password' 'Could not change password'
); );
}; };
Cloud.prototype.resetPassword = function (username, onSuccess, onError) { Cloud.prototype.resetPassword = function (username, onSuccess, onError) {
@ -403,6 +402,8 @@ Cloud.prototype.resendVerification = function (username, onSuccess, onError) {
// Projects // Projects
Cloud.prototype.saveProject = function (projectName, body, onSuccess, onError) { Cloud.prototype.saveProject = function (projectName, body, onSuccess, onError) {
// Expects a body object with the following paramters:
// xml, media, thumbnail, remixID (optional), notes (optional)
var myself = this; var myself = this;
this.checkCredentials( this.checkCredentials(
function (username) { function (username) {

Wyświetl plik

@ -5606,9 +5606,10 @@ IDE_Morph.prototype.buildProjectRequest = function () {
return body; return body;
} }
IDE_Morph.prototype.verifyProjectContents = function (body) { IDE_Morph.prototype.verifyProject = function (body) {
// Ensure the project is less than 10MB and serializes correctly.
var encodedBody = JSON.stringify(body); var encodedBody = JSON.stringify(body);
if (ecodedBody.length > Cloud.MAX_FILE_SIZE) { if (encodedBody.length > Cloud.MAX_FILE_SIZE) {
new DialogBoxMorph().inform( new DialogBoxMorph().inform(
'Snap!Cloud - Cannot Save Project', 'Snap!Cloud - Cannot Save Project',
'The media inside this project exceeds 10 MB.\n' + 'The media inside this project exceeds 10 MB.\n' +
@ -5645,24 +5646,28 @@ IDE_Morph.prototype.verifyProjectContents = function (body) {
this.serializer.isCollectingMedia = false; this.serializer.isCollectingMedia = false;
this.serializer.flushMedia(); this.serializer.flushMedia();
return size; return encodedBody.length;
} }
IDE_Morph.prototype.saveProjectToCloud = function (name) { IDE_Morph.prototype.saveProjectToCloud = function (name) {
var projectBody, projectSize; var myself = this, projectBody, projectSize;
if (!name) {return; } if (name) {
this.setProjectName(name);
}
this.showMessage('Saving project\nto the cloud...'); this.showMessage('Saving project\nto the cloud...');
this.setProjectName(name); console.log('name', name);
projectBody = this.buildProjectRequest(); projectBody = this.buildProjectRequest();
projectSize = this.verifyProjectSize(projectBody); console.log(projectBody);
projectSize = this.verifyProject(projectBody);
console.log(projectSize);
if (!projectSize) {return; } if (!projectSize) {return; }
this.showMessage( this.showMessage(
'Uploading ' + Math.round(projectSize / 1024) + ' KB...' 'Uploading ' + Math.round(projectSize / 1024) + ' KB...'
); );
this.cloud.saveProject( this.cloud.saveProject(
name, this.projectName,
projectBody, projectBody,
function () {myself.showMessage('saved.', 2); }, function () {myself.showMessage('saved.', 2); },
this.cloudError() this.cloudError()
@ -6700,16 +6705,8 @@ ProjectDialogMorph.prototype.saveProject = function () {
}; };
ProjectDialogMorph.prototype.saveCloudProject = function () { ProjectDialogMorph.prototype.saveCloudProject = function () {
var myself = this; this.ide.source = 'cloud';
this.ide.showMessage('Saving project\nto the cloud...'); this.ide.saveProjectToCloud();
this.ide.cloud.saveProject(
this.ide,
function () {
myself.ide.source = 'cloud';
myself.ide.showMessage('saved.', 2);
},
this.ide.cloudError()
);
this.destroy(); this.destroy();
}; };