mirror of
https://github.com/TiddlyWiki/TiddlyWiki5.git
synced 2026-02-02 02:56:44 +00:00
* Move Node.js specific files out of the core plugin * Package server files as new $:/core-server plugin * Missed commander.js * Fix crash in browser * Extend server-only mechanism to be usable by other plugins * in * Revert "Extend server-only mechanism to be usable by other plugins" This reverts commit3faf503073. * Revert "in" This reverts commitb80213128f. * Reapply "Extend server-only mechanism to be usable by other plugins" This reverts commitc6c83bc18b. * Fix test failure * Move filesystem utilities into core-server * Move old-style release notes out of the way * Move the 5.4.0 release note into the right place * Revert "Move the 5.4.0 release note into the right place" This reverts commit3f5c2bfba3. * Revert "Move old-style release notes out of the way" This reverts commitee16e48a43.
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
/*\
|
|
title: $:/core/modules/server/routes/put-tiddler.js
|
|
type: application/javascript
|
|
module-type: route
|
|
|
|
PUT /recipes/default/tiddlers/:title
|
|
|
|
\*/
|
|
"use strict";
|
|
|
|
exports.method = "PUT";
|
|
|
|
exports.path = /^\/recipes\/default\/tiddlers\/(.+)$/;
|
|
|
|
exports.handler = function(request,response,state) {
|
|
var title = $tw.utils.decodeURIComponentSafe(state.params[0]),
|
|
fields = $tw.utils.parseJSONSafe(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;
|
|
}
|
|
// If this is a skinny tiddler, it means the client never got the full
|
|
// version of the tiddler to edit. So we must preserve whatever text
|
|
// already exists on the server, or else we'll inadvertently delete it.
|
|
if(fields._is_skinny !== undefined) {
|
|
var tiddler = state.wiki.getTiddler(title);
|
|
if(tiddler) {
|
|
fields.text = tiddler.fields.text;
|
|
}
|
|
delete fields._is_skinny;
|
|
}
|
|
state.wiki.addTiddler(new $tw.Tiddler(fields,{title: title}));
|
|
var changeCount = state.wiki.getChangeCount(title).toString();
|
|
response.writeHead(204, "OK",{
|
|
Etag: "\"default/" + encodeURIComponent(title) + "/" + changeCount + ":\"",
|
|
"Content-Type": "text/plain"
|
|
});
|
|
response.end();
|
|
};
|