2018-07-18 15:54:43 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/server/routes/put-tiddler.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: route
|
|
|
|
|
|
|
|
PUT /recipes/default/tiddlers/:title
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
exports.method = "PUT";
|
|
|
|
|
|
|
|
exports.path = /^\/recipes\/default\/tiddlers\/(.+)$/;
|
|
|
|
|
|
|
|
exports.handler = function(request,response,state) {
|
2021-08-29 12:39:32 +00:00
|
|
|
var title = $tw.utils.decodeURIComponentSafe(state.params[0]),
|
2022-02-21 15:29:25 +00:00
|
|
|
fields = $tw.utils.parseJSONSafe(state.data);
|
2018-07-18 15:54:43 +00:00
|
|
|
// 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;
|
|
|
|
}
|
2022-11-02 17:26:08 +00:00
|
|
|
// 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;
|
|
|
|
}
|
2021-10-27 10:15:30 +00:00
|
|
|
state.wiki.addTiddler(new $tw.Tiddler(fields,{title: title}));
|
2018-07-18 15:54:43 +00:00
|
|
|
var changeCount = state.wiki.getChangeCount(title).toString();
|
|
|
|
response.writeHead(204, "OK",{
|
|
|
|
Etag: "\"default/" + encodeURIComponent(title) + "/" + changeCount + ":\"",
|
|
|
|
"Content-Type": "text/plain"
|
|
|
|
});
|
|
|
|
response.end();
|
|
|
|
};
|
|
|
|
|
|
|
|
}());
|