mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Start using the server connection tiddler to store host details
This commit is contained in:
parent
5d10cd2ae3
commit
4742ab14fc
@ -711,7 +711,22 @@ exports.initServerConnections = function() {
|
||||
this.serverConnections = {};
|
||||
var self = this;
|
||||
$tw.modules.forEachModuleOfType("serverconnection",function(title,module) {
|
||||
self.serverConnections[title] = module;
|
||||
// Get the associated syncer
|
||||
if(module.syncer) {
|
||||
var syncer = self.syncers[module.syncer];
|
||||
if(syncer) {
|
||||
// Add the connection and save information about it
|
||||
var connection = syncer.addConnection(module);
|
||||
if(connection instanceof Error) {
|
||||
console.log("Error adding connection: " + connection);
|
||||
} else {
|
||||
self.serverConnections[title] = {
|
||||
syncer: syncer,
|
||||
connection: connection
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -4,4 +4,5 @@ module-type: serverconnection
|
||||
|
||||
syncer: tiddlywebsyncer
|
||||
# replace with a tiddlyspace to which you have write access
|
||||
server: http://tw5tiddlyweb.tiddlyspace.com/
|
||||
host: http://tw5tiddlyweb.tiddlyspace.com/
|
||||
recipe: tw5tiddlyweb_public
|
||||
|
@ -16,13 +16,7 @@ Main TiddlyWeb integration module
|
||||
Creates a TiddlyWebSyncer object
|
||||
*/
|
||||
var TiddlyWebSyncer = function(options) {
|
||||
// Mark us as not logged in
|
||||
$tw.wiki.addTiddler({
|
||||
title: TiddlyWebSyncer.titleIsLoggedIn,
|
||||
text: "no"
|
||||
});
|
||||
// Get the login status
|
||||
this.getStatus();
|
||||
this.connection = undefined;
|
||||
};
|
||||
|
||||
TiddlyWebSyncer.titleIsLoggedIn = "$:/plugins/tiddlyweb/IsLoggedIn";
|
||||
@ -36,6 +30,27 @@ TiddlyWebSyncer.prototype.showError = function(error) {
|
||||
console.log("TiddlyWeb error: " + error);
|
||||
};
|
||||
|
||||
TiddlyWebSyncer.prototype.addConnection = function(connection) {
|
||||
// Check if we've already got a connection
|
||||
if(this.connection) {
|
||||
return Error("TiddlyWebSyncer can only handle a single connection");
|
||||
}
|
||||
// Check the connection has its constituent parts
|
||||
if(!connection.host || !connection.recipe) {
|
||||
return Error("Missing connection data")
|
||||
}
|
||||
// Mark us as not logged in
|
||||
$tw.wiki.addTiddler({
|
||||
title: TiddlyWebSyncer.titleIsLoggedIn,
|
||||
text: "no"
|
||||
});
|
||||
// Save and return the connection object
|
||||
this.connection = connection;
|
||||
// Get the login status
|
||||
this.getStatus();
|
||||
return ""; // We only support a single connection
|
||||
};
|
||||
|
||||
/*
|
||||
Handle syncer messages
|
||||
*/
|
||||
@ -74,7 +89,7 @@ TiddlyWebSyncer.prototype.getCsrfToken = function() {
|
||||
TiddlyWebSyncer.prototype.getStatus = function(callback) {
|
||||
// Get status
|
||||
this.httpRequest({
|
||||
url: "http://tw5tiddlyweb.tiddlyspace.com/status",
|
||||
url: this.connection.host + "status",
|
||||
callback: function(err,data) {
|
||||
// Decode the status JSON
|
||||
var json = null;
|
||||
@ -134,7 +149,7 @@ Attempt to login to TiddlyWeb.
|
||||
TiddlyWebSyncer.prototype.login = function(username,password,callback) {
|
||||
var self = this;
|
||||
var httpRequest = this.httpRequest({
|
||||
url: "http://tw5tiddlyweb.tiddlyspace.com/challenge/tiddlywebplugins.tiddlyspace.cookie_form",
|
||||
url: this.connection.host + "challenge/tiddlywebplugins.tiddlyspace.cookie_form",
|
||||
type: "POST",
|
||||
data: {
|
||||
user: username,
|
||||
@ -164,7 +179,7 @@ TiddlyWebSyncer.prototype.logout = function(options) {
|
||||
options = options || {};
|
||||
var self = this;
|
||||
var httpRequest = this.httpRequest({
|
||||
url: "http://tw5tiddlyweb.tiddlyspace.com/logout",
|
||||
url: this.connection.host + "logout",
|
||||
type: "POST",
|
||||
data: {
|
||||
csrf_token: this.getCsrfToken(),
|
||||
|
Loading…
Reference in New Issue
Block a user