1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-08-07 06:14:44 +00:00

More configuration controls for TiddlySpot saver

And more reliable checking of the result returned from the server
This commit is contained in:
Jermolene 2014-01-12 12:05:15 +00:00
parent 5dff212e5a
commit e254529763
2 changed files with 13 additions and 5 deletions

View File

@ -27,10 +27,11 @@ UploadSaver.prototype.save = function(text,method,callback) {
return false; return false;
} }
// Get the various parameters we need // Get the various parameters we need
var backupDir = ".", var backupDir = this.wiki.getTextReference("$:/UploadBackupDir") || ".",
username = this.wiki.getTextReference("$:/UploadName"), username = this.wiki.getTextReference("$:/UploadName"),
password = $tw.utils.getPassword("upload"), password = $tw.utils.getPassword("upload"),
uploadDir = ".", uploadDir = this.wiki.getTextReference("$:/UploadDir") || ".",
uploadFilename = this.wiki.getTextReference("$:/UploadFilename") || "index.html",
url = this.wiki.getTextReference("$:/UploadURL"); url = this.wiki.getTextReference("$:/UploadURL");
// Bail out if we don't have the bits we need // Bail out if we don't have the bits we need
if(!username || username.toString().trim() === "" || !password || password.toString().trim() === "") { 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("--" + boundary + "\r\nContent-disposition: form-data; name=\"UploadPlugin\"\r\n");
head.push("backupDir=" + backupDir + ";user=" + username + ";password=" + password + ";uploaddir=" + uploadDir + ";;"); head.push("backupDir=" + backupDir + ";user=" + username + ";password=" + password + ";uploaddir=" + uploadDir + ";;");
head.push("\r\n" + "--" + boundary); 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-Type: text/html;charset=UTF-8");
head.push("Content-Length: " + text.length + "\r\n"); head.push("Content-Length: " + text.length + "\r\n");
head.push(""); 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.setRequestHeader("Content-Type","multipart/form-data; ;charset=UTF-8; boundary=" + boundary);
http.onreadystatechange = function() { http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) { if(http.readyState == 4 && http.status == 200) {
if(http.responseText.trim() === "0 - Fileindex.html") { if(http.responseText.substr(0,4) === "0 - ") {
callback(null); callback(null);
} else { } else {
callback(http.responseText); callback(http.responseText);

View File

@ -16,7 +16,14 @@ http://$(userName)$.tiddlyspot.com/backup/
|[[Wiki name|$:/UploadName]] |<$edit-text tiddler="$:/UploadName" default="" tag="input"/> | |[[Wiki name|$:/UploadName]] |<$edit-text tiddler="$:/UploadName" default="" tag="input"/> |
|Password |<$password name="upload"/> | |Password |<$password name="upload"/> |
|Server URL |<$edit-text tiddler="$:/UploadURL" default="" tag="input"/> |
|Backups |<<backupLink>> | |Backups |<<backupLink>> |
!! 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://<wikiname>.tiddlyspot.com/store.cgi` and can be changed to use a custom server address// //The server URL defaults to `http://<wikiname>.tiddlyspot.com/store.cgi` and can be changed to use a custom server address//