2024-03-10 17:45:33 +00:00
|
|
|
/*\
|
2024-03-11 09:10:01 +00:00
|
|
|
title: $:/plugins/tiddlywiki/multiwikiserver/routes/handlers/post-bag-tiddlers.js
|
2024-03-10 17:45:33 +00:00
|
|
|
type: application/javascript
|
2024-03-18 08:44:45 +00:00
|
|
|
module-type: mws-route
|
2024-03-10 17:45:33 +00:00
|
|
|
|
2024-03-20 15:13:50 +00:00
|
|
|
POST /bags/:bag_name/tiddlers/
|
2024-03-10 17:45:33 +00:00
|
|
|
|
|
|
|
\*/
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
exports.method = "POST";
|
|
|
|
|
2024-03-20 15:13:50 +00:00
|
|
|
exports.path = /^\/bags\/([^\/]+)\/tiddlers\/$/;
|
2024-03-10 17:45:33 +00:00
|
|
|
|
|
|
|
exports.bodyFormat = "stream";
|
|
|
|
|
|
|
|
exports.csrfDisable = true;
|
|
|
|
|
|
|
|
exports.handler = function(request,response,state) {
|
|
|
|
const path = require("path"),
|
2024-03-10 20:20:06 +00:00
|
|
|
fs = require("fs"),
|
|
|
|
processIncomingStream = require("$:/plugins/tiddlywiki/multiwikiserver/routes/helpers/multipart-forms.js").processIncomingStream;
|
2024-03-10 17:45:33 +00:00
|
|
|
// Get the parameters
|
2024-03-20 15:13:50 +00:00
|
|
|
var bag_name = $tw.utils.decodeURIComponentSafe(state.params[0]);
|
2024-03-10 17:45:33 +00:00
|
|
|
// Process the incoming data
|
2024-03-10 20:20:06 +00:00
|
|
|
processIncomingStream({
|
|
|
|
store: $tw.mws.store,
|
|
|
|
state: state,
|
|
|
|
response: response,
|
2024-03-17 14:54:06 +00:00
|
|
|
bag_name: bag_name,
|
2024-03-10 20:20:06 +00:00
|
|
|
callback: function(err,results) {
|
2024-03-15 16:39:59 +00:00
|
|
|
// If application/json is requested then this is an API request, and gets the response in JSON
|
|
|
|
if(request.headers.accept && request.headers.accept.indexOf("application/json") !== -1) {
|
|
|
|
state.sendResponse(200,{"Content-Type": "application/json"},JSON.stringify({
|
|
|
|
"imported-tiddlers": results
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
response.writeHead(200, "OK",{
|
|
|
|
"Content-Type": "text/html"
|
|
|
|
});
|
|
|
|
response.write(`
|
|
|
|
<!doctype html>
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
`);
|
|
|
|
// Render the html
|
|
|
|
var html = $tw.mws.store.adminWiki.renderTiddler("text/html","$:/plugins/tiddlywiki/multiwikiserver/templates/post-bag-tiddlers",{
|
|
|
|
variables: {
|
|
|
|
"bag-name": bag_name,
|
|
|
|
"imported-titles": JSON.stringify(results)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
response.write(html);
|
|
|
|
response.write(`
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
`);
|
|
|
|
response.end();
|
|
|
|
}
|
2024-03-10 17:45:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
}());
|