Introduce multiwikiclient plugin

Routes are now rationalised, too.
This commit is contained in:
Jeremy Ruston
2024-03-20 15:13:50 +00:00
parent 38ee942d8f
commit 9b3ca525ee
45 changed files with 679 additions and 166 deletions

View File

@@ -0,0 +1,35 @@
/*\
title: $:/plugins/tiddlywiki/multiwikiserver/routes/handlers/delete-bag-tiddler.js
type: application/javascript
module-type: mws-route
DELETE /bags/:bag_name/tiddler/:title
\*/
(function() {
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.method = "DELETE";
exports.path = /^\/bags\/([^\/]+)\/tiddlers\/(.+)$/;
exports.handler = function(request,response,state) {
// Get the parameters
var bag_name = $tw.utils.decodeURIComponentSafe(state.params[0]),
title = $tw.utils.decodeURIComponentSafe(state.params[1]);
if(bag_name) {
$tw.mws.store.deleteTiddler(title,bag_name);
response.writeHead(204, "OK", {
"Content-Type": "text/plain"
});
response.end();
} else {
response.writeHead(404);
response.end();
}
};
}());

View File

@@ -1,39 +0,0 @@
/*\
title: $:/plugins/tiddlywiki/multiwikiserver/routes/handlers/delete-recipe-tiddler.js
type: application/javascript
module-type: mws-route
DELETE /wiki/:recipe_name/recipes/:bag_name/tiddler/:title
NOTE: Urls currently include the recipe name twice. This is temporary to minimise the changes to the TiddlyWeb plugin
\*/
(function() {
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.method = "DELETE";
exports.path = /^\/wiki\/([^\/]+)\/bags\/([^\/]+)\/tiddlers\/(.+)$/;
exports.handler = function(request,response,state) {
// Get the parameters
var recipe_name = $tw.utils.decodeURIComponentSafe(state.params[0]),
bag_name = $tw.utils.decodeURIComponentSafe(state.params[1]),
title = $tw.utils.decodeURIComponentSafe(state.params[2]);
var recipeBags = $tw.mws.store.getRecipeBags(recipe_name);
if(recipeBags.indexOf(bag_name) !== -1) {
$tw.mws.store.deleteTiddler(title,bag_name);
response.writeHead(204, "OK", {
"Content-Type": "text/plain"
});
response.end();
} else {
response.writeHead(404);
response.end();
}
};
}());

View File

