From e254529763436348051dbb2ece028fdad15c9573 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Sun, 12 Jan 2014 12:05:15 +0000 Subject: [PATCH] More configuration controls for TiddlySpot saver And more reliable checking of the result returned from the server --- core/modules/savers/upload.js | 9 +++++---- core/ui/ControlPanel/Saving.tid | 9 ++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/core/modules/savers/upload.js b/core/modules/savers/upload.js index ef506cb84..403c4810b 100644 --- a/core/modules/savers/upload.js +++ b/core/modules/savers/upload.js @@ -27,10 +27,11 @@ UploadSaver.prototype.save = function(text,method,callback) { return false; } // Get the various parameters we need - var backupDir = ".", + var backupDir = this.wiki.getTextReference("$:/UploadBackupDir") || ".", username = this.wiki.getTextReference("$:/UploadName"), password = $tw.utils.getPassword("upload"), - uploadDir = ".", + uploadDir = this.wiki.getTextReference("$:/UploadDir") || ".", + uploadFilename = this.wiki.getTextReference("$:/UploadFilename") || "index.html", url = this.wiki.getTextReference("$:/UploadURL"); // Bail out if we don't have the bits we need if(!username || username.toString().trim() === "" || !password || password.toString().trim() === "") { @@ -47,7 +48,7 @@ UploadSaver.prototype.save = function(text,method,callback) { head.push("--" + boundary + "\r\nContent-disposition: form-data; name=\"UploadPlugin\"\r\n"); head.push("backupDir=" + backupDir + ";user=" + username + ";password=" + password + ";uploaddir=" + uploadDir + ";;"); head.push("\r\n" + "--" + boundary); - head.push("Content-disposition: form-data; name=\"userfile\"; filename=\"index.html\""); + head.push("Content-disposition: form-data; name=\"userfile\"; filename=\"" + uploadFilename + "\""); head.push("Content-Type: text/html;charset=UTF-8"); head.push("Content-Length: " + text.length + "\r\n"); head.push(""); @@ -60,7 +61,7 @@ UploadSaver.prototype.save = function(text,method,callback) { http.setRequestHeader("Content-Type","multipart/form-data; ;charset=UTF-8; boundary=" + boundary); http.onreadystatechange = function() { if(http.readyState == 4 && http.status == 200) { - if(http.responseText.trim() === "0 - Fileindex.html") { + if(http.responseText.substr(0,4) === "0 - ") { callback(null); } else { callback(http.responseText); diff --git a/core/ui/ControlPanel/Saving.tid b/core/ui/ControlPanel/Saving.tid index f72525021..629233144 100644 --- a/core/ui/ControlPanel/Saving.tid +++ b/core/ui/ControlPanel/Saving.tid @@ -16,7 +16,14 @@ http://$(userName)$.tiddlyspot.com/backup/ |[[Wiki name|$:/UploadName]] |<$edit-text tiddler="$:/UploadName" default="" tag="input"/> | |Password |<$password name="upload"/> | -|Server URL |<$edit-text tiddler="$:/UploadURL" default="" tag="input"/> | |Backups |<> | +!! Advanced settings + +|Server URL |<$edit-text tiddler="$:/UploadURL" default="" tag="input"/> | +|Upload filename |<$edit-text tiddler="$:/UploadFilename" default="index.html" tag="input"/> | +|Upload directory |<$edit-text tiddler="$:/UploadDir" default="." tag="input"/> | +|Backup directory |<$edit-text tiddler="$:/UploadBackupDir" default="." tag="input"/> | + + //The server URL defaults to `http://.tiddlyspot.com/store.cgi` and can be changed to use a custom server address//