couchdb-node-cms
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -311,2 +311,32 @@ var nano = require('nano'), | ||
var isPrivate = false; | ||
var insertAttach = function(doc, fileName, mimeType, file, res){ | ||
var cbGet = function(err, resp){ | ||
if (err) { | ||
throw new Error('Error retrieving data ' + err); | ||
} | ||
}; | ||
var cbAttach = function(err, r){ | ||
cbGet(err, r); | ||
db.get(doc, function (err, resp) { | ||
resp.credentials = resp.credentials || {}; | ||
resp.credentials[fileName] = { | ||
isPrivate: isPrivate | ||
}; | ||
db.insert(resp, function (err, r) { | ||
renderPost(doc, res); | ||
}); | ||
}); | ||
}; | ||
db.get(doc, { revs_info: true }, function (err, body) { | ||
if(err) | ||
cbGet(err, body); | ||
if(body) | ||
file.pipe(db.attachment.insert(doc, fileName, null, mimeType, {rev: body._rev}, cbAttach)); | ||
else | ||
file.pipe(db.attachment.insert(doc, fileName, null, mimeType, cbAttach)); | ||
}); | ||
}; | ||
app.post(apiRoot + '/posts/:id/files', function (req, res) { | ||
@@ -317,21 +347,19 @@ | ||
}); | ||
var fileData, fileName, mimeType, isPrivate = false; | ||
busboy.on('file', function (fieldname, file, filename, encoding, mimetype) { | ||
// console.log('File [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding + ', mimetype: ' + mimetype); | ||
console.log('File [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding + ', mimetype: ' + mimetype); | ||
fileName = filename; | ||
mimeType = mimetype; | ||
file.on('data', function (data) { | ||
fileData = data | ||
// console.log('File [' + fieldname + '] got ' + data.length + ' bytes'); | ||
}); | ||
file.on('end', function () { | ||
console.log('File [' + fieldname + '] Finished'); | ||
}); | ||
insertAttach(req.params.id, filename, mimetype, file, res); | ||
}); | ||
busboy.on('field', function (fieldname, val, fieldnameTruncated, valTruncated) { | ||
console.log('Field [' + fieldname + ']: value: ' + val); | ||
if (val === 'on') | ||
isPrivate = true; | ||
else | ||
isPrivate = false; | ||
switch(fieldname){ | ||
case 'isPrivate': | ||
if (val === 'on') | ||
isPrivate = true; | ||
else | ||
isPrivate = false; | ||
break; | ||
} | ||
}); | ||
@@ -341,36 +369,8 @@ | ||
console.log('Done parsing form!'); | ||
db.get(req.params.id, function (err, resp) { | ||
if (!err) { | ||
db.attachment.insert(req.params.id, fileName, fileData, mimeType, { | ||
rev: resp._rev | ||
}, | ||
function (err, attachResp) { | ||
if (!err) { | ||
db.get(req.params.id, function (err, resp2) { | ||
resp2.credentials = resp2.credentials || {}; | ||
resp2.credentials[fileName] = { | ||
isPrivate: isPrivate | ||
}; | ||
db.insert(resp2, function (err, r) { | ||
renderPost(req.params.id, res); | ||
// res.writeHead(303, { | ||
// Connection: 'close', | ||
// Location: apiRoot + '/posts/' + req.params.id | ||
// }) | ||
// res.end(); | ||
}); | ||
}); | ||
} else { | ||
res.status(500).send('Error retrieving data'); | ||
} | ||
}); | ||
} else { | ||
res.status(500).send('Error retrieving data'); | ||
} | ||
}); | ||
}); | ||
}); | ||
req.pipe(busboy); | ||
}); | ||
}; | ||
@@ -377,0 +377,0 @@ |
{ | ||
"name": "couchdb-node-cms", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"author": "Hussein Taha", | ||
@@ -5,0 +5,0 @@ "email": "taha.hussein@outlook.com", |
@@ -52,2 +52,2 @@ | ||
* 0.1.3 Initial release | ||
* 0.1.4 Initial release |
var express = require('express') | ||
, CmsEngine = require('couchdb-node-cms') | ||
// , CmsEngine = require('couchdb-node-cms') | ||
, CmsEngine = require('./lib/main') | ||
, config = require('./config'); | ||
@@ -4,0 +5,0 @@ |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
38848
661
4