Skip to content

Commit

Permalink
Fix bug where save states weren't enumerated locally.
Browse files Browse the repository at this point in the history
  • Loading branch information
Proplex committed Nov 22, 2017
1 parent d433170 commit f3dbd95
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 46 deletions.
21 changes: 11 additions & 10 deletions app/rest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,33 +52,34 @@ def save_state():
save_state_file.write(json.dumps(state))
print "I'm saving: " + state["project"]["uuid"]
return jsonify({"results": "SUCCESS", "uuid": state["project"]["uuid"]}) #Return the UUID if successful. This is used by the client to receive the UUID on the first initial save.
except IOError as error:
except IOError as error: #Disk error on save
return jsonify({"results": "FAIL", "reason": "IOERROR", "error": str(error.errno), "errorstring": str(error.strerror)})
except TypeError as error:
except TypeError as error: #Save state format error
return jsonify({"results": "FAIL", "reason": "BADPOST", "error": str(error)})
except Exception as error:
except Exception as error: #Other general error
return jsonify({"results": "FAIL", "reason": "OTHER", "error": str(error)})
return jsonify({"results": "FAIL", "reason": "NOTPOST"}) #How'd we get here? Someone trying to load the page?


#This URL (website.com/rest/resume_state) is used to fetch the JSON file of the state requested by the user.
#The user requests the UUID of the specific JSON file, which is fetched and dumped back to client.
#JSON schema TBD
@rest.route('/resume_state/', methods=["GET", "POST"])
@rest.route('/resume_state', methods=["GET", "POST"])
@rest.route('/resume_state/<uuid>', methods=["GET", "POST"])
def resume_state(uuid=None):
if uuid == None: #We're looking to see which save states we have
states = ""
try:
for save_state in os.listdir(current_app.config["JSON_STORE_DATA"]):
states += save_state[:-5] + "," #Only return the UUID, remove .json ending
return str(states[:-1])
except:
return "FAIL" #Something went wrong. Let's be purposely dense about what went wrong.
if save_state[-5:] == ".json":
states += save_state[:-5] + "," #Only return the UUID, remove .json ending
return jsonify({"results": "SUCCESS", "data": str(states[:-1])})
except Exception as error: #There was an error listing the directory, return general error
return jsonify({"results": "FAIL", "reason": "OTHER", "error": str(error)})
else: #We're requesting a specific UUID to resume from.
try:
with open(current_app.config["JSON_STORE_DATA"] + secure_filename(str(uuid))+ ".json", 'r') as save_state_file:
return save_state_file.read()
except:
return "FAIL"
except Exception as error: #Other general error
return jsonify({"results": "FAIL", "reason": "OTHER", "error": str(error)})
return "FAIL" #How'd we get here?
10 changes: 0 additions & 10 deletions app/static/js/Menubar.Help.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ Menubar.Help = function ( editor ) {
options.setClass( 'options' );
container.add( options );

// Source code

var option = new UI.Row();
option.setClass( 'option' );
option.setTextContent( 'Source code' );
option.onClick( function () {

window.open( 'https://github.com/mrdoob/three.js/tree/master/editor', '_blank' );

} );
//options.add( option );

// How To
Expand Down
2 changes: 1 addition & 1 deletion app/static/js/Menubar.Status.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Menubar.Status = function ( editor ) {

} );

var version = new UI.Text( 'prototype' );
var version = new UI.Text( 'v1.0.0' );
version.setClass( 'title' );
version.setOpacity( 0.5 );
container.add( version );
Expand Down
35 changes: 18 additions & 17 deletions app/static/js/Storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,24 @@ var Storage = function () {
contentType: "application/json",
dataType: "json",
success: function(data) {
if (data.results == "FAIL") {
if (data.reason == "IOERROR") {
// The server had a disk or permissions error. Let the user know
if (data.error == 13) { // No permission
console.error('[' + /\d\d\:\d\d\:\d\d/.exec(new Date())[0] + ']', 'Failed to save state to server. The server doesn\'t have permission to write to disk.');
} else if (data.error == 28) { // Disk full
console.error('[' + /\d\d\:\d\d\:\d\d/.exec(new Date())[0] + ']', 'Failed to save state to server. The server doesn\'t have enough space to save to disk.');
} else { //Other IO error
console.error('[' + /\d\d\:\d\d\:\d\d/.exec(new Date())[0] + ']', 'Failed to save state to server. There was an I/O Error.', data.errorstring);
}
} // Other error
console.error('[' + /\d\d\:\d\d\:\d\d/.exec(new Date())[0] + ']', 'Failed to save state to server.', data.reason, data.error);
}
console.log('[' + /\d\d\:\d\d\:\d\d/.exec(new Date())[0] + ']', 'Saved state to server as UUID', data.uuid);
if ( editor.project_uuid == "" ) {
editor.project_uuid = data.uuid; //Set the initial UUID if this the first save-state for this session.
}
if ( data.results == "SUCCESS" ) {
console.log('[' + /\d\d\:\d\d\:\d\d/.exec(new Date())[0] + ']', 'Saved state to server as UUID', data.uuid);
if ( editor.project_uuid == "" ) {
editor.project_uuid = data.uuid; //Set the initial UUID if this the first save-state for this session.
}
} else {
if (data.reason == "IOERROR") {
// The server had a disk or permissions error. Let the user know
if (data.error == 13) { // No permission
console.error('[' + /\d\d\:\d\d\:\d\d/.exec(new Date())[0] + ']', 'Failed to save state to server. The server doesn\'t have permission to write to disk.');
} else if (data.error == 28) { // Disk full
console.error('[' + /\d\d\:\d\d\:\d\d/.exec(new Date())[0] + ']', 'Failed to save state to server. The server doesn\'t have enough space to save to disk.');
} else { //Other IO error
console.error('[' + /\d\d\:\d\d\:\d\d/.exec(new Date())[0] + ']', 'Failed to save state to server. There was an I/O Error.', data.errorstring);
}
} // Other error
console.error('[' + /\d\d\:\d\d\:\d\d/.exec(new Date())[0] + ']', 'Failed to save state to server.', data.reason, data.error);
}
},
error: function() {
console.error('[' + /\d\d\:\d\d\:\d\d/.exec(new Date())[0] + ']', 'Failed to save state to server. ');
Expand Down
17 changes: 9 additions & 8 deletions app/templates/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -458,16 +458,17 @@

function fetchStates() {
$.ajax({
url: '/rest/resume_state/',
data: {
format: 'json'
},
url: '/rest/resume_state',
dataType: 'json',
success: function (data) {
var all_uuids = this.responseText.split(",");
saves.innerHTML = "";
for (var i = 0; i < all_uuids.length; i++)
saves.insertAdjacentHTML("beforeend", "<a href=\"#\" onClick=\"loadProject('" + all_uuids[i] + "');\" class=\"list-group-item list-group-item-action\">" + all_uuids[i] + "</a>");
if ( data.results == "SUCCESS" ) {
var all_uuids = data.data.split(",");
saves.innerHTML = "";
for (var i = 0; i < all_uuids.length; i++)
saves.insertAdjacentHTML("beforeend", "<a href=\"#\" onClick=\"loadProject('" + all_uuids[i] + "');\" class=\"list-group-item list-group-item-action\">" + all_uuids[i] + "</a>");
} else {
console.error('[' + /\d\d\:\d\d\:\d\d/.exec(new Date())[0] + ']', 'Failed to fetch save state from server.', data.reason, data.error);
}
},
type: 'GET'
});
Expand Down

0 comments on commit f3dbd95

Please sign in to comment.