1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-05 01:26:18 +00:00
TiddlyWiki5/core/modules/server/routes/get-tiddlers-json.js
Arlen22 81f07cdf85
Use this.wiki where applicable (#4601)
* Use state.wiki

* use local wiki where available

* fix a couple this vs self cases
2020-05-06 11:27:50 +01:00

49 lines
1.5 KiB
JavaScript

/*\
title: $:/core/modules/server/routes/get-tiddlers-json.js
type: application/javascript
module-type: route
GET /recipes/default/tiddlers.json?filter=<filter>
\*/
(function() {
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var DEFAULT_FILTER = "[all[tiddlers]!is[system]sort[title]]";
exports.method = "GET";
exports.path = /^\/recipes\/default\/tiddlers.json$/;
exports.handler = function(request,response,state) {
var filter = state.queryParameters.filter || DEFAULT_FILTER;
if(state.wiki.getTiddlerText("$:/config/Server/AllowAllExternalFilters") !== "yes") {
if(state.wiki.getTiddlerText("$:/config/Server/ExternalFilters/" + filter) !== "yes") {
console.log("Blocked attempt to GET /recipes/default/tiddlers.json with filter: " + filter);
response.writeHead(403);
response.end();
return;
}
}
var excludeFields = (state.queryParameters.exclude || "text").split(","),
titles = state.wiki.filterTiddlers(filter);
response.writeHead(200, {"Content-Type": "application/json"});
var tiddlers = [];
$tw.utils.each(titles,function(title) {
var tiddler = state.wiki.getTiddler(title);
if(tiddler) {
var tiddlerFields = tiddler.getFieldStrings({exclude: excludeFields});
tiddlerFields.revision = state.wiki.getChangeCount(title);
tiddlerFields.type = tiddlerFields.type || "text/vnd.tiddlywiki";
tiddlers.push(tiddlerFields);
}
});
var text = JSON.stringify(tiddlers);
response.end(text,"utf8");
};
}());