mirror of
https://github.com/Jermolene/TiddlyWiki5.git
synced 2026-01-21 03:51:11 -08:00
* Refactor server routes to modules New module type: serverroute Caveats: Loading order is not deterministic but this would only matter if two route modules attempted to use the same path regexp (that would be silly). * Add static assets plugin This plugin allows the node server to fetch static assets in the /assets directory. I felt that this was a feature that goes above the core functionality. That is why I added it as a plugin. with the modular route extensions this was a breeze. * Add serverroute description to ModuleTypes
37 lines
1 KiB
JavaScript
37 lines
1 KiB
JavaScript
/*\
|
|
title: $:/core/modules/serverroute/put-tiddler.js
|
|
type: application/javascript
|
|
module-type: serverroute
|
|
|
|
PUT /recipes/default/tiddlers/:title
|
|
|
|
\*/
|
|
(function() {
|
|
module.exports = {
|
|
method: "PUT",
|
|
path: /^\/recipes\/default\/tiddlers\/(.+)$/,
|
|
|
|
handler: function(request,response,state) {
|
|
var title = decodeURIComponent(state.params[0]),
|
|
fields = JSON.parse(state.data);
|
|
// Pull up any subfields in the `fields` object
|
|
if(fields.fields) {
|
|
$tw.utils.each(fields.fields,function(field,name) {
|
|
fields[name] = field;
|
|
});
|
|
delete fields.fields;
|
|
}
|
|
// Remove any revision field
|
|
if(fields.revision) {
|
|
delete fields.revision;
|
|
}
|
|
state.wiki.addTiddler(new $tw.Tiddler(state.wiki.getCreationFields(),fields,{title: title},state.wiki.getModificationFields()));
|
|
var changeCount = state.wiki.getChangeCount(title).toString();
|
|
response.writeHead(204, "OK",{
|
|
Etag: "\"default/" + encodeURIComponent(title) + "/" + changeCount + ":\"",
|
|
"Content-Type": "text/plain"
|
|
});
|
|
response.end();
|
|
}
|
|
};
|
|
}());
|