@@ -3,7 +3,7 @@ title: $:/plugins/tiddlywiki/multiwikiserver/routes/handlers/get-bag-tiddler-blo
type: application/javascript
module-type: mws-route
GET /wiki/:bag_name/bags/:bag_name/tiddler/:title/blob
GET /bags/:bag_name/tiddler/:title/blob
\*/
(function() {
@@ -14,14 +14,13 @@ GET /wiki/:bag_name/bags/:bag_name/tiddler/:title/blob
exports.method = "GET";
exports.path = /^\/wiki\/([^\/]+)\/bags\/([^\/]+)\/tiddlers\/([^\/]+)\/blob$/;
exports.path = /^\/bags\/([^\/]+)\/tiddlers\/([^\/]+)\/blob$/;
exports.handler = function(request,response,state) {
// Get the parameters
const bag_name = $tw.utils.decodeURIComponentSafe(state.params[0]),
bag_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]),
title = $tw.utils.decodeURIComponentSafe(state.params[2]);
if(bag_name === bag_name_2) {
title = $tw.utils.decodeURIComponentSafe(state.params[1]);
if(bag_name) {
const result = $tw.mws.store.getBagTiddlerStream(title,bag_name);
if(result) {
response.writeHead(200, "OK",{

View File

@@ -3,9 +3,8 @@ title: $:/plugins/tiddlywiki/multiwikiserver/routes/handlers/get-bag-tiddler.js
type: application/javascript
module-type: mws-route
GET /wiki/:bag_name/bags/:bag_name/tiddler/:title
GET /bags/:bag_name/tiddler/:title
NOTE: Urls currently include the bag name twice. This is temporary to minimise the changes to the TiddlyWeb plugin
\*/
(function() {
@@ -16,15 +15,14 @@ NOTE: Urls currently include the bag name twice. This is temporary to minimise t
exports.method = "GET";
exports.path = /^\/wiki\/([^\/]+)\/bags\/([^\/]+)\/tiddlers\/(.+)$/;
exports.path = /^\/bags\/([^\/]+)\/tiddlers\/(.+)$/;
exports.handler = function(request,response,state) {
// Get the parameters
var bag_name = $tw.utils.decodeURIComponentSafe(state.params[0]),
bag_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]),
title = $tw.utils.decodeURIComponentSafe(state.params[2]),
result = bag_name === bag_name_2 && $tw.mws.store.getBagTiddler(title,bag_name);
if(bag_name === bag_name_2 && result) {
title = $tw.utils.decodeURIComponentSafe(state.params[1]),
result = bag_name && $tw.mws.store.getBagTiddler(title,bag_name);
if(bag_name && result) {
// If application/json is requested then this is an API request, and gets the response in JSON
if(request.headers.accept && request.headers.accept.indexOf("application/json") !== -1) {
var tiddlerFields = {},

View File

@@ -3,10 +3,8 @@ title: $:/plugins/tiddlywiki/multiwikiserver/routes/handlers/get-bag.js
type: application/javascript
module-type: mws-route
GET /wiki/:bag_name/bags/:bag_name/
GET /wiki/:bag_name/bags/:bag_name
NOTE: Urls currently include the bag name twice. This is temporary to minimise the changes to the TiddlyWeb plugin
GET /bags/:bag_name/
GET /bags/:bag_name
\*/
(function() {
@@ -17,19 +15,18 @@ NOTE: Urls currently include the bag name twice. This is temporary to minimise t
exports.method = "GET";
exports.path = /^\/wiki\/([^\/]+)\/bags\/([^\/]+)(\/?)$/;
exports.path = /^\/bags\/([^\/]+)(\/?)$/;
exports.handler = function(request,response,state) {
// Redirect if there is no trailing slash. We do this so that the relative URL specified in the upload form works correctly
if(state.params[2] !== "/") {
if(state.params[1] !== "/") {
state.redirect(301,state.urlInfo.path + "/");
return;
}
// Get the parameters
var bag_name = $tw.utils.decodeURIComponentSafe(state.params[0]),
bag_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]),
bagTiddlers = bag_name === bag_name_2 && $tw.mws.store.getBagTiddlers(bag_name);
if(bag_name === bag_name_2 && bagTiddlers) {
bagTiddlers = bag_name && $tw.mws.store.getBagTiddlers(bag_name);
if(bag_name && bagTiddlers) {
// If application/json is requested then this is an API request, and gets the response in JSON
if(request.headers.accept && request.headers.accept.indexOf("application/json") !== -1) {
state.sendResponse(200,{"Content-Type": "application/json"},JSON.stringify(bagTiddlers),"utf8");

View File

@@ -3,9 +3,7 @@ title: $:/plugins/tiddlywiki/multiwikiserver/routes/handlers/get-recipe-tiddler.
type: application/javascript
module-type: mws-route
GET /wiki/:recipe_name/recipes/:recipe_name/tiddler/:title
NOTE: Urls currently include the recipe name twice. This is temporary to minimise the changes to the TiddlyWeb plugin
GET /recipes/:recipe_name/tiddler/:title
\*/
(function() {
@@ -16,15 +14,14 @@ NOTE: Urls currently include the recipe name twice. This is temporary to minimis
exports.method = "GET";
exports.path = /^\/wiki\/([^\/]+)\/recipes\/([^\/]+)\/tiddlers\/(.+)$/;
exports.path = /^\/recipes\/([^\/]+)\/tiddlers\/(.+)$/;
exports.handler = function(request,response,state) {
// Get the parameters
var recipe_name = $tw.utils.decodeURIComponentSafe(state.params[0]),
recipe_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]),
title = $tw.utils.decodeURIComponentSafe(state.params[2]),
tiddlerInfo = recipe_name === recipe_name_2 && $tw.mws.store.getRecipeTiddler(title,recipe_name);
if(recipe_name === recipe_name_2 && tiddlerInfo && tiddlerInfo.tiddler) {
title = $tw.utils.decodeURIComponentSafe(state.params[1]),
tiddlerInfo = recipe_name && $tw.mws.store.getRecipeTiddler(title,recipe_name);
if(recipe_name && tiddlerInfo && tiddlerInfo.tiddler) {
// If application/json is requested then this is an API request, and gets the response in JSON
if(request.headers.accept && request.headers.accept.indexOf("application/json") !== -1) {
var tiddlerFields = {},

View File

@@ -3,9 +3,7 @@ title: $:/plugins/tiddlywiki/multiwikiserver/routes/handlers/get-recipe-tiddlers
type: application/javascript
module-type: mws-route
GET /wiki/:recipe_name/recipes/:recipe_name/tiddlers.json?filter=:filter
NOTE: Urls currently include the recipe name twice. This is temporary to minimise the changes to the TiddlyWeb plugin
GET /recipes/:recipe_name/tiddlers.json?filter=:filter
\*/
(function() {
@@ -16,13 +14,12 @@ NOTE: Urls currently include the recipe name twice. This is temporary to minimis
exports.method = "GET";
exports.path = /^\/wiki\/([^\/]+)\/recipes\/([^\/]+)\/tiddlers.json$/;
exports.path = /^\/recipes\/([^\/]+)\/tiddlers.json$/;
exports.handler = function(request,response,state) {
// Get the parameters
var recipe_name = $tw.utils.decodeURIComponentSafe(state.params[0]),
recipe_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]);
if(recipe_name === recipe_name_2) {
var recipe_name = $tw.utils.decodeURIComponentSafe(state.params[0]);
if(recipe_name) {
// Get the tiddlers in the recipe
var recipeTiddlers = $tw.mws.store.getRecipeTiddlers(recipe_name);
// Get a skinny version of each tiddler

View File

@@ -36,7 +36,7 @@ exports.handler = function(request,response,state) {
$:/boot/bootprefix.js
$:/core
$:/library/sjcl.js
$:/plugins/tiddlywiki/tiddlyweb
$:/plugins/tiddlywiki/multiwikiclient
$:/themes/tiddlywiki/snowwhite
$:/themes/tiddlywiki/vanilla
`
@@ -57,7 +57,7 @@ exports.handler = function(request,response,state) {
response.write(",\n")
}
});
response.write(JSON.stringify({title: "$:/config/tiddlyweb/host",text: "$protocol$//$host$$pathname$/"}));
response.write(JSON.stringify({title: "$:/config/multiwikiclient/recipe",text: recipe_name}));
response.write(",\n")
response.write(template.substring(markerPos + marker.length))
// Finish response

View File

@@ -1,42 +0,0 @@
/*\
title: $:/plugins/tiddlywiki/multiwikiserver/routes/handlers/get-status.js
type: application/javascript
module-type: mws-route
GET /wiki/:recipe_name/status
\*/
(function() {
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.method = "GET";
exports.path = /^\/wiki\/([^\/]+)\/status$/;
exports.handler = function(request,response,state) {
// Get the recipe name from the parameters
var recipe_name = $tw.utils.decodeURIComponentSafe(state.params[0]);
// Compose the response
var text = JSON.stringify({
username: "Joe Bloggs",
anonymous: false,
read_only: false,
logout_is_available: false,
space: {
recipe: recipe_name
},
tiddlywiki_version: $tw.version
});
// Send response
if(text) {
state.sendResponse(200,{"Content-Type": "application/json"},text,"utf8");
} else {
response.writeHead(404);
response.end();
}
};
}());

View File

@@ -3,9 +3,7 @@ title: $:/plugins/tiddlywiki/multiwikiserver/routes/handlers/post-bag-tiddlers.j
type: application/javascript
module-type: mws-route
POST /wiki/:bag_name/bags/:bag_name/tiddlers/
NOTE: Urls currently include the bag name twice. This is temporary to minimise the changes to the TiddlyWeb plugin
POST /bags/:bag_name/tiddlers/
\*/
(function() {
@@ -16,7 +14,7 @@ NOTE: Urls currently include the bag name twice. This is temporary to minimise t
exports.method = "POST";
exports.path = /^\/wiki\/([^\/]+)\/bags\/([^\/]+)\/tiddlers\/$/;
exports.path = /^\/bags\/([^\/]+)\/tiddlers\/$/;
exports.bodyFormat = "stream";
@@ -27,12 +25,7 @@ exports.handler = function(request,response,state) {
fs = require("fs"),
processIncomingStream = require("$:/plugins/tiddlywiki/multiwikiserver/routes/helpers/multipart-forms.js").processIncomingStream;
// Get the parameters
var bag_name = $tw.utils.decodeURIComponentSafe(state.params[0]),
bag_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]);
// Require the bag names to match
if(bag_name !== bag_name_2) {
return state.sendResponse(400,{"Content-Type": "text/plain"},"Bad Request: bag names do not match");
}
var bag_name = $tw.utils.decodeURIComponentSafe(state.params[0]);
// Process the incoming data
processIncomingStream({
store: $tw.mws.store,

View File

@@ -3,9 +3,7 @@ title: $:/plugins/tiddlywiki/multiwikiserver/routes/handlers/put-bag.js
type: application/javascript
module-type: mws-route
PUT /wiki/:bag_name/bags/:bag_name
NOTE: Urls currently include the bag name twice. This is temporary to minimise the changes to the TiddlyWeb plugin
PUT /bags/:bag_name
\*/
(function() {
@@ -16,14 +14,13 @@ NOTE: Urls currently include the bag name twice. This is temporary to minimise t
exports.method = "PUT";
exports.path = /^\/wiki\/([^\/]+)\/bags\/(.+)$/;
exports.path = /^\/bags\/(.+)$/;
exports.handler = function(request,response,state) {
// Get the parameters
var bag_name = $tw.utils.decodeURIComponentSafe(state.params[0]),
bag_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]),
data = $tw.utils.parseJSONSafe(state.data);
if(bag_name === bag_name_2 && data) {
if(bag_name && data) {
const result = $tw.mws.store.createBag(bag_name,data.description);
if(!result) {
state.sendResponse(204,{

View File

@@ -3,9 +3,7 @@ title: $:/plugins/tiddlywiki/multiwikiserver/routes/handlers/put-recipe-tiddler.
type: application/javascript
module-type: mws-route
PUT /wiki/:recipe_name/recipes/:recipe_name/tiddlers/:title
NOTE: Urls currently include the recipe name twice. This is temporary to minimise the changes to the TiddlyWeb plugin
PUT /recipes/:recipe_name/tiddlers/:title
\*/
(function() {
@@ -16,13 +14,12 @@ NOTE: Urls currently include the recipe name twice. This is temporary to minimis
exports.method = "PUT";
exports.path = /^\/wiki\/([^\/]+)\/recipes\/([^\/]+)\/tiddlers\/(.+)$/;
exports.path = /^\/recipes\/([^\/]+)\/tiddlers\/(.+)$/;
exports.handler = function(request,response,state) {
// Get the parameters
var recipe_name = $tw.utils.decodeURIComponentSafe(state.params[0]),
recipe_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]),
title = $tw.utils.decodeURIComponentSafe(state.params[2]),
title = $tw.utils.decodeURIComponentSafe(state.params[1]),
fields = $tw.utils.parseJSONSafe(state.data);
// Pull up any subfields in the `fields` object
if(typeof fields.fields === "object") {
@@ -37,8 +34,7 @@ exports.handler = function(request,response,state) {
fields[name] = $tw.utils.stringifyList(value);
}
});
// Require the recipe names to match
if(recipe_name === recipe_name_2) {
if(recipe_name) {
var result = $tw.mws.store.saveRecipeTiddler(fields,recipe_name);
if(result) {
response.writeHead(204, "OK",{

View File

@@ -3,9 +3,7 @@ title: $:/plugins/tiddlywiki/multiwikiserver/routes/handlers/put-recipe.js
type: application/javascript
module-type: mws-route
PUT /wiki/:recipe_name/recipes/:recipe_name
NOTE: Urls currently include the recipe name twice. This is temporary to minimise the changes to the TiddlyWeb plugin
PUT /recipes/:recipe_name
\*/
(function() {
@@ -16,14 +14,13 @@ NOTE: Urls currently include the recipe name twice. This is temporary to minimis
exports.method = "PUT";
exports.path = /^\/wiki\/([^\/]+)\/recipes\/(.+)$/;
exports.path = /^\/recipes\/(.+)$/;
exports.handler = function(request,response,state) {
// Get the parameters
var recipe_name = $tw.utils.decodeURIComponentSafe(state.params[0]),
recipe_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]),
data = $tw.utils.parseJSONSafe(state.data);
if(recipe_name === recipe_name_2 && data) {
if(recipe_name && data) {
const result = $tw.mws.store.createRecipe(recipe_name,data.bag_names,data.description);
if(!result) {
state.sendResponse(204,{