mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-30 13:29:56 +00:00
Introduce $tw.mws for MWS globals
This commit is contained in:
parent
2c810faeeb
commit
f925f036c9
@ -41,7 +41,7 @@ function loadBackupArchive(archivePath) {
|
|||||||
const bagNames = fs.readdirSync(path.resolve(archivePath,"bags")).filter(filename => filename !== ".DS_Store");
|
const bagNames = fs.readdirSync(path.resolve(archivePath,"bags")).filter(filename => filename !== ".DS_Store");
|
||||||
for(const bagName of bagNames) {
|
for(const bagName of bagNames) {
|
||||||
console.log(`Reading bag ${bagName}`);
|
console.log(`Reading bag ${bagName}`);
|
||||||
$tw.sqlTiddlerStore.createBag(decodeURIComponent(bagName),"No description for " + bagName);
|
$tw.mws.store.createBag(decodeURIComponent(bagName),"No description for " + bagName);
|
||||||
// Read the metadata
|
// Read the metadata
|
||||||
const jsonInfo = JSON.parse(fs.readFileSync(path.resolve(archivePath,"bags",bagName,"meta/info.json"),"utf8"));
|
const jsonInfo = JSON.parse(fs.readFileSync(path.resolve(archivePath,"bags",bagName,"meta/info.json"),"utf8"));
|
||||||
if(fs.existsSync(path.resolve(archivePath,"bags",bagName,"tiddlers"))) {
|
if(fs.existsSync(path.resolve(archivePath,"bags",bagName,"tiddlers"))) {
|
||||||
@ -50,7 +50,7 @@ function loadBackupArchive(archivePath) {
|
|||||||
for(const tiddlerFilename of tiddlerFilenames) {
|
for(const tiddlerFilename of tiddlerFilenames) {
|
||||||
const jsonTiddler = fs.readFileSync(path.resolve(archivePath,"bags",bagName,"tiddlers",tiddlerFilename),"utf8"),
|
const jsonTiddler = fs.readFileSync(path.resolve(archivePath,"bags",bagName,"tiddlers",tiddlerFilename),"utf8"),
|
||||||
tiddler = JSON.parse(jsonTiddler);
|
tiddler = JSON.parse(jsonTiddler);
|
||||||
$tw.sqlTiddlerStore.saveBagTiddler(tiddler,decodeURIComponent(bagName));
|
$tw.mws.store.saveBagTiddler(tiddler,decodeURIComponent(bagName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ function loadBackupArchive(archivePath) {
|
|||||||
const recipeNames = fs.readdirSync(path.resolve(archivePath,"recipes")).filter(filename => filename !== ".DS_Store");
|
const recipeNames = fs.readdirSync(path.resolve(archivePath,"recipes")).filter(filename => filename !== ".DS_Store");
|
||||||
for(const recipeName of recipeNames) {
|
for(const recipeName of recipeNames) {
|
||||||
const jsonInfo = JSON.parse(fs.readFileSync(path.resolve(archivePath,"recipes",recipeName,"info.json"),"utf8"));
|
const jsonInfo = JSON.parse(fs.readFileSync(path.resolve(archivePath,"recipes",recipeName,"info.json"),"utf8"));
|
||||||
$tw.sqlTiddlerStore.createRecipe(decodeURIComponent(recipeName),jsonInfo.recipe.map(recipeLine => recipeLine[0]),"No description for " + recipeName);
|
$tw.mws.store.createRecipe(decodeURIComponent(recipeName),jsonInfo.recipe.map(recipeLine => recipeLine[0]),"No description for " + recipeName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,28 +38,30 @@ exports.startup = function() {
|
|||||||
var databasePath = path.resolve($tw.boot.wikiPath,"store/database.sqlite");
|
var databasePath = path.resolve($tw.boot.wikiPath,"store/database.sqlite");
|
||||||
// Create and initialise the tiddler store
|
// Create and initialise the tiddler store
|
||||||
var SqlTiddlerStore = require("$:/plugins/tiddlywiki/multiwikiserver/sql-tiddler-store.js").SqlTiddlerStore;
|
var SqlTiddlerStore = require("$:/plugins/tiddlywiki/multiwikiserver/sql-tiddler-store.js").SqlTiddlerStore;
|
||||||
$tw.sqlTiddlerStore = new SqlTiddlerStore({
|
$tw.mws = {
|
||||||
databasePath: databasePath
|
store: new SqlTiddlerStore({
|
||||||
});
|
databasePath: databasePath
|
||||||
|
})
|
||||||
|
};
|
||||||
// Create docs bag and recipe
|
// Create docs bag and recipe
|
||||||
$tw.sqlTiddlerStore.createBag("docs","TiddlyWiki Documentation from https://tiddlywiki.com/");
|
$tw.mws.store.createBag("docs","TiddlyWiki Documentation from https://tiddlywiki.com/");
|
||||||
$tw.sqlTiddlerStore.createRecipe("docs",["docs"],"TiddlyWiki Documentation from https://tiddlywiki.com/");
|
$tw.mws.store.createRecipe("docs",["docs"],"TiddlyWiki Documentation from https://tiddlywiki.com/");
|
||||||
$tw.sqlTiddlerStore.saveTiddlersFromPath(path.resolve($tw.boot.corePath,$tw.config.editionsPath,"tw5.com/tiddlers"),"docs");
|
$tw.mws.store.saveTiddlersFromPath(path.resolve($tw.boot.corePath,$tw.config.editionsPath,"tw5.com/tiddlers"),"docs");
|
||||||
$tw.sqlTiddlerStore.createBag("dev-docs","TiddlyWiki Developer Documentation from https://tiddlywiki.com/dev/");
|
$tw.mws.store.createBag("dev-docs","TiddlyWiki Developer Documentation from https://tiddlywiki.com/dev/");
|
||||||
$tw.sqlTiddlerStore.createRecipe("dev-docs",["dev-docs"],"TiddlyWiki Developer Documentation from https://tiddlywiki.com/dev/");
|
$tw.mws.store.createRecipe("dev-docs",["dev-docs"],"TiddlyWiki Developer Documentation from https://tiddlywiki.com/dev/");
|
||||||
$tw.sqlTiddlerStore.saveTiddlersFromPath(path.resolve($tw.boot.corePath,$tw.config.editionsPath,"dev/tiddlers"),"dev-docs");
|
$tw.mws.store.saveTiddlersFromPath(path.resolve($tw.boot.corePath,$tw.config.editionsPath,"dev/tiddlers"),"dev-docs");
|
||||||
// Create bags and recipes
|
// Create bags and recipes
|
||||||
$tw.sqlTiddlerStore.createBag("bag-alpha","A test bag");
|
$tw.mws.store.createBag("bag-alpha","A test bag");
|
||||||
$tw.sqlTiddlerStore.createBag("bag-beta","Another test bag");
|
$tw.mws.store.createBag("bag-beta","Another test bag");
|
||||||
$tw.sqlTiddlerStore.createBag("bag-gamma","A further test bag");
|
$tw.mws.store.createBag("bag-gamma","A further test bag");
|
||||||
$tw.sqlTiddlerStore.createRecipe("recipe-rho",["bag-alpha","bag-beta"],"First wiki");
|
$tw.mws.store.createRecipe("recipe-rho",["bag-alpha","bag-beta"],"First wiki");
|
||||||
$tw.sqlTiddlerStore.createRecipe("recipe-sigma",["bag-alpha","bag-gamma"],"Second Wiki");
|
$tw.mws.store.createRecipe("recipe-sigma",["bag-alpha","bag-gamma"],"Second Wiki");
|
||||||
$tw.sqlTiddlerStore.createRecipe("recipe-tau",["bag-alpha"],"Third Wiki");
|
$tw.mws.store.createRecipe("recipe-tau",["bag-alpha"],"Third Wiki");
|
||||||
$tw.sqlTiddlerStore.createRecipe("recipe-upsilon",["bag-alpha","bag-gamma","bag-beta"],"Fourth Wiki");
|
$tw.mws.store.createRecipe("recipe-upsilon",["bag-alpha","bag-gamma","bag-beta"],"Fourth Wiki");
|
||||||
// Save tiddlers
|
// Save tiddlers
|
||||||
$tw.sqlTiddlerStore.saveBagTiddler({title: "$:/SiteTitle",text: "Bag Alpha"},"bag-alpha");
|
$tw.mws.store.saveBagTiddler({title: "$:/SiteTitle",text: "Bag Alpha"},"bag-alpha");
|
||||||
$tw.sqlTiddlerStore.saveBagTiddler({title: "$:/SiteTitle",text: "Bag Beta"},"bag-beta");
|
$tw.mws.store.saveBagTiddler({title: "$:/SiteTitle",text: "Bag Beta"},"bag-beta");
|
||||||
$tw.sqlTiddlerStore.saveBagTiddler({title: "$:/SiteTitle",text: "Bag Gamma"},"bag-gamma");
|
$tw.mws.store.saveBagTiddler({title: "$:/SiteTitle",text: "Bag Gamma"},"bag-gamma");
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -23,9 +23,9 @@ exports.handler = function(request,response,state) {
|
|||||||
var recipe_name = $tw.utils.decodeURIComponentSafe(state.params[0]),
|
var recipe_name = $tw.utils.decodeURIComponentSafe(state.params[0]),
|
||||||
bag_name = $tw.utils.decodeURIComponentSafe(state.params[1]),
|
bag_name = $tw.utils.decodeURIComponentSafe(state.params[1]),
|
||||||
title = $tw.utils.decodeURIComponentSafe(state.params[2]);
|
title = $tw.utils.decodeURIComponentSafe(state.params[2]);
|
||||||
var recipeBags = $tw.sqlTiddlerStore.getRecipeBags(recipe_name);
|
var recipeBags = $tw.mws.store.getRecipeBags(recipe_name);
|
||||||
if(recipeBags.indexOf(bag_name) !== -1) {
|
if(recipeBags.indexOf(bag_name) !== -1) {
|
||||||
$tw.sqlTiddlerStore.deleteTiddler(title,bag_name);
|
$tw.mws.store.deleteTiddler(title,bag_name);
|
||||||
response.writeHead(204, "OK", {
|
response.writeHead(204, "OK", {
|
||||||
"Content-Type": "text/plain"
|
"Content-Type": "text/plain"
|
||||||
});
|
});
|
||||||
|
@ -23,7 +23,7 @@ exports.handler = function(request,response,state) {
|
|||||||
var bag_name = $tw.utils.decodeURIComponentSafe(state.params[0]),
|
var bag_name = $tw.utils.decodeURIComponentSafe(state.params[0]),
|
||||||
bag_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]),
|
bag_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]),
|
||||||
title = $tw.utils.decodeURIComponentSafe(state.params[2]),
|
title = $tw.utils.decodeURIComponentSafe(state.params[2]),
|
||||||
result = bag_name === bag_name_2 && $tw.sqlTiddlerStore.getBagTiddler(title,bag_name);
|
result = bag_name === bag_name_2 && $tw.mws.store.getBagTiddler(title,bag_name);
|
||||||
if(bag_name === bag_name_2 && result) {
|
if(bag_name === bag_name_2 && result) {
|
||||||
// If application/json is requested then this is an API request, and gets the response in JSON
|
// 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) {
|
if(request.headers.accept && request.headers.accept.indexOf("application/json") !== -1) {
|
||||||
@ -40,7 +40,7 @@ exports.handler = function(request,response,state) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
tiddlerFields.type = tiddlerFields.type || "text/vnd.tiddlywiki";
|
tiddlerFields.type = tiddlerFields.type || "text/vnd.tiddlywiki";
|
||||||
tiddlerFields = $tw.sqlTiddlerStore.processCanonicalUriTiddler(tiddlerFields,bag_name,null);
|
tiddlerFields = $tw.mws.store.processCanonicalUriTiddler(tiddlerFields,bag_name,null);
|
||||||
state.sendResponse(200,{"Content-Type": "application/json"},JSON.stringify(tiddlerFields),"utf8");
|
state.sendResponse(200,{"Content-Type": "application/json"},JSON.stringify(tiddlerFields),"utf8");
|
||||||
} else {
|
} else {
|
||||||
// This is not a JSON API request, we should return the raw tiddler content
|
// This is not a JSON API request, we should return the raw tiddler content
|
||||||
|
@ -22,7 +22,7 @@ exports.handler = function(request,response,state) {
|
|||||||
// Get the parameters
|
// Get the parameters
|
||||||
var bag_name = $tw.utils.decodeURIComponentSafe(state.params[0]),
|
var bag_name = $tw.utils.decodeURIComponentSafe(state.params[0]),
|
||||||
bag_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]),
|
bag_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]),
|
||||||
titles = bag_name === bag_name_2 && $tw.sqlTiddlerStore.getBagTiddlers(bag_name);
|
titles = bag_name === bag_name_2 && $tw.mws.store.getBagTiddlers(bag_name);
|
||||||
if(bag_name === bag_name_2 && titles) {
|
if(bag_name === bag_name_2 && titles) {
|
||||||
// If application/json is requested then this is an API request, and gets the response in JSON
|
// 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) {
|
if(request.headers.accept && request.headers.accept.indexOf("application/json") !== -1) {
|
||||||
@ -33,7 +33,7 @@ exports.handler = function(request,response,state) {
|
|||||||
"Content-Type": "text/html"
|
"Content-Type": "text/html"
|
||||||
});
|
});
|
||||||
// Render the html
|
// Render the html
|
||||||
var html = $tw.sqlTiddlerStore.adminWiki.renderTiddler("text/html","$:/plugins/tiddlywiki/multiwikiserver/templates/get-bags",{
|
var html = $tw.mws.store.adminWiki.renderTiddler("text/html","$:/plugins/tiddlywiki/multiwikiserver/templates/get-bags",{
|
||||||
variables: {
|
variables: {
|
||||||
"bag-name": bag_name,
|
"bag-name": bag_name,
|
||||||
"bag-titles": JSON.stringify(titles)
|
"bag-titles": JSON.stringify(titles)
|
||||||
|
@ -23,7 +23,7 @@ exports.handler = function(request,response,state) {
|
|||||||
var recipe_name = $tw.utils.decodeURIComponentSafe(state.params[0]),
|
var recipe_name = $tw.utils.decodeURIComponentSafe(state.params[0]),
|
||||||
recipe_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]),
|
recipe_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]),
|
||||||
title = $tw.utils.decodeURIComponentSafe(state.params[2]),
|
title = $tw.utils.decodeURIComponentSafe(state.params[2]),
|
||||||
tiddlerInfo = recipe_name === recipe_name_2 && $tw.sqlTiddlerStore.getRecipeTiddler(title,recipe_name);
|
tiddlerInfo = recipe_name === recipe_name_2 && $tw.mws.store.getRecipeTiddler(title,recipe_name);
|
||||||
if(recipe_name === recipe_name_2 && tiddlerInfo && tiddlerInfo.tiddler) {
|
if(recipe_name === recipe_name_2 && tiddlerInfo && tiddlerInfo.tiddler) {
|
||||||
// If application/json is requested then this is an API request, and gets the response in JSON
|
// 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) {
|
if(request.headers.accept && request.headers.accept.indexOf("application/json") !== -1) {
|
||||||
@ -40,7 +40,7 @@ exports.handler = function(request,response,state) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
tiddlerFields.type = tiddlerFields.type || "text/vnd.tiddlywiki";
|
tiddlerFields.type = tiddlerFields.type || "text/vnd.tiddlywiki";
|
||||||
tiddlerFields = $tw.sqlTiddlerStore.processCanonicalUriTiddler(tiddlerFields,null,recipe_name);
|
tiddlerFields = $tw.mws.store.processCanonicalUriTiddler(tiddlerFields,null,recipe_name);
|
||||||
state.sendResponse(200,{"Content-Type": "application/json"},JSON.stringify(tiddlerFields),"utf8");
|
state.sendResponse(200,{"Content-Type": "application/json"},JSON.stringify(tiddlerFields),"utf8");
|
||||||
} else {
|
} else {
|
||||||
// This is not a JSON API request, we should return the raw tiddler content
|
// This is not a JSON API request, we should return the raw tiddler content
|
||||||
|
@ -24,11 +24,11 @@ exports.handler = function(request,response,state) {
|
|||||||
recipe_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]);
|
recipe_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]);
|
||||||
if(recipe_name === recipe_name_2) {
|
if(recipe_name === recipe_name_2) {
|
||||||
// Get the tiddlers in the recipe
|
// Get the tiddlers in the recipe
|
||||||
var recipeTiddlers = $tw.sqlTiddlerStore.getRecipeTiddlers(recipe_name);
|
var recipeTiddlers = $tw.mws.store.getRecipeTiddlers(recipe_name);
|
||||||
// Get a skinny version of each tiddler
|
// Get a skinny version of each tiddler
|
||||||
var tiddlers = [];
|
var tiddlers = [];
|
||||||
$tw.utils.each(recipeTiddlers,function(recipeTiddlerInfo) {
|
$tw.utils.each(recipeTiddlers,function(recipeTiddlerInfo) {
|
||||||
var tiddlerInfo = $tw.sqlTiddlerStore.getRecipeTiddler(recipeTiddlerInfo.title,recipe_name);
|
var tiddlerInfo = $tw.mws.store.getRecipeTiddler(recipeTiddlerInfo.title,recipe_name);
|
||||||
tiddlers.push(Object.assign({},tiddlerInfo.tiddler,{text: undefined}));
|
tiddlers.push(Object.assign({},tiddlerInfo.tiddler,{text: undefined}));
|
||||||
});
|
});
|
||||||
var text = JSON.stringify(tiddlers);
|
var text = JSON.stringify(tiddlers);
|
||||||
|
@ -26,9 +26,9 @@ exports.handler = function(request,response,state) {
|
|||||||
"Content-Type": "text/html"
|
"Content-Type": "text/html"
|
||||||
});
|
});
|
||||||
// Get the tiddlers in the recipe
|
// Get the tiddlers in the recipe
|
||||||
var recipeTiddlers = $tw.sqlTiddlerStore.getRecipeTiddlers(recipe_name);
|
var recipeTiddlers = $tw.mws.store.getRecipeTiddlers(recipe_name);
|
||||||
// Render the template
|
// Render the template
|
||||||
var template = $tw.sqlTiddlerStore.adminWiki.renderTiddler("text/plain","$:/core/templates/tiddlywiki5.html",{
|
var template = $tw.mws.store.adminWiki.renderTiddler("text/plain","$:/core/templates/tiddlywiki5.html",{
|
||||||
variables: {
|
variables: {
|
||||||
saveTiddlerFilter: `
|
saveTiddlerFilter: `
|
||||||
$:/boot/boot.css
|
$:/boot/boot.css
|
||||||
@ -50,10 +50,10 @@ exports.handler = function(request,response,state) {
|
|||||||
}
|
}
|
||||||
response.write(template.substring(0,markerPos + marker.length));
|
response.write(template.substring(0,markerPos + marker.length));
|
||||||
$tw.utils.each(recipeTiddlers,function(recipeTiddlerInfo) {
|
$tw.utils.each(recipeTiddlers,function(recipeTiddlerInfo) {
|
||||||
var result = $tw.sqlTiddlerStore.getRecipeTiddler(recipeTiddlerInfo.title,recipe_name);
|
var result = $tw.mws.store.getRecipeTiddler(recipeTiddlerInfo.title,recipe_name);
|
||||||
if(result) {
|
if(result) {
|
||||||
var tiddlerFields = result.tiddler;
|
var tiddlerFields = result.tiddler;
|
||||||
tiddlerFields = $tw.sqlTiddlerStore.processCanonicalUriTiddler(tiddlerFields,null,recipe_name);
|
tiddlerFields = $tw.mws.store.processCanonicalUriTiddler(tiddlerFields,null,recipe_name);
|
||||||
response.write(JSON.stringify(tiddlerFields).replace(/</g,"\\u003c"));
|
response.write(JSON.stringify(tiddlerFields).replace(/</g,"\\u003c"));
|
||||||
response.write(",\n")
|
response.write(",\n")
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ exports.handler = function(request,response,state) {
|
|||||||
bag_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]),
|
bag_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]),
|
||||||
data = $tw.utils.parseJSONSafe(state.data);
|
data = $tw.utils.parseJSONSafe(state.data);
|
||||||
if(bag_name === bag_name_2 && data) {
|
if(bag_name === bag_name_2 && data) {
|
||||||
const result = $tw.sqlTiddlerStore.createBag(bag_name,data.description);
|
const result = $tw.mws.store.createBag(bag_name,data.description);
|
||||||
if(!result) {
|
if(!result) {
|
||||||
state.sendResponse(204,{
|
state.sendResponse(204,{
|
||||||
"Content-Type": "text/plain"
|
"Content-Type": "text/plain"
|
||||||
|
@ -39,7 +39,7 @@ exports.handler = function(request,response,state) {
|
|||||||
});
|
});
|
||||||
// Require the recipe names to match
|
// Require the recipe names to match
|
||||||
if(recipe_name === recipe_name_2) {
|
if(recipe_name === recipe_name_2) {
|
||||||
var result = $tw.sqlTiddlerStore.saveRecipeTiddler(fields,recipe_name);
|
var result = $tw.mws.store.saveRecipeTiddler(fields,recipe_name);
|
||||||
if(result) {
|
if(result) {
|
||||||
response.writeHead(204, "OK",{
|
response.writeHead(204, "OK",{
|
||||||
Etag: "\"" + result.bag_name + "/" + encodeURIComponent(title) + "/" + result.tiddler_id + ":\"",
|
Etag: "\"" + result.bag_name + "/" + encodeURIComponent(title) + "/" + result.tiddler_id + ":\"",
|
||||||
|
@ -24,7 +24,7 @@ exports.handler = function(request,response,state) {
|
|||||||
recipe_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]),
|
recipe_name_2 = $tw.utils.decodeURIComponentSafe(state.params[1]),
|
||||||
data = $tw.utils.parseJSONSafe(state.data);
|
data = $tw.utils.parseJSONSafe(state.data);
|
||||||
if(recipe_name === recipe_name_2 && data) {
|
if(recipe_name === recipe_name_2 && data) {
|
||||||
const result = $tw.sqlTiddlerStore.createRecipe(recipe_name,data.bag_names,data.description);
|
const result = $tw.mws.store.createRecipe(recipe_name,data.bag_names,data.description);
|
||||||
console.log(`create recipe route handler for ${recipe_name} with ${JSON.stringify(data)} got result ${JSON.stringify(result)}`)
|
console.log(`create recipe route handler for ${recipe_name} with ${JSON.stringify(data)} got result ${JSON.stringify(result)}`)
|
||||||
if(!result) {
|
if(!result) {
|
||||||
state.sendResponse(204,{
|
state.sendResponse(204,{
|
||||||
|
Loading…
Reference in New Issue
Block a user