mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fix saving for node-library content
This commit is contained in:
parent
dfed4963ed
commit
393fc349b9
@ -294,19 +294,26 @@ RED.library = (function() {
|
||||
//}
|
||||
}
|
||||
var queryArgs = [];
|
||||
var data = {};
|
||||
for (var i=0;i<options.fields.length;i++) {
|
||||
var field = options.fields[i];
|
||||
if (field == "name") {
|
||||
queryArgs.push("name="+encodeURIComponent(name));
|
||||
data.name = name;
|
||||
} else {
|
||||
queryArgs.push(encodeURIComponent(field)+"="+encodeURIComponent($("#node-input-"+field).val()));
|
||||
data[field] = $("#node-input-"+field).val();
|
||||
}
|
||||
}
|
||||
var queryString = queryArgs.join("&");
|
||||
|
||||
var text = options.editor.getText();
|
||||
$.post("library/"+options.url+'/'+fullpath+"?"+queryString,text,function() {
|
||||
RED.notify("Saved "+options.type,"success");
|
||||
data.text = options.editor.getText();
|
||||
$.ajax({
|
||||
url:"library/"+options.url+'/'+fullpath,
|
||||
type: "POST",
|
||||
data: JSON.stringify(data),
|
||||
contentType: "application/json; charset=utf-8"
|
||||
}).done(function(data,textStatus,xhr) {
|
||||
RED.notify("Saved "+options.type,"success");
|
||||
}).fail(function(xhr,textStatus,err) {
|
||||
RED.notify("Saved failed: "+xhr.responseText,"error");
|
||||
});
|
||||
}
|
||||
$( "#node-dialog-library-save-confirm" ).dialog({
|
||||
|
@ -45,21 +45,19 @@ function createLibrary(type) {
|
||||
|
||||
redApp.post(new RegExp("/library/"+type+"\/(.*)"),needsPermission("library.write"),function(req,res) {
|
||||
var path = req.params[0];
|
||||
var fullBody = '';
|
||||
req.on('data', function(chunk) {
|
||||
fullBody += chunk.toString();
|
||||
});
|
||||
req.on('end', function() {
|
||||
storage.saveLibraryEntry(type,path,req.query,fullBody).then(function() {
|
||||
res.send(204);
|
||||
}).otherwise(function(err) {
|
||||
log.warn("Error saving library entry '"+path+"' : "+err);
|
||||
if (err.message.indexOf('forbidden') === 0) {
|
||||
res.send(403);
|
||||
return;
|
||||
}
|
||||
res.send(500);
|
||||
});
|
||||
var meta = req.body;
|
||||
var text = meta.text;
|
||||
delete meta.text;
|
||||
|
||||
storage.saveLibraryEntry(type,path,meta,text).then(function() {
|
||||
res.send(204);
|
||||
}).otherwise(function(err) {
|
||||
log.warn("Error saving library entry '"+path+"' : "+err);
|
||||
if (err.message.indexOf('forbidden') === 0) {
|
||||
res.send(403);
|
||||
return;
|
||||
}
|
||||
res.send(500);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -195,10 +195,10 @@ describe("library api", function() {
|
||||
|
||||
it('can store and retrieve item', function(done) {
|
||||
initStorage({},{'test':{}});
|
||||
var flow = '[]';
|
||||
var flow = {text:"test content"};
|
||||
request(app)
|
||||
.post('/library/test/foo')
|
||||
.set('Content-Type', 'text/plain')
|
||||
.set('Content-Type', 'application/json')
|
||||
.send(flow)
|
||||
.expect(204).end(function (err, res) {
|
||||
if (err) {
|
||||
@ -211,16 +211,16 @@ describe("library api", function() {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
res.text.should.equal(flow);
|
||||
res.text.should.equal(flow.text);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('lists a stored item', function(done) {
|
||||
initStorage({},{'test':{'':['abc','def']}});
|
||||
initStorage({},{'test':{'a':['abc','def']}});
|
||||
request(app)
|
||||
.get('/library/test')
|
||||
.get('/library/test/a')
|
||||
.expect(200)
|
||||
.end(function(err,res) {
|
||||
if (err) {
|
||||
|
Loading…
Reference in New Issue
Block a user