Can we add a route to fetch tags?

I use the TiddlyWiki browser extension to save articles to TiddlyWiki. I would like the plugin to fetch all the tags of the current user’s wiki to make it easier to select, instead of the user manually entering tags. Therefore, I think adding an additional route would be a suitable solution. What do you think about this? @jeremyruston

/*\
title: $:/core/modules/server/routes/get-tags-json.js
type: application/javascript
module-type: route

\*/
(function () {
  /*jslint node: true, browser: true */
  /*global $tw: false */
  'use strict';

  var DEFAULT_FILTER = '[tags[]]';

  exports.method = 'GET';

  exports.path = /^\/recipes\/default\/tags.json$/;

  exports.handler = function (request, response, state) {
    var filter = state.queryParameters.filter || DEFAULT_FILTER;
    const tags = state.wiki.filterTiddlers(filter);
    var text = JSON.stringify(tags);
    state.sendResponse(
      200,
      { 'Content-Type': 'application/json' },
      text,
      'utf8',
    );
  };
})();

The effect seems pretty good.

Hi @oeyoews the core already goes to some trouble to prevent clients from executing arbitrary filters on the server due to concerns about denial-of-service attacks and performance issues. I think the way to handle this is to create a tiddler that displays the required data in JSON (eg using the <<jsontiddler>> macro) and then for the client to use the get rendered tiddler route to obtain the rendered copy.

1 Like

Well, it is indeed possible by configuring _render_template

Which browser extension? Browser extensions have access to the current page. So it should be possible to get that info from the wiki itself. I think there is no need to ask the server.

It is to save any page to tiddlywiki. This is an extension that I maintain myself. tiddlywiki extension

1 Like


tiddlywiki-starter-kit/plugins/oeyoews/neotw-tag-route/tiddlers/tags.tid at main · oeyoews/tiddlywiki-starter-kit · GitHub Not sure if this is the easiest way to write it