mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-05 01:26:18 +00:00
81f07cdf85
* Use state.wiki * use local wiki where available * fix a couple this vs self cases
49 lines
1.5 KiB
JavaScript
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");
|
|
};
|
|
|
|
}());
|