Merge ec3aac6aa981e15708d7616c1b6f5c302c08e8d8 into b866c33c9306142d805a2a91ec8503d185636ade
This commit is contained in:
commit
1d088d5f50
@ -52,6 +52,7 @@ DocumentHandler.prototype.handlePost = function (request, response) {
|
|||||||
var _this = this;
|
var _this = this;
|
||||||
var buffer = '';
|
var buffer = '';
|
||||||
var cancelled = false;
|
var cancelled = false;
|
||||||
|
var ct = request.headers['content-type'];
|
||||||
|
|
||||||
// What to do when done
|
// What to do when done
|
||||||
var onSuccess = function () {
|
var onSuccess = function () {
|
||||||
@ -65,6 +66,20 @@ DocumentHandler.prototype.handlePost = function (request, response) {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//added support for json data
|
||||||
|
if (ct && ct.split(';')[0] === 'application/json') {
|
||||||
|
try {
|
||||||
|
let json = JSON.parse(buffer);
|
||||||
|
buffer = json.data;
|
||||||
|
} catch(e) {
|
||||||
|
winston.verbose('error adding document');
|
||||||
|
response.writeHead(500, { 'content-type': 'application/json' });
|
||||||
|
response.end(JSON.stringify({ message: 'invalid JSON received.' }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// And then save if we should
|
// And then save if we should
|
||||||
_this.chooseKey(function (key) {
|
_this.chooseKey(function (key) {
|
||||||
_this.store.set(key, buffer, function (res) {
|
_this.store.set(key, buffer, function (res) {
|
||||||
@ -83,7 +98,6 @@ DocumentHandler.prototype.handlePost = function (request, response) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// If we should, parse a form to grab the data
|
// If we should, parse a form to grab the data
|
||||||
var ct = request.headers['content-type'];
|
|
||||||
if (ct && ct.split(';')[0] === 'multipart/form-data') {
|
if (ct && ct.split(';')[0] === 'multipart/form-data') {
|
||||||
var busboy = new Busboy({ headers: request.headers });
|
var busboy = new Busboy({ headers: request.headers });
|
||||||
busboy.on('field', function (fieldname, val) {
|
busboy.on('field', function (fieldname, val) {
|
||||||
|
@ -64,7 +64,7 @@ haste_document.prototype.save = function(data, callback) {
|
|||||||
type: 'post',
|
type: 'post',
|
||||||
data: data,
|
data: data,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
contentType: 'application/json; charset=utf-8',
|
contentType: 'text/plain; charset=utf-8',
|
||||||
success: function(res) {
|
success: function(res) {
|
||||||
_this.locked = true;
|
_this.locked = true;
|
||||||
_this.key = res.key;
|
_this.key = res.key;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user