# HG changeset patch # User Nicholas Jillings # Date 1501660219 -3600 # Node ID a10cbbccc4f34a5656a0798ee9c0511d6a888aa4 # Parent eaa5dc4aedbf98d835c7659a366853f29adf012b #193. Partial files save with prefix ‘update’. Partials are deleted once full test is submitted and saved. diff -r eaa5dc4aedbf -r a10cbbccc4f3 js/core.js --- a/js/core.js Wed Aug 02 08:29:23 2017 +0100 +++ b/js/core.js Wed Aug 02 08:50:19 2017 +0100 @@ -3575,7 +3575,7 @@ returnURL = specification.projectReturn; } } - xmlhttp.open("POST", returnURL + "php/save.php?key=" + this.key + "&saveFilenamePrefix=" + this.parent.filenamePrefix); + xmlhttp.open("POST", returnURL + "php/save.php?key=" + this.key + "&saveFilenamePrefix=" + this.parent.filenamePrefix + "&state=update"); xmlhttp.setRequestHeader('Content-Type', 'text/xml'); xmlhttp.onerror = function () { console.log('Error updating file to server!'); @@ -3613,6 +3613,7 @@ } else { saveURL += this.parent.filenamePrefix; } + saveURL += "&state=finish"; return new Promise(function (resolve, reject) { var xmlhttp = new XMLHttpRequest(); xmlhttp.open("POST", saveURL); diff -r eaa5dc4aedbf -r a10cbbccc4f3 php/save.php --- a/php/save.php Wed Aug 02 08:29:23 2017 +0100 +++ b/php/save.php Wed Aug 02 08:50:19 2017 +0100 @@ -33,7 +33,17 @@ } $postText = file_get_contents('php://input'); $file_key = $_GET['key']; -$filename = '../saves/'.$saveFilenamePrefix.$file_key.".xml"; + +$update = false; +if (isset($_GET["update"])) { + $update = $_GET["update"] == "update"; +} + +if ($update) { + $filename = '../saves/update-'.$saveFilenamePrefix.$file_key.".xml"; +} else { + $filename = '../saves/'.$saveFilenamePrefix.$file_key.".xml"; +} if (!file_exists($filename)) { die('Could not find save'); @@ -132,4 +142,8 @@ // Return XML confirmation data $xml = 'OK"'.$filename.'"'; echo $xml; + +if (!$update) { + unlink('../saves/update-'.$saveFilenamePrefix.$file_key.".xml"); +} ?> diff -r eaa5dc4aedbf -r a10cbbccc4f3 python/pythonServer.py --- a/python/pythonServer.py Wed Aug 02 08:29:23 2017 +0100 +++ b/python/pythonServer.py Wed Aug 02 08:50:19 2017 +0100 @@ -138,12 +138,15 @@ global curSaveIndex options = self.path.rsplit('?') options = options[1].rsplit('&') + update = False for option in options: optionPair = option.rsplit('=') if optionPair[0] == "key": key = optionPair[1] elif optionPair[0] == "saveFilenamePrefix": prefix = optionPair[1] + elif optionPair[0] == "state": + update = optionPair[1] == "update" if key == None: self.send_response(404) return @@ -153,6 +156,8 @@ postVars = self.rfile.read(varLen) print("Saving file key "+key) filename = prefix+'-'+key+'.xml' + if update: + filename = "update-"+filename file = open('../saves/'+filename,'wb') file.write(postVars) file.close() @@ -173,6 +178,8 @@ self.wfile.write(bytes(reply, "utf-8")) curSaveIndex += 1 curFileName = 'test-'+str(curSaveIndex)+'.xml' + if update == False: + os.remove("../saves/update-"+filename) def poolXML(s): pool = ET.parse('../tests/pool.xml